/* Общие стили. Mobile-first: от 360 px без горизонтальной прокрутки, нижнее меню до 768 px. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1c1f24;
  --muted: #5d6470;
  --border: #d6dae0;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --accent-soft: #e3ecfa;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --success: #1b7a3d;
  --warning-soft: #fff4d6;
  --warning-text: #6b4e00;
  --banner: #8a1c14;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .06);
  --radius: 10px;
  --tap: 44px;
  --bottom-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --surface: #1b1e24;
    --surface-2: #252a32;
    --text: #e7e9ec;
    --muted: #a1a8b3;
    --border: #343a44;
    --accent: #6ea2f5;
    --accent-text: #0d1726;
    --accent-soft: #1d2b42;
    --danger: #f28b82;
    --danger-soft: #3a1f1d;
    --success: #7bd394;
    --warning-soft: #3a3016;
    --warning-text: #f2d48a;
    --banner: #a3271d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  overflow-wrap: anywhere;
}

img, video, canvas, iframe { max-width: 100%; height: auto; }
h1 { font-size: 1.4rem; line-height: 1.25; margin: 0 0 .75rem; }
h2 { font-size: 1.15rem; margin: 1.25rem 0 .5rem; }
p { margin: .5rem 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
[hidden] { display: none !important; }

.boot { padding: 2rem 1rem; text-align: center; color: var(--muted); }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: .5rem 1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
  max-width: 100%;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-light { background: #fff; border-color: #fff; color: #1c1f24; }
.btn-link { border: 0; background: none; color: var(--accent); padding: .5rem 0; text-decoration: underline; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

.form { display: grid; gap: .9rem; grid-template-columns: minmax(0, 1fr); }
.field { display: grid; gap: .3rem; min-width: 0; }
.field label { font-weight: 600; font-size: .95rem; }
.field .req { color: var(--danger); }
.field input, .field select, .field textarea, .combo input {
  width: 100%; min-height: var(--tap); padding: .55rem .7rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 16px; /* меньше 16px — iOS увеличивает страницу при фокусе */
}
.field textarea { min-height: 6rem; resize: vertical; }
.field input[aria-invalid="true"], .field select[aria-invalid="true"], .field textarea[aria-invalid="true"] { border-color: var(--danger); }
.combo { display: block; }
.field-hint { color: var(--muted); font-size: .85rem; }
.field-error { color: var(--danger); font-size: .9rem; min-height: 0; }
.field-error:empty { display: none; }
.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.form-actions .btn { flex: 1 1 auto; }
.form-message { color: var(--danger); }
.form-message:empty { display: none; }
.notice { background: var(--warning-soft); color: var(--warning-text); padding: .7rem .9rem; border-radius: 8px; }

/* ---------- оболочка ---------- */

.shell { min-height: 100vh; }
.sidebar { display: none; }
.content { min-width: 0; padding-bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom, 0px) + 1rem); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .6rem;
  min-height: 52px; padding: .4rem 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 600; flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-user { color: var(--muted); font-size: .85rem; max-width: 40%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-mark { color: var(--accent); }

.main { padding: 1rem; max-width: 1200px; outline: none; }
.main:focus { outline: none; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  min-height: var(--bottom-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottom-link {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 0; min-height: var(--bottom-h); padding: 4px 2px;
  border: 0; background: none; color: var(--muted);
  font: inherit; font-size: .7rem; text-decoration: none; cursor: pointer;
}
.bottom-link .nav-icon { font-size: 1.2rem; line-height: 1; }
.bottom-link .nav-label { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bottom-link.active { color: var(--accent); font-weight: 600; }
.bottom-link .badge { position: absolute; top: 4px; right: calc(50% - 22px); }

.badge {
  display: inline-block; min-width: 1.3rem; padding: 0 .35rem;
  border-radius: 999px; background: var(--danger); color: #fff;
  font-size: .72rem; font-weight: 700; line-height: 1.3rem; text-align: center;
}

.sheet-list { display: grid; gap: .25rem; }
.sheet-link {
  display: flex; align-items: center; gap: .75rem;
  min-height: var(--tap); padding: .5rem .6rem; width: 100%;
  border: 0; border-radius: 8px; background: none; color: var(--text);
  font: inherit; text-align: left; text-decoration: none; cursor: pointer;
}
.sheet-link:hover, .sheet-link.active { background: var(--accent-soft); }
.sheet-link .nav-icon { width: 1.4rem; text-align: center; color: var(--muted); }
.sheet-logout { color: var(--danger); }
.sheet-user { margin-top: 0; }

@media (min-width: 768px) {
  .shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); }
  .sidebar {
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    display: flex; flex-direction: column;
    background: var(--surface); border-right: 1px solid var(--border);
  }
  .brand { display: flex; gap: .5rem; align-items: center; padding: 1rem; font-weight: 700; }
  .side-list { display: grid; gap: 2px; padding: 0 .5rem; }
  .side-link {
    display: flex; align-items: center; gap: .6rem;
    min-height: 40px; padding: .35rem .6rem; border-radius: 8px;
    color: var(--text); text-decoration: none;
  }
  .side-link:hover { background: var(--surface-2); }
  .side-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .side-link .nav-icon { width: 1.3rem; text-align: center; color: var(--muted); }
  .side-link .nav-label { flex: 1 1 auto; min-width: 0; }
  .side-foot { margin-top: auto; display: grid; gap: .25rem; padding: 1rem; border-top: 1px solid var(--border); }
  .side-user { font-weight: 600; }
  .side-action { border: 0; background: none; padding: .35rem 0; color: var(--accent); font: inherit; text-align: left; cursor: pointer; text-decoration: underline; }
  .topbar-user { display: none; }
  .topbar .brand-mark { display: none; }
  .bottom-nav { display: none; }
  .content { padding-bottom: 2rem; }
  .main { padding: 1.5rem 2rem; }
}

/* ---------- вход ---------- */

.bare { width: 100%; min-height: 100vh; min-height: 100dvh; padding: 1rem; display: flex; align-items: center; justify-content: center; }
.auth-card {
  width: 100%; max-width: 420px; margin: auto;
  padding: 1.25rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.auth-brand { display: flex; gap: .5rem; align-items: center; font-weight: 700; margin-bottom: 1rem; }
.narrow { max-width: 480px; }

/* ---------- блоки страницы ---------- */

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.empty { padding: 2rem 1rem; text-align: center; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty h1, .empty h2 { margin-top: 0; }
.empty-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-top: 1rem; }
.empty-denied, .empty-error { border-style: solid; }
.empty-error { border-color: var(--danger); }
.loading { padding: 2rem 1rem; color: var(--muted); text-align: center; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }

/* ---------- таблица: на телефоне — карточки ---------- */

.table-wrap { width: 100%; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .85rem; color: var(--muted); font-weight: 600; }
.table-empty { padding: 1rem 0; }
@media (max-width: 767.98px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { margin-bottom: .6rem; padding: .6rem .8rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
  .table td { display: grid; grid-template-columns: minmax(0, 40%) minmax(0, 1fr); gap: .5rem; padding: .25rem 0; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; }
}
@media (min-width: 768px) {
  .table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
  .table th, .table td { padding: .55rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
  .table tbody tr:last-child td { border-bottom: 0; }
}
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--surface-2); }

/* ---------- плашка, тосты, модалка ---------- */

.banner {
  position: sticky; top: 0; z-index: 40;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .5rem 1rem; background: var(--banner); color: #fff;
}
.banner-text { font-weight: 600; min-width: 0; }
.banner .btn { min-height: 38px; }

.toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom, 0px) + .75rem);
  z-index: 60; display: grid; gap: .5rem; width: min(92vw, 420px);
}
@media (min-width: 768px) { .toasts { bottom: 1.25rem; } }
.toast { padding: .7rem 1rem; border-radius: var(--radius); background: var(--text); color: var(--bg); box-shadow: var(--shadow); }
.toast-error { background: var(--danger); color: #fff; }
.toast-success { background: var(--success); color: #fff; }

.modal-open { overflow: hidden; }
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .45);
}
.modal {
  width: 100%; max-height: 90vh; overflow-y: auto;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
  background: var(--surface); color: var(--text);
  border-radius: 14px 14px 0 0; box-shadow: var(--shadow);
}
.modal-title { margin-top: 0; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
@media (min-width: 768px) {
  .modal-overlay { align-items: center; }
  .modal { width: min(560px, 92vw); border-radius: 14px; padding: 1.25rem; }
}
