/* Личный кабинет СистемаПоток — общие стили.
   Дизайн-токены, шрифты, паттерн nav/frame — клон из website/ (Home.html и др).
   Добавлены формы, таблицы, статусы для функционала ЛК.
   Любые правки в шаблоне (новый блок, новый компонент) обновляют
   kabinet/docs/05-frontend-structure.md (см. AGENTS.md living-docs rule). */

:root {
  /* Цвета — те же что в website/Home.html и dems-frontend AppColors */
  --bg: #FFFFFF;
  --bg-2: #F4F6F6;
  --shell: #EBECEC;
  --ink: #14171B;
  --ink-2: #727782;
  --ink-3: #9AA0AB;
  --blue: #3B82F6;
  --mint: #5ED7B2;
  --teal: #14B8A6;
  --violet: #8D82F3;
  --warn: #E09A62;
  --error: #F43F5E;
  --success: #5ED7B2;

  --border: rgba(176, 183, 195, .45);
  --border-strong: rgba(20, 23, 27, .08);
  --shadow-sm: 0 1px 2px rgba(20, 23, 27, .04), 0 1px 1px rgba(20, 23, 27, .03);
  --shadow-md: 0 1px 2px rgba(20, 23, 27, .04), 0 8px 24px -10px rgba(20, 23, 27, .10);
  --shadow-lg: 0 1px 2px rgba(20, 23, 27, .04), 0 24px 60px -22px rgba(20, 23, 27, .18);

  /* Радиусы — те же что AppRadii: xs=6, sm=10, md=14, lg=20, xl=26, full=999 */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;
  --r-full: 999px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--shell);
  color: var(--ink);
  font-family: "DM Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}
.mono { font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; border: 0; background: none; cursor: pointer; }
input, textarea, select { font-family: inherit; }

/* ─── Frame: внешняя «карточка» страницы (как у website) ─── */
.page { padding: 14px; min-height: 100vh; }
.frame {
  background: var(--bg);
  border-radius: 24px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  border: 1px solid var(--border-strong);
}

/* ─── Nav (top bar) ─── */
.nav {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 20px 14px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border-strong);
}
.nav .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px;
  border-radius: 10px;
}
.nav .brand .mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: #0E1116;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.nav .brand .mark::before,
.nav .brand .mark::after {
  content: "";
  position: absolute;
  border-radius: 50%;
}
.nav .brand .mark::before {
  width: 10px;
  height: 10px;
  background: var(--mint);
  top: 8px;
  left: 8px;
}
.nav .brand .mark::after {
  width: 10px;
  height: 10px;
  background: var(--blue);
  bottom: 8px;
  right: 8px;
}
.nav .brand .nm {
  display: flex;
  flex-direction: column;
  line-height: 1;
}
.nav .brand .nm .t { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.nav .brand .nm .s {
  font-size: 10.5px;
  color: var(--ink-2);
  margin-top: 3px;
  font-family: "JetBrains Mono", monospace;
  letter-spacing: .04em;
}

.nav .tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 14px;
}
.nav .tabs a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--r-full);
  font-size: 14px;
  color: var(--ink-2);
  font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.nav .tabs a:hover { color: var(--ink); background: rgba(0, 0, 0, .04); }
.nav .tabs a.active {
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-strong);
}

.nav .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.nav .user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  border-radius: var(--r-full);
  background: #fff;
  border: 1px solid var(--border-strong);
}
.nav .user .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--violet));
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav .user .who { font-size: 13px; }
.nav .user .who .nm { font-weight: 600; }
.nav .user .who .em { color: var(--ink-2); font-size: 11px; font-family: "JetBrains Mono", monospace; }

/* ─── Layout: side menu + body ─── */
.shell {
  display: flex;
  min-height: calc(100vh - 28px);
}
.aside {
  width: 240px;
  background: var(--bg-2);
  border-right: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
}
.aside h4 {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin: 16px 10px 6px;
}
.aside .nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  color: var(--ink-2);
  font-weight: 500;
  font-size: 14px;
  transition: background .12s ease, color .12s ease;
  margin-bottom: 2px;
}
.aside .nav-item:hover { background: rgba(0, 0, 0, .04); color: var(--ink); }
.aside .nav-item.active {
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-strong);
}
.aside .nav-item .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.aside .footer { margin-top: auto; padding: 10px; border-top: 1px solid var(--border-strong); }
.aside .footer .user {
  display: flex; align-items: center; gap: 10px;
}
.aside .footer .user .avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--violet));
  color: #fff; font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.aside .footer .user .who { flex: 1; min-width: 0; }
.aside .footer .user .who .nm {
  font-size: 13px; font-weight: 600; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.aside .footer .user .who .em {
  font-size: 11px; color: var(--ink-2);
  font-family: "JetBrains Mono", monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.aside .footer .logout {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--border-strong);
  transition: background .12s ease, color .12s ease;
}
.aside .footer .logout:hover { background: #fff; color: var(--error); }

.body {
  flex: 1;
  padding: 28px 32px;
  overflow-y: auto;
  max-width: 1100px;
}
.body h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.body .sub {
  font-size: 13px;
  color: var(--ink-2);
  margin-bottom: 22px;
}

/* ─── Cards ─── */
.card {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}
.card.compact { padding: 14px 16px; }
.card .ttl {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 12px;
}
.card.success { background: rgba(94, 215, 178, .08); border-color: rgba(94, 215, 178, .35); }

/* ─── Forms ─── */
.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .12);
}
/* Невалидные поля подсвечиваются красным — но только после того как
   пользователь ввёл хоть что-то (иначе пустые required поля кричат с порога). */
.field input:not(:placeholder-shown):invalid,
.field input.invalid {
  border-color: var(--error);
  background: rgba(244, 63, 94, .04);
}
.field input:not(:placeholder-shown):invalid:focus,
.field input.invalid:focus {
  box-shadow: 0 0 0 3px rgba(244, 63, 94, .14);
}
.field .helper {
  font-size: 11.5px;
  color: var(--ink-2);
  margin-top: 6px;
}
.field .field-error {
  font-size: 11.5px;
  color: var(--error);
  margin-top: 6px;
  display: none;
}
.field.invalid .field-error { display: block; }
.field.invalid input { border-color: var(--error); }
.row { display: flex; gap: 10px; }
.row > .field { flex: 1; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: var(--r-full);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s ease, transform .08s ease, box-shadow .12s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary {
  background: var(--ink);
  color: #fff;
  border: 1px solid var(--ink);
}
.btn.primary:hover:not(:disabled) { background: #000; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn.secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border-strong);
}
.btn.secondary:hover:not(:disabled) { background: var(--bg-2); }
.btn.danger {
  background: #fff;
  color: var(--error);
  border: 1px solid var(--error);
}
.btn.danger:hover:not(:disabled) { background: var(--error); color: #fff; }
.btn.success {
  background: var(--success);
  color: #0a3b2a;
  border: 1px solid var(--success);
}
.btn.success:hover:not(:disabled) { filter: brightness(0.96); }
.btn.fullwidth { width: 100%; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn .ic { width: 16px; height: 16px; }

/* ─── Status badges ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.dot::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge.running { background: rgba(94, 215, 178, .18); color: #0a8765; }
.badge.provisioning { background: rgba(141, 130, 243, .18); color: #4d3fc7; }
.badge.pending { background: rgba(224, 154, 98, .18); color: #a35b1c; }
.badge.failed,
.badge.rejected { background: rgba(244, 63, 94, .12); color: #b91537; }
.badge.archived { background: rgba(154, 160, 171, .18); color: var(--ink-2); }
.badge.admin { background: rgba(59, 130, 246, .15); color: #1d4ed8; }

/* ─── Alerts ─── */
.alert {
  padding: 12px 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 14px;
}
.alert.error { background: rgba(244, 63, 94, .08); color: #b91537; border: 1px solid rgba(244, 63, 94, .3); }
.alert.warning { background: rgba(224, 154, 98, .10); color: #a35b1c; border: 1px solid rgba(224, 154, 98, .3); }
.alert.info { background: rgba(59, 130, 246, .08); color: #1d4ed8; border: 1px solid rgba(59, 130, 246, .25); }
.alert.success { background: rgba(94, 215, 178, .10); color: #0a8765; border: 1px solid rgba(94, 215, 178, .35); }

/* ─── Tables ─── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.table th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-2);
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-strong);
  background: var(--bg-2);
}
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-strong);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--bg-2); }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ─── Empty state ─── */
.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--ink-2);
}
.empty .ic {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  color: var(--ink-3);
}
.empty h3 { color: var(--ink); margin: 0 0 6px; font-size: 16px; }
.empty p { margin: 0 0 18px; font-size: 13.5px; }

/* ─── Centered auth pages ─── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--shell);
}
.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: 32px;
  border: 1px solid var(--border-strong);
}
.auth-card.wide { max-width: 560px; }
.auth-card .logo { display: flex; justify-content: center; margin-bottom: 16px; }
.auth-card .logo img { height: 36px; }
.auth-card h1 {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
}
.auth-card .sub {
  text-align: center;
  font-size: 13px;
  color: var(--ink-2);
  margin: 0 0 24px;
}
.auth-card .switch {
  margin-top: 10px;
  text-align: center;
  font-size: 13.5px;
  color: var(--ink-2);
}
.auth-card .switch a { color: var(--blue); font-weight: 600; cursor: pointer; }

/* ─── kv list (детали tenant) ─── */
.kv {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 8px 14px;
}
.kv dt { color: var(--ink-2); font-size: 12.5px; }
.kv dd { margin: 0; color: var(--ink); font-size: 13.5px; word-break: break-word; }
.kv dd.mono { font-family: "JetBrains Mono", monospace; font-size: 13px; }
.kv dd.big { font-size: 18px; font-weight: 700; color: var(--error); }

/* ─── Spinner ─── */
.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spin .8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Modal (native <dialog>) ─── */
dialog.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 480px;
  width: calc(100% - 40px);
}
dialog.modal::backdrop {
  background: rgba(20, 23, 27, .55);
  backdrop-filter: blur(2px);
}
dialog.modal .modal-card {
  background: var(--bg);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  border: 1px solid var(--border-strong);
}
dialog.modal h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 6px;
}
dialog.modal .mhint {
  font-size: 13px;
  color: var(--ink-2);
  margin: 0 0 18px;
}
dialog.modal .actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ─── Page loading ─── */
.page-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--ink-2);
}
