/* Палитра — та же, что AppPalette в app_alexandria/lib/theme/app_theme.dart */
:root {
  --bg: #FEFAE0;
  --card: #FFFFFF;
  --text: #45462A;
  --secondary: #8B8768;
  --border: #EFDCAC;
  --accent: #BC6C25;
  --accent-muted: #D4A373;
  --danger: #B03A2E;
  --toast: #45462A;
  --shadow: 0 8px 24px rgba(69, 70, 42, .12);
  --r-card: 16px;
  --r-button: 14px;
  --r-small: 10px;
  --sidebar: 232px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #2F3122; --card: #45462A; --text: #FEFAE0; --secondary: #B6AC84;
    --border: #5A5B3C; --danger: #E07A5F; --toast: #606C38;
    --shadow: 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #2F3122; --card: #45462A; --text: #FEFAE0; --secondary: #B6AC84;
  --border: #5A5B3C; --danger: #E07A5F; --toast: #606C38;
  --shadow: 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--accent); }
a.btn, a.circle, a.back, a.note-item, .nav a, .tabbar a, .sidebar .me { text-decoration: none; }
svg.i { width: 20px; height: 20px; fill: currentColor; flex: none; }
.hidden { display: none !important; }

.boot { height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.spinner.sm { width: 14px; height: 14px; border-width: 2px; }
.spinner.white { border-color: rgba(255,255,255,.35); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Вход ─────────────────────────────────────────────── */
.auth {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 24px 16px; text-align: center;
}
.auth .logo {
  width: 84px; height: 84px; border-radius: 22px; background: var(--accent);
  display: grid; place-items: center; color: #fff; margin-bottom: 24px;
}
.auth .logo svg { width: 42px; height: 42px; }
.auth h1 { font-size: 34px; letter-spacing: -.5px; margin: 0 0 8px; }
.auth p.tag { color: var(--secondary); margin: 0 0 48px; max-width: 360px; line-height: 1.4; }
.auth .box { width: 100%; max-width: 360px; }
.auth .terms { font-size: 12px; color: var(--secondary); margin-top: 16px; }
.auth .err { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 48px; padding: 0 20px; border-radius: var(--r-button);
  background: var(--accent); color: #fff; font-weight: 600; font-size: 15px;
  transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.block { width: 100%; height: 52px; }
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: var(--r-small); }

/* ── Каркас ───────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex: none; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 20px 12px;
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; font-weight: 700; font-size: 18px; }
.brand .mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.brand .mark svg { width: 18px; height: 18px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
  color: var(--text); text-decoration: none; font-weight: 500; margin-bottom: 2px;
}
.nav a:hover { background: var(--card); }
.nav a.active { background: var(--card); color: var(--accent); font-weight: 600; box-shadow: 0 1px 0 var(--border); }
.nav .badge {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--secondary); font-weight: 600;
}
.sidebar .me { text-decoration: none; margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px; font-size: 13px; color: var(--secondary); min-width: 0; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--border); flex: none; object-fit: cover; display: grid; place-items: center; font-weight: 700; color: var(--text); }
.me .email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.page { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 12px 20px 32px; }
.page.wide { max-width: none; padding: 0; }

.head { display: flex; align-items: flex-start; gap: 10px; padding: 12px 0 12px; }
.head h1 { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -.5px; line-height: 1.15; }
.head .sub { font-size: 13px; color: var(--secondary); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head .grow { flex: 1; min-width: 0; }
.circle {
  width: 34px; height: 34px; border-radius: 50%; background: var(--card);
  display: grid; place-items: center; color: var(--text); flex: none;
}
.circle:hover { color: var(--accent); }
.circle svg { width: 18px; height: 18px; }
.circle.spinning svg { animation: spin .8s linear infinite; }

.tabbar { display: none; }
.mobile-only { display: none; }

.card { background: var(--card); border-radius: var(--r-card); padding: 16px; }
.label { font-size: 12px; font-weight: 700; letter-spacing: .3px; color: var(--secondary); margin-bottom: 10px; text-transform: uppercase; }

/* ── Терминал ─────────────────────────────────────────── */
.terminal { display: flex; flex-direction: column; align-items: center; padding-top: 28px; }
.start {
  width: 190px; height: 190px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font-size: 17px; font-weight: 700; letter-spacing: .5px;
  box-shadow: 0 12px 32px rgba(188, 108, 37, .33);
  animation: pulse 2s ease-in-out infinite alternate;
}
.start svg { width: 40px; height: 40px; }
.start.busy { background: var(--accent-muted); box-shadow: none; animation: none; transform: scale(.95); }
.start:disabled { cursor: default; }
@keyframes pulse { from { transform: scale(.92); } to { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .start { animation: none; } }

.linkbox {
  width: 100%; max-width: 560px; margin-top: 28px; display: flex; gap: 8px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-button); padding: 6px;
}
.linkbox:focus-within { border-color: var(--accent); }
.linkbox input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 0 10px; height: 40px; font-size: 15px; }
.linkbox input::placeholder { color: var(--secondary); }
.hint { font-size: 13px; color: var(--secondary); margin-top: 12px; text-align: center; }
.hint.err { color: var(--danger); }

.jobs { width: 100%; max-width: 560px; margin-top: 28px; display: flex; flex-direction: column; gap: 10px; }
.job { display: flex; flex-direction: column; gap: 8px; }
.job .row { display: flex; align-items: center; gap: 10px; }
.job .dot { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.job .dot.ok { background: var(--accent); color: #fff; }
.job .dot.bad { background: var(--danger); color: #fff; }
.job .dot svg { width: 14px; height: 14px; }
.job .title { font-weight: 600; font-size: 15px; line-height: 1.3; }
.job .url { font-size: 12px; color: var(--secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .msg { font-size: 13px; color: var(--secondary); line-height: 1.4; }
.job .grow { flex: 1; min-width: 0; }
.bar { height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .6s ease; }
.job .actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Архив ────────────────────────────────────────────── */
.archive { display: flex; height: 100vh; }
.list-pane { width: 400px; flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--border); min-height: 0; }
.list-pane .top { padding: 12px 16px 8px; }
.list-pane .head { padding-left: 4px; padding-right: 4px; }
.search {
  display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 12px;
  padding: 0 12px; height: 40px; color: var(--secondary); border: 1px solid transparent;
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); }
.search svg { width: 18px; height: 18px; }
.notes { flex: 1; overflow-y: auto; padding: 4px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.note-item { text-align: left; background: var(--card); border-radius: var(--r-card); padding: 14px 16px; border: 2px solid transparent; display: block; width: 100%; }
.note-item:hover { border-color: var(--border); }
.note-item.active { border-color: var(--accent); }
.note-item .t { font-size: 16px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-item .s { font-size: 13px; color: var(--secondary); line-height: 1.4; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-item .m { display: flex; font-size: 12px; color: var(--secondary); margin-top: 8px; gap: 8px; }
.note-item .m .host { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item mark { background: rgba(188, 108, 37, .25); color: inherit; border-radius: 3px; }

.detail-pane { flex: 1; min-width: 0; overflow-y: auto; }
.detail { max-width: 780px; margin: 0 auto; padding: 16px 28px 40px; }
.detail .bar-top { display: flex; align-items: center; gap: 8px; padding: 4px 0 8px; position: relative; }
.detail .back { display: none; align-items: center; color: var(--accent); font-weight: 600; font-size: 17px; }
.detail .back svg { width: 26px; height: 26px; }
.detail h1 { font-size: 28px; line-height: 1.25; margin: 6px 0 10px; font-weight: 700; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--secondary); margin-bottom: 18px; }
.chip { background: var(--card); border-radius: 10px; padding: 5px 10px; font-size: 12px; font-weight: 600; color: var(--text); display: inline-flex; align-items: center; gap: 6px; }
button.chip:hover { color: var(--accent); }
.chip svg { width: 14px; height: 14px; }
.tag { font-size: 12px; color: var(--accent); }
.detail .card { margin-bottom: 12px; }
.detail .summary { font-size: 15px; line-height: 1.55; white-space: pre-wrap; }
.detail .src { font-size: 14px; word-break: break-all; }
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--secondary); padding: 40px 20px; gap: 6px; min-height: 50vh; }
.empty svg { width: 56px; height: 56px; margin-bottom: 8px; opacity: .8; }
.empty b { color: var(--text); font-size: 18px; }

.menu { position: absolute; right: 0; top: 42px; width: 210px; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); z-index: 20; overflow: hidden; border: 1px solid var(--border); }
.menu button { display: flex; align-items: center; width: 100%; padding: 12px 14px; font-weight: 500; gap: 10px; }
.menu button + button { border-top: 1px solid var(--border); }
.menu button:hover { background: var(--bg); }
.menu button span { flex: 1; text-align: left; }
.menu button svg { width: 18px; height: 18px; }
.menu .danger { color: var(--danger); }

/* Markdown */
.md { font-size: 15px; line-height: 1.65; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 16px; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.3em 0 .5em; line-height: 1.3; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 0 0 .9em; }
.md ul, .md ol { padding-left: 1.4em; }
.md li + li { margin-top: .25em; }
.md em { color: var(--secondary); }
.md blockquote { border-left: 3px solid var(--accent); padding-left: 12px; margin-left: 0; color: var(--secondary); }
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; background: var(--border); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--border); padding: 12px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.4em 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md img { max-width: 100%; border-radius: 8px; }
.md .wikilink { color: var(--accent); font-weight: 500; }

/* ── Настройки ────────────────────────────────────────── */
.settings { display: flex; flex-direction: column; gap: 14px; }
.kv { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.kv:last-child { border-bottom: 0; padding-bottom: 0; }
.kv:first-of-type { padding-top: 0; }
.kv .k { color: var(--secondary); flex: none; }
.kv .v { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.kv .v.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 8px 6px; border-radius: 10px; font-size: 14px; font-weight: 500; color: var(--secondary); }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
.desc { font-size: 13px; color: var(--secondary); margin: 8px 0 0; line-height: 1.45; }
.card .btn { margin-top: 14px; }

/* ── Тост и модалка ───────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: var(--toast); color: #FEFAE0; padding: 11px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 100; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.danger { background: var(--danger); color: #fff; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 90; padding: 16px; animation: fade .15s; }
.dialog { background: var(--card); border-radius: 18px; padding: 22px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.dialog h3 { margin: 0 0 8px; font-size: 18px; }
.dialog p { margin: 0 0 20px; color: var(--secondary); font-size: 14px; line-height: 1.45; }
.dialog .row { display: flex; gap: 10px; justify-content: flex-end; }
@keyframes fade { from { opacity: 0; } }

.drop-hint { position: fixed; inset: 0; background: rgba(188,108,37,.12); border: 3px dashed var(--accent); z-index: 80; pointer-events: none; }

/* ── Телефон ──────────────────────────────────────────── */
@media (max-width: 899px) {
  .sidebar { display: none; }
  .mobile-only { display: grid; }
  .main { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .page { padding: 8px 16px 24px; }
  .head h1 { font-size: 30px; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--bg); border-top: 1px solid var(--border);
    padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--secondary); text-decoration: none; padding: 4px 0; }
  .tabbar a.active { color: var(--accent); }
  .tabbar svg { width: 24px; height: 24px; }

  .archive { height: auto; min-height: calc(100vh - 70px); }
  .list-pane { width: 100%; border-right: 0; }
  .list-pane .top { padding: 8px 16px 8px; }
  .notes { overflow: visible; }
  .archive.has-note .list-pane { display: none; }
  .archive:not(.has-note) .detail-pane { display: none; }
  .detail { padding: 8px 16px 32px; }
  .detail .back { display: inline-flex; margin-left: -8px; }
  .detail h1 { font-size: 26px; }
  .start { width: 170px; height: 170px; }
  .terminal { padding-top: 16px; }
}
