/* Цвета — токены; внутри Telegram подставляются цвета темы пользователя (--tg-theme-*). */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --accent-soft: #e8f0fe;
  --danger: #c62828;
  --radius: 12px;
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #181b21;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --line: #2a2e36;
    --accent: #5b9dff;
    --accent-text: #0f1115;
    --accent-soft: #1d2a40;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b21;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --line: #2a2e36;
  --accent: #5b9dff;
  --accent-text: #0f1115;
  --accent-soft: #1d2a40;
  color-scheme: dark;
}

/* В Telegram — цвета темы клиента. */
:root.tg {
  --bg: var(--tg-theme-secondary-bg-color, #f4f5f7);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #16181d);
  --muted: var(--tg-theme-hint-color, #6b7280);
  --line: var(--tg-theme-section-separator-color, rgba(127, 127, 127, 0.2));
  --accent: var(--tg-theme-button-color, #1f6feb);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --accent-soft: color-mix(in srgb, var(--tg-theme-button-color, #1f6feb) 14%, transparent);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; }

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px var(--gutter);
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

:root.tg .top { display: none; } /* в Telegram заголовок и «Назад» — у самого клиента */

.top-title { flex: 1; min-width: 0; }
.title { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle:empty { display: none; }

.back {
  border: 0;
  background: none;
  font-size: 28px;
  line-height: 1;
  padding: 0 6px 2px 0;
  color: var(--accent);
  cursor: pointer;
}

.ghost {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
}
.ghost:hover { background: var(--accent-soft); }

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px var(--gutter) calc(24px + env(safe-area-inset-bottom));
}

.loading, .empty { color: var(--muted); text-align: center; padding: 40px 8px; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.tab {
  flex: 1;
  border: 0;
  background: none;
  padding: 8px;
  border-radius: 9px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
}
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }

.search {
  width: 100%;
  padding: 11px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  outline: none;
}
.search:focus { border-color: var(--accent); }

.list {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
}
:root.tg .list { border: 0; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-top: 1px solid var(--line);
  background: none;
  text-align: left;
  cursor: pointer;
}
.row:first-child { border-top: 0; }
.row:hover { background: var(--accent-soft); }

.avatar {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.chev { color: var(--muted); font-size: 20px; }

.section-title {
  margin: 20px 4px 8px;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

details.requisites {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 14px;
}
:root.tg details.requisites { border: 0; }
details.requisites summary {
  cursor: pointer;
  padding: 12px 0;
  font-weight: 500;
  list-style: none;
}
details.requisites summary::-webkit-details-marker { display: none; }
details.requisites summary::after { content: "▾"; float: right; color: var(--muted); }
details.requisites[open] summary::after { content: "▴"; }
dl.req { margin: 0 0 12px; display: grid; grid-template-columns: minmax(96px, 34%) 1fr; gap: 6px 12px; }
dl.req dt { color: var(--muted); font-size: 13px; }
dl.req dd { margin: 0; word-break: break-word; font-size: 14px; }

.doc {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}
.doc:first-child { border-top: 0; }
.doc.d1 { padding-left: 34px; }
.doc.d2 { padding-left: 54px; }
.doc-head { display: flex; gap: 10px; align-items: baseline; }
.doc-icon { flex: none; width: 20px; text-align: center; }
.doc-main { flex: 1; min-width: 0; }
.doc-title { font-weight: 500; }
.doc-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.doc-total { font-weight: 500; white-space: nowrap; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 0 30px; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent);
  padding: 7px 12px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.btn:hover { background: var(--accent-soft); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }

.login {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  margin-top: 24px;
}
.login h1 { font-size: 20px; margin: 0 0 8px; }
.login p { color: var(--muted); margin: 0 0 18px; }
.login .btn { display: inline-block; text-decoration: none; padding: 10px 18px; }
.error { color: var(--danger); margin-top: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 2 * var(--gutter));
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 3;
}

@media (max-width: 420px) {
  .doc.d1 { padding-left: 24px; }
  .doc.d2 { padding-left: 36px; }
  .actions { margin-left: 0; }
}
