/* RuWeb AI — панель управления. Отдельный файл, чат-приложение не затрагивает. */

:root {
  color-scheme: dark;
  --bg: #0b0f18;
  --panel: #121a2a;
  --panel-2: #0e1422;
  --panel-3: #182238;
  --line: #233052;
  --line-soft: #1b2740;
  --text: #e9eefc;
  --muted: #8e9cbd;
  --faint: #66739a;
  --accent: #7d9bff;
  --accent-strong: #b6c5ff;
  --accent-fg: #0c1120;
  --good: #63d494;
  --warn: #ffd479;
  --bad: #ff8f9a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px #05070dcc;
  --nav-w: 248px;
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); min-height: 100dvh; }
a { color: var(--accent); }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
code { font: .88em ui-monospace, Consolas, monospace; background: var(--panel-2); padding: .1rem .35rem; border-radius: .35rem; overflow-wrap: anywhere; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: .3rem; }

/* ---------- каркас ---------- */

.shell { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: 100dvh; }

.side {
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 1.1rem;
  padding: 1.2rem .9rem;
  background: linear-gradient(180deg, #0e1524, #0b0f18);
  border-right: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: center; gap: .65rem; color: inherit; text-decoration: none; font-weight: 750; font-size: 1.02rem; padding: .2rem .45rem; }
.brand .logo { display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: .6rem; background: linear-gradient(135deg, var(--accent-strong), var(--accent)); color: var(--accent-fg); font-weight: 800; }

.side nav { display: flex; flex-direction: column; gap: .15rem; }
.side nav button {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem .7rem; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--muted); font: inherit; text-align: left; cursor: pointer;
}
.side nav button svg { width: 1.05rem; height: 1.05rem; flex: none; opacity: .85; }
.side nav button:hover { background: var(--panel-2); color: var(--text); }
.side nav button[aria-current] { background: var(--panel-3); color: var(--text); font-weight: 650; }
.side nav button[aria-current] svg { color: var(--accent-strong); opacity: 1; }
.side nav .sep { margin: .5rem .7rem .35rem; border-top: 1px solid var(--line-soft); }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: .45rem; padding: .2rem .45rem; font-size: .85rem; }
.side-foot a { color: var(--muted); text-decoration: none; }
.side-foot a:hover { color: var(--text); }
.side-foot button { align-self: flex-start; }

main { min-width: 0; padding: 1.6rem clamp(1rem, 3vw, 2.2rem) 3rem; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.page-head h1 { font-size: clamp(1.35rem, 3vw, 1.7rem); line-height: 1.2; letter-spacing: -.01em; }
.page-head p { color: var(--muted); margin-top: .25rem; max-width: 46rem; }
.head-actions { display: flex; align-items: center; gap: .7rem; }
.head-actions a { text-decoration: none; }

/* ---------- карточки ---------- */

.card { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); margin-bottom: 1rem; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .9rem 1.1rem .7rem; flex-wrap: wrap; }
.card-head h2 { font-size: 1.02rem; font-weight: 700; }
.card-head .sub { color: var(--muted); font-size: .85rem; margin-top: .15rem; }
.card-body { padding: .4rem 1.1rem 1.1rem; display: flex; flex-direction: column; gap: .75rem; }
.card-body > .flush { margin-inline: -1.1rem; }
.card-body > button { align-self: flex-start; }
.card-body > .issued { align-self: stretch; }

/* ---------- кнопки ---------- */

button, .button {
  font: inherit; color: var(--text);
  background: var(--panel-3);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .5rem .85rem; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .4rem;
  transition: border-color .15s, background .15s, opacity .15s;
}
button:hover:enabled, .button:hover { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary, .button.primary { background: linear-gradient(180deg, var(--accent-strong), #9db1f8); border-color: transparent; color: var(--accent-fg); font-weight: 700; }
button.primary:hover:enabled { filter: brightness(1.06); }
button.ghost { background: transparent; }
button.small { padding: .28rem .6rem; font-size: .85rem; }
button.danger { color: var(--bad); background: transparent; border-color: #4a2a35; }
button.danger:hover:enabled { border-color: var(--bad); }
.spin { width: 1em; height: 1em; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: rot .7s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ---------- формы ---------- */

label { display: block; color: var(--muted); font-size: .88rem; min-width: 0; }
input:not([type="checkbox"]):not([type="file"]), select, textarea {
  width: 100%; display: block; margin-top: .3rem; padding: .55rem .7rem;
  font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  min-width: 0;
}
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: #33436b; }
input[type="checkbox"] { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
input[type="number"] { max-width: 9rem; }
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13.5rem), 1fr)); gap: .7rem .8rem; align-items: end; }
.checkline { display: flex; align-items: center; gap: .5rem; color: var(--text); }
.checkline input { margin: 0; }
.inline { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }
.inline > label { display: contents; }
.note { font-size: .83rem; color: var(--faint); }
.hint { font-size: .78rem; color: var(--faint); }

/* ---------- таблицы ---------- */

.table-scroll { overflow-x: auto; margin-inline: -1.1rem; padding-inline: 1.1rem; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: .9rem; }
th { color: var(--faint); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: .45rem .55rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .55rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #ffffff06; }
td .name-input { min-width: 11rem; }
td code { background: none; padding: 0; color: var(--muted); display: block; font-size: .82rem; }
.empty { color: var(--faint); padding: .4rem 0; }

/* ---------- бейджи и статусы ---------- */

.badge { display: inline-block; border-radius: 999px; padding: .1rem .6rem; font-size: .78rem; border: 1px solid var(--line); white-space: nowrap; }
.badge.cost-free, .badge.cost-quota { color: var(--good); border-color: #1f4634; background: #122b1e; }
.badge.cost-paid, .badge.cost-unknown { color: var(--warn); border-color: #4d3d1c; background: #2c2410; }
.dot { width: .55rem; height: .55rem; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: var(--good); box-shadow: 0 0 6px #63d49488; }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.dot.off { background: var(--faint); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn-text { color: var(--warn); }
.traits { color: var(--faint); font-size: .8rem; display: block; margin-top: .15rem; }

/* ---------- логин ---------- */

.login-card { max-width: 24rem; margin: 9vh auto 0; background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.6rem; display: flex; flex-direction: column; gap: 1rem; }
.login-card h1 { font-size: 1.3rem; }
.login-card .brand { justify-content: center; padding: 0; margin-bottom: .3rem; }

/* ---------- обзор ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: .8rem; }
.stat { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: .9rem 1.1rem; }
.stat .k { color: var(--faint); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.stat .v { font-size: 1.5rem; font-weight: 750; margin-top: .2rem; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: .85rem; color: var(--muted); font-weight: 500; white-space: nowrap; }
.overview-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 26rem), 1fr)); gap: 0 1rem; align-items: start; }

.health-row { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; border-bottom: 1px solid var(--line-soft); }
.health-row:last-child { border-bottom: 0; }
.health-row .who { flex: 1; min-width: 0; }
.health-row .who .st { font-size: .8rem; color: var(--faint); }
.error-line { display: flex; gap: .6rem; padding: .45rem 0; border-bottom: 1px solid var(--line-soft); font-size: .85rem; }
.error-line:last-child { border-bottom: 0; }
.error-line time { color: var(--faint); white-space: nowrap; }
.error-line .what { overflow-wrap: anywhere; }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .6rem; }
.quick button { justify-content: center; padding: .8rem .6rem; flex-direction: column; gap: .3rem; font-weight: 600; }
.quick button span { font-size: .78rem; color: var(--muted); font-weight: 400; }

/* ---------- фильтры ---------- */

.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: .6rem .8rem; align-items: end; }
.filters .count { color: var(--muted); font-size: .85rem; padding-bottom: .55rem; white-space: nowrap; }

/* ---------- прочее ---------- */

dialog { color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); width: min(92vw, 32rem); max-height: 90dvh; overflow: auto; padding: 1.2rem; }
dialog::backdrop { background: #05070dbb; backdrop-filter: blur(3px); }
dialog h2 { margin-bottom: .7rem; font-size: 1.1rem; }
dialog > * + * { margin-top: .7rem; }
.test-output { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--panel-2); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: .8rem; min-height: 3rem; }
.issued { background: #122b1e; border: 1px solid #1f4634; color: var(--good); border-radius: var(--radius-sm); padding: .6rem .8rem; overflow-wrap: anywhere; }

/* ---------- тосты ---------- */

#toasts { position: fixed; top: .9rem; right: .9rem; z-index: 100; display: flex; flex-direction: column; gap: .5rem; max-width: min(92vw, 26rem); }
.toast { background: var(--panel-3); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); padding: .65rem .9rem; box-shadow: var(--shadow); font-size: .88rem; animation: slide-in .18s ease-out; overflow-wrap: anywhere; }
.toast.success { border-left-color: var(--good); }
.toast.error { border-left-color: var(--bad); }
.toast.info { border-left-color: var(--accent); }
.toast.out { opacity: 0; transform: translateX(.5rem); transition: opacity .3s, transform .3s; }
@keyframes slide-in { from { opacity: 0; transform: translateX(.6rem); } }

/* ---------- адаптив ---------- */

@media (max-width: 940px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line-soft); padding: .8rem 1rem; gap: .6rem; }
  .side nav { flex-direction: row; overflow-x: auto; padding-bottom: .2rem; }
  .side nav button { white-space: nowrap; }
  .side nav .sep { display: none; }
  .side-foot { flex-direction: row; margin-top: 0; align-items: center; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .count { grid-column: 1 / -1; padding-bottom: 0; }
}

@media (max-width: 560px) {
  main { padding: 1rem .8rem 2.5rem; }
  .filters { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  input, select, textarea { font-size: 16px; }
}
