:root {
  --bg: #0a0a0b;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-strong: rgba(255, 255, 255, 0.07);
  --line: rgba(255, 255, 255, 0.1);
  --line-soft: rgba(255, 255, 255, 0.06);
  --ink: #f5f5f7;
  --muted: rgba(245, 245, 247, 0.6);
  --faint: rgba(245, 245, 247, 0.4);
  --accent: #e7c98a;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --blur: saturate(160%) blur(22px);
  --radius: 22px;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

/* Важно: класс .login-screen задаёт display:grid и перебивал атрибут [hidden].
   Это правило гарантирует, что скрытые элементы действительно скрыты. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(231, 201, 138, 0.08), transparent 60%),
    radial-gradient(1000px 700px at 100% 0%, rgba(120, 130, 255, 0.06), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  z-index: 0;
  pointer-events: none;
  opacity: 0.5;
}
.bg-orb--1 { width: 520px; height: 520px; top: -160px; left: -120px; background: rgba(231, 201, 138, 0.16); }
.bg-orb--2 { width: 480px; height: 480px; bottom: -180px; right: -140px; background: rgba(90, 110, 255, 0.14); }

.glass {
  background: var(--panel);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--line);
}

/* ── Кнопки / поля ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, opacity 0.18s ease, border-color 0.18s ease;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--ink); color: #0a0a0b; }
.btn-primary:hover { background: #fff; }
.btn-ghost { background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); color: var(--ink); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); }
.btn-accent { background: var(--accent); color: #1a1608; }
.btn-accent:hover { background: #f0d79b; }

.field {
  width: 100%;
  height: 46px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 15px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  transition: border-color 0.18s ease, background 0.18s ease;
}
.field::placeholder { color: var(--faint); }
.field:focus { outline: none; border-color: rgba(255, 255, 255, 0.35); background: rgba(255, 255, 255, 0.07); }
textarea.field { height: auto; min-height: 120px; padding: 12px 16px; resize: vertical; line-height: 1.5; }
select.field { appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23888' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center; padding-right: 40px; }
select.field option { background: #17171a; color: var(--ink); }

/* ── Брендинг ── */
.brand-kicker {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--faint);
}
.brand-logo {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.05em;
  margin-top: 4px;
}
.brand-logo--sm { font-size: 17px; }
.brand-sep { color: var(--faint); font-weight: 400; margin: 0 2px; }

/* ── Экран входа ── */
.login-screen {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  isolation: isolate;
}
.login-screen::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background: url("background_opening.jpg") center / cover no-repeat;
}
.login-screen::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1100px 700px at 50% 45%, rgba(10, 10, 11, 0.35), transparent 70%),
    linear-gradient(180deg, rgba(10, 10, 11, 0.55) 0%, rgba(10, 10, 11, 0.35) 40%, rgba(10, 10, 11, 0.72) 100%);
  backdrop-filter: saturate(115%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 42px 34px;
  border-radius: 26px;
  background: rgba(14, 14, 16, 0.55);
  backdrop-filter: saturate(160%) blur(28px);
  -webkit-backdrop-filter: saturate(160%) blur(28px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 10px 0 0; font-size: 28px; letter-spacing: -0.03em; }
.login-hint { margin: 0 0 6px; font-size: 14px; color: var(--muted); }
.login-error { margin: 0; font-size: 13px; color: var(--danger); }

/* ── Приложение ── */
.app {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 20px 80px;
}

.topbar {
  position: sticky;
  top: 14px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
}
.topbar-brand { min-width: 0; }
.tabs { display: flex; gap: 6px; margin-left: auto; background: rgba(0,0,0,0.25); padding: 5px; border-radius: 999px; border: 1px solid var(--line-soft); }
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.18s ease, color 0.18s ease;
}
.tab:hover { color: var(--ink); }
.tab.is-active { background: rgba(255, 255, 255, 0.12); color: var(--ink); }
.tab-count {
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.topbar-actions { display: flex; gap: 8px; }

.status-line {
  margin: 16px 4px 4px;
  font-size: 13px;
  color: var(--faint);
  min-height: 18px;
}

.view { margin-top: 8px; }

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.field--search { flex: 1 1 260px; }
.field--select { flex: 0 0 auto; width: auto; min-width: 180px; }

/* ── Заявки: сетка карточек ── */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}
.app-card {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-radius: 18px;
  padding: 18px;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.app-card:hover { transform: translateY(-3px); border-color: rgba(255, 255, 255, 0.24); background: var(--panel-strong); }
.app-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.app-card-name { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.app-card-date { font-size: 12px; color: var(--faint); margin-top: 2px; }
.app-card-row { font-size: 13.5px; color: var(--muted); display: flex; gap: 8px; }
.app-card-row b { color: var(--ink); font-weight: 500; }
.app-card-cats { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 2px; }
.app-card-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  white-space: nowrap;
}
.chip-cat { color: var(--accent); border-color: rgba(231, 201, 138, 0.3); background: rgba(231, 201, 138, 0.08); }
.chip-reply { color: var(--ok); border-color: rgba(74, 222, 128, 0.35); background: rgba(74, 222, 128, 0.1); }

/* Статусы */
.status-dot { width: 7px; height: 7px; border-radius: 50%; }
.st-new     { color: #8fbcff; } .st-new .status-dot     { background: #8fbcff; }
.st-reviewing { color: #e7c98a; } .st-reviewing .status-dot { background: #e7c98a; }
.st-accepted { color: var(--ok); } .st-accepted .status-dot { background: var(--ok); }
.st-rejected { color: var(--danger); } .st-rejected .status-dot { background: var(--danger); }
.st-paid    { color: #c7a3ff; } .st-paid .status-dot    { background: #c7a3ff; }

/* ── Чаты ── */
.chats-list { display: flex; flex-direction: column; gap: 12px; }
.chat-card {
  text-align: left;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-radius: 16px;
  padding: 16px 18px;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
.chat-card:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.24); background: var(--panel-strong); }
.chat-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.chat-card-id { font-size: 12px; color: var(--faint); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.chat-card-preview { font-size: 14px; color: var(--muted); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chat-card-meta { font-size: 12px; color: var(--faint); margin-top: 8px; display: flex; gap: 12px; flex-wrap: wrap; }

.empty-state { padding: 60px 20px; text-align: center; color: var(--faint); }

/* ── Drawer ── */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.28s ease;
}
.drawer-backdrop.is-open { opacity: 1; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  height: 100vh;
  width: min(560px, 100vw);
  border-left: 1px solid var(--line);
  border-radius: 0;
  box-shadow: var(--shadow);
  transform: translateX(102%);
  transition: transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
  overflow-y: auto;
  background: rgba(18, 18, 21, 0.85);
}
.drawer.is-open { transform: translateX(0); }
.drawer-close {
  position: sticky;
  top: 14px;
  float: right;
  margin: 14px 14px 0 0;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.06);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}
.drawer-close:hover { background: rgba(255,255,255,0.14); }
.drawer-body { padding: 22px 28px 60px; }

/* «Ручка» шторки — видна только в мобильном режиме bottom-sheet */
.drawer-grabber { display: none; }

/* ── Тост (всплывающее уведомление) ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(440px, calc(100vw - 32px));
  padding: 14px 20px;
  border-radius: 16px;
  background: rgba(28, 28, 32, 0.92);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  color: var(--ink);
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.toast.is-open { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast::before {
  content: "";
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border-radius: 50%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 14px;
}
.toast.toast--ok::before {
  background-color: var(--ok);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%230a0a0b' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6L9 17l-5-5'/%3E%3C/svg%3E");
}
.toast.toast--err::before {
  background-color: var(--danger);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%230a0a0b' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 6L6 18M6 6l12 12'/%3E%3C/svg%3E");
}

.d-kicker { font-size: 11px; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--faint); }
.d-title { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin: 6px 0 4px; }
.d-section-title { font-size: 12px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); margin: 26px 0 12px; }
.d-hint { margin: -4px 0 12px; font-size: 13px; color: var(--muted); line-height: 1.45; }

/* Сворачиваемый блок технических данных */
.d-details { margin-top: 28px; border-top: 1px solid var(--line-soft); padding-top: 16px; }
.d-details summary {
  cursor: pointer;
  list-style: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.d-details summary::-webkit-details-marker { display: none; }
.d-details summary::before { content: "+"; font-size: 15px; line-height: 1; color: var(--faint); }
.d-details[open] summary::before { content: "–"; }
.d-details summary:hover { color: var(--muted); }

.d-grid { display: grid; grid-template-columns: 1fr; gap: 1px; background: var(--line-soft); border: 1px solid var(--line-soft); border-radius: 14px; overflow: hidden; }
.d-row { display: grid; grid-template-columns: 130px 1fr; gap: 12px; padding: 12px 16px; background: rgba(255,255,255,0.02); font-size: 14px; }
.d-row dt { color: var(--faint); }
.d-row dd { margin: 0; color: var(--ink); word-break: break-word; }
.d-row dd a { color: var(--accent); text-decoration: none; }
.d-row dd a:hover { text-decoration: underline; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--muted); }

/* Смена статуса */
.d-status-row { display: flex; gap: 8px; flex-wrap: wrap; }
.d-status-btn {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  transition: all 0.15s ease;
}
.d-status-btn:hover { color: var(--ink); border-color: rgba(255,255,255,0.3); }
.d-status-btn.is-active { background: var(--ink); color: #0a0a0b; border-color: var(--ink); }

/* Ответ на email */
.reply-box { display: flex; flex-direction: column; gap: 10px; }
.reply-box .btn { width: 100%; min-height: 48px; margin-top: 2px; }
.reply-hint { font-size: 13px; color: var(--muted); margin: 0; }
.reply-warn { font-size: 13px; color: var(--danger); margin: 0; }
.reply-status { font-size: 13px; margin: 0; min-height: 16px; }
.reply-status.ok { color: var(--ok); }
.reply-status.err { color: var(--danger); }

.reply-history { display: flex; flex-direction: column; gap: 10px; }
.reply-item { border: 1px solid var(--line-soft); border-radius: 12px; padding: 12px 14px; background: rgba(255,255,255,0.02); }
.reply-item-head { font-size: 12px; color: var(--faint); margin-bottom: 6px; }
.reply-item-subj { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.reply-item-msg { font-size: 13.5px; color: var(--muted); line-height: 1.5; white-space: pre-wrap; }

/* Транскрипт чата */
.transcript { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.msg { max-width: 85%; padding: 11px 15px; border-radius: 16px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.msg-subj { font-weight: 600; font-size: 12.5px; opacity: 0.85; margin-bottom: 4px; }
.msg-time { display: block; font-size: 10.5px; color: var(--faint); margin-top: 5px; }
.msg-user { align-self: flex-end; background: var(--ink); color: #0a0a0b; border-bottom-right-radius: 5px; }
.msg-user .msg-time { color: rgba(10,10,11,0.5); }
.msg-bot { align-self: flex-start; background: rgba(255,255,255,0.07); border: 1px solid var(--line-soft); border-bottom-left-radius: 5px; }

@media (max-width: 760px) {
  .app { padding: 10px 12px calc(72px + env(safe-area-inset-bottom)); }

  /* Топбар: 1-я строка — бренд + действия, 2-я — вкладки на всю ширину */
  .topbar {
    flex-wrap: wrap;
    gap: 12px;
    top: 8px;
    padding: 12px 14px;
    border-radius: 18px;
  }
  .topbar-brand { flex: 1 1 auto; min-width: 0; }
  .brand-logo--sm { font-size: 15px; }
  .topbar-actions { flex: 0 0 auto; margin-left: auto; gap: 8px; }

  .tabs {
    order: 3;
    width: 100%;
    margin-left: 0;
    gap: 4px;
    padding: 4px;
  }
  .tab { flex: 1 1 0; justify-content: center; padding: 10px 8px; font-size: 13.5px; }

  .btn { min-height: 40px; padding: 0 16px; font-size: 13.5px; }

  .status-line { margin: 14px 2px 2px; }

  /* Инструменты фильтров — в столбик, на всю ширину */
  .toolbar { flex-direction: column; gap: 10px; margin-bottom: 16px; }
  .field--search,
  .field--select { flex: 1 1 auto; width: 100%; min-width: 0; }

  /* Карточки заявок — одна колонка */
  .apps-grid { grid-template-columns: 1fr; gap: 12px; }
  .app-card { padding: 16px; }

  /* Drawer как нативная iOS-шторка снизу */
  .drawer {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    max-height: 92dvh;
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 24px 24px 0 0;
    transform: translateY(100%);
  }
  .drawer.is-open { transform: translateY(0); }
  .drawer-grabber {
    display: block;
    position: sticky;
    top: 0;
    z-index: 3;
    width: 40px;
    height: 5px;
    margin: 10px auto 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.25);
  }
  .drawer-close {
    position: absolute;
    top: 12px;
    right: 14px;
    margin: 0;
    float: none;
    width: 36px; height: 36px; font-size: 22px;
  }
  .drawer-body { padding: 6px 18px calc(40px + env(safe-area-inset-bottom)); }
  .d-title { font-size: 22px; }
  .d-row { grid-template-columns: 100px 1fr; gap: 10px; padding: 11px 14px; font-size: 13.5px; }
  .msg { max-width: 90%; }
}

@media (max-width: 420px) {
  .brand-kicker { font-size: 9.5px; letter-spacing: 0.18em; }
  .brand-logo--sm { font-size: 14px; }
  .topbar-actions .btn { padding: 0 12px; }
  .app-card-name { font-size: 16px; }
  .d-row { grid-template-columns: 88px 1fr; }
}
