/* MyWiki — общая дизайн-система (ТЗ-uiux §5).
   Единственный источник токенов и общих компонентов: шапка, аватар-меню,
   кнопки, поля, карточки, модалка, адаптивные таблицы. Страницы добавляют
   только свои специфичные стили. Тема: системная по умолчанию, ручной
   выбор — data-theme на <html> (ставит ui.js из localStorage). */

:root {
  color-scheme: light dark;
  --bg:#ffffff; --fg:#1a1a1a; --muted:#6b7280; --card:#f4f4f5; --accent:#2563eb;
  --border:#e5e7eb; --err:#dc2626; --okc:#16a34a; --warn:#d97706;
  --accent-soft:color-mix(in srgb, var(--accent) 10%, transparent);
  --shadow:0 1px 2px rgba(0,0,0,.05), 0 8px 24px -12px rgba(0,0,0,.15);
  --r-sm:8px; --r-md:10px; --r-lg:14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#0f1115; --fg:#e8e8ea; --muted:#9aa0aa; --card:#1a1d24; --accent:#3b82f6;
    --border:#2a2e37; --err:#f87171; --okc:#4ade80; --warn:#fbbf24;
    --shadow:0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.5); }
}
/* Ручной выбор темы перебивает системную в обе стороны. */
:root[data-theme="dark"] { color-scheme: dark;
  --bg:#0f1115; --fg:#e8e8ea; --muted:#9aa0aa; --card:#1a1d24; --accent:#3b82f6;
  --border:#2a2e37; --err:#f87171; --okc:#4ade80; --warn:#fbbf24;
  --shadow:0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.5); }
:root[data-theme="light"] { color-scheme: light;
  --bg:#ffffff; --fg:#1a1a1a; --muted:#6b7280; --card:#f4f4f5; --accent:#2563eb;
  --border:#e5e7eb; --err:#dc2626; --okc:#16a34a; --warn:#d97706;
  --shadow:0 1px 2px rgba(0,0,0,.05), 0 8px 24px -12px rgba(0,0,0,.15); }

* { box-sizing:border-box; }
/* Атрибут hidden не должен перебиваться авторскими display-правилами. */
[hidden] { display:none !important; }
body { margin:0; background:var(--bg); color:var(--fg);
  font:15px/1.55 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif; }

/* Видимый фокус только с клавиатуры (ТЗ-uiux §5, доступность). */
:focus-visible { outline:2px solid var(--accent); outline-offset:2px; border-radius:4px; }
:focus:not(:focus-visible) { outline:none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration:.01ms !important; transition-duration:.01ms !important; }
}
/* Поля <16px iOS Safari зумит при фокусе — на тачах поднимаем.
   Кнопкам темы в аватар-меню — тап-зону побольше. */
@media (hover:none) and (pointer:coarse) {
  input:not([type=checkbox]):not([type=radio]), textarea, select { font-size:16px !important; }
  .utheme button { padding:8px 13px; }
}

/* ---------- шапка (рисует ui.js) ---------- */
.appbar { position:sticky; top:0; z-index:30; background:var(--bg);
  padding:10px 18px; border-bottom:1px solid var(--border);
  display:flex; align-items:center; gap:14px;
  padding-top:calc(10px + env(safe-area-inset-top, 0px));
  padding-left:calc(18px + env(safe-area-inset-left, 0px));
  padding-right:calc(18px + env(safe-area-inset-right, 0px)); }
.appbar .brand { font-weight:700; color:var(--fg); text-decoration:none; letter-spacing:-.01em; }
.appnav { display:flex; gap:4px; min-width:0; overflow-x:auto; scrollbar-width:none; }
.appnav::-webkit-scrollbar { display:none; }
.appnav a { color:var(--muted); text-decoration:none; font-size:14px; white-space:nowrap;
  padding:5px 10px; border-radius:999px; }
.appnav a:hover { color:var(--accent); }
.appnav a.on { color:var(--accent); background:var(--accent-soft); font-weight:600; }
.appbar-actions { margin-left:auto; display:flex; align-items:center; gap:8px; min-width:0; }

.avatar { width:34px; height:34px; border-radius:50%; border:none; cursor:pointer; flex:0 0 auto;
  background:var(--accent); color:#fff; font:inherit; font-size:13px; font-weight:700;
  display:flex; align-items:center; justify-content:center; }
.avatar-wrap { position:relative; flex:0 0 auto; }
.umenu { position:absolute; right:0; top:calc(100% + 8px); min-width:230px; z-index:40;
  background:var(--bg); border:1px solid var(--border); border-radius:var(--r-lg);
  box-shadow:var(--shadow); padding:6px; }
.umenu .uhead { padding:8px 10px 10px; border-bottom:1px solid var(--border); margin-bottom:6px; }
.umenu .uhead .nm { font-weight:600; }
.umenu .uhead .em { font-size:12.5px; color:var(--muted); overflow-wrap:anywhere; }
.umenu a, .umenu button.uitem { display:flex; width:100%; align-items:center; gap:8px;
  padding:9px 10px; border:none; background:none; border-radius:var(--r-sm); cursor:pointer;
  color:var(--fg); text-decoration:none; font:inherit; text-align:left; }
.umenu a:hover, .umenu button.uitem:hover { background:var(--card); }
.umenu .uitem.danger { color:var(--err); }
.usep { border-top:1px solid var(--border); margin:6px 0; }
.utheme { display:flex; gap:4px; padding:4px 10px 8px; }
.utheme .tlabel { font-size:12.5px; color:var(--muted); align-self:center; margin-right:auto; }
.utheme button { border:1px solid var(--border); background:none; color:var(--muted);
  font:inherit; font-size:12px; border-radius:999px; padding:3px 9px; cursor:pointer; }
.utheme button.on { border-color:var(--accent); color:var(--accent); background:var(--accent-soft); }

/* ---------- нижняя навигация владельца (телефон) ---------- */
.bottomnav { display:none; }
@media (max-width:640px) {
  /* страницы прибавляют var(--bottomnav-h, 0px) к нижнему отступу контента */
  body[data-has-bottomnav] { --bottomnav-h:58px; }
  .bottomnav { position:fixed; left:0; right:0; bottom:0; z-index:30; display:flex;
    background:var(--bg); border-top:1px solid var(--border);
    padding:4px 4px calc(4px + env(safe-area-inset-bottom, 0px)); }
  .bottomnav a { flex:1; text-align:center; text-decoration:none; color:var(--muted);
    font-size:10.5px; padding:4px 2px; border-radius:var(--r-sm); min-height:44px; }
  .bottomnav a .ic { display:block; font-size:19px; line-height:1.25; }
  .bottomnav a.on { color:var(--accent); }
  /* когда есть нижняя навигация — скрываем дублирующие ссылки в шапке */
  body[data-has-bottomnav] .appnav { display:none; }
}

/* ---------- кнопки и поля ---------- */
.btn { display:inline-flex; align-items:center; justify-content:center; gap:7px;
  padding:9px 14px; border-radius:var(--r-md); border:1px solid var(--border);
  background:transparent; color:var(--fg); font:inherit; font-size:14px; cursor:pointer;
  min-height:38px; }
.btn:hover { border-color:var(--accent); color:var(--accent); }
.btn:disabled { opacity:.5; cursor:default; pointer-events:none; }
.btn.primary { border:none; background:var(--accent); color:#fff; font-weight:600; }
.btn.primary:hover { color:#fff; filter:brightness(1.07); }
.btn.ok { border-color:var(--okc); color:var(--okc); }
.btn.danger { border-color:var(--err); color:var(--err); }
.btn.ghost { border:none; background:none; color:var(--accent); padding:5px 8px; min-height:0; }
.btn.ghost:hover { text-decoration:underline; }

.spinner { width:15px; height:15px; border-radius:50%; flex:0 0 auto;
  border:2px solid currentColor; border-top-color:transparent;
  animation:uispin .7s linear infinite; }
@keyframes uispin { to { transform:rotate(360deg); } }

.field { font-size:13px; color:var(--muted); display:flex; flex-direction:column; gap:4px; }
.field input, .field select { padding:10px 12px; border-radius:var(--r-md);
  border:1px solid var(--border); background:var(--bg); color:var(--fg); font:inherit; width:100%; }
.field input[readonly] { background:var(--card); color:var(--muted); }
.field input.invalid { border-color:var(--err); }
.fielderr { font-size:12px; color:var(--err); min-height:0; }

.msg { min-height:20px; font-size:13px; }
.msg.err { color:var(--err); }
.msg.ok { color:var(--okc); }

/* ---------- карточки, бейджи ---------- */
.card { border:1px solid var(--border); border-radius:var(--r-lg); padding:14px 16px;
  background:var(--bg); }
.badge { font-size:12px; padding:2px 8px; border-radius:999px;
  border:1px solid var(--border); color:var(--muted); white-space:nowrap; }
.badge.accent { border-color:var(--accent); color:var(--accent); }
.badge.warn { border-color:var(--warn); color:var(--warn); }
.badge.ok { border-color:var(--okc); color:var(--okc); }

/* ---------- модалка подтверждения (UI.confirm) ---------- */
.uimodal-overlay { position:fixed; inset:0; z-index:100; background:rgba(0,0,0,.35);
  display:flex; align-items:center; justify-content:center; padding:20px; }
.uimodal { background:var(--bg); border:1px solid var(--border); border-radius:var(--r-lg);
  box-shadow:var(--shadow); max-width:400px; width:100%; padding:18px; }
.uimodal .mt { font-weight:700; font-size:16px; margin-bottom:6px; }
.uimodal .mx { color:var(--muted); font-size:14px; }
.uimodal .mbtns { display:flex; justify-content:flex-end; gap:8px; margin-top:16px; }

/* ---------- тост ---------- */
.uitoast { position:fixed; left:50%; transform:translateX(-50%);
  bottom:calc(24px + env(safe-area-inset-bottom, 0px)); z-index:110;
  background:var(--fg); color:var(--bg); font-size:14px; padding:9px 16px;
  border-radius:999px; box-shadow:var(--shadow); max-width:88vw; text-align:center; }

/* ---------- таблицы: на телефоне превращаются в карточки ----------
   Разметка: <table class="rtable"> + data-label на каждой td. */
.tablewrap { overflow-x:auto; }
table.rtable { width:100%; border-collapse:collapse; }
.rtable th, .rtable td { padding:8px 10px; border-bottom:1px solid var(--border);
  text-align:right; white-space:nowrap; font-variant-numeric:tabular-nums; }
.rtable th:first-child, .rtable td:first-child { text-align:left; }
.rtable th { font-size:12px; color:var(--muted); font-weight:500; }
.rtable tr.click { cursor:pointer; }
.rtable tr.click:hover td { background:var(--accent-soft); }
@media (max-width:560px) {
  .rtable thead { display:none; }
  .rtable, .rtable tbody { display:block; }
  .rtable tr { display:block; border:1px solid var(--border); border-radius:var(--r-md);
    padding:4px 12px; margin-bottom:8px; }
  .rtable td { display:flex; justify-content:space-between; gap:14px; align-items:baseline;
    border:none; padding:6px 0; text-align:right; white-space:normal; }
  .rtable td::before { content:attr(data-label); color:var(--muted); font-size:12px; text-align:left; }
  /* ячейка без data-label — «шапка» карточки (имя/дата): своя строка, слева, жирно */
  .rtable td:not([data-label]) { display:block; text-align:left; font-weight:600; }
  .rtable td:not([data-label])::before { content:none; }
  .rtable tr.click:hover td { background:none; }
  .rtable tr.total { border-color:var(--fg); }
}
