:root {
  --brand: #1F4E79;
  --brand-2: #2E6DA4;
  --brand-soft: #E8F0F8;
  --bg: #F4F6F9;
  --card: #FFFFFF;
  --text: #16202B;
  --muted: #5F6B7A;
  --line: #E2E7EE;
  --ok: #1E7F4F;
  --ok-soft: #E3F4EA;
  --warn: #9A6200;
  --warn-soft: #FFF3D6;
  --err: #B42318;
  --err-soft: #FDE8E7;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 4px 16px rgba(16, 32, 48, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #6FA8DC; --brand-2: #8BBBE6; --brand-soft: #1B2B3B;
    --bg: #0F141A; --card: #182029; --text: #E8EDF3; --muted: #9AA6B4; --line: #26313D;
    --ok: #5FCB8F; --ok-soft: #14301F; --warn: #F2C063; --warn-soft: #33290F;
    --err: #F2827A; --err-soft: #3A1714;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #6FA8DC; --brand-2: #8BBBE6; --brand-soft: #1B2B3B;
  --bg: #0F141A; --card: #182029; --text: #E8EDF3; --muted: #9AA6B4; --line: #26313D;
  --ok: #5FCB8F; --ok-soft: #14301F; --warn: #F2C063; --warn-soft: #33290F;
  --err: #F2827A; --err-soft: #3A1714;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { min-height: 100vh; display: flex; }
.side {
  display: none; width: 240px; flex: none; background: var(--card); border-right: 1px solid var(--line);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; padding: 4px 8px 20px; }
.brand img { width: 32px; height: 32px; border-radius: 8px; }
.side a {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; color: var(--text);
  text-decoration: none; font-weight: 500; margin-bottom: 2px;
}
.side a.active { background: var(--brand-soft); color: var(--brand); }
.side .me { position: absolute; bottom: 16px; left: 14px; right: 14px; font-size: .85rem; }
main { flex: 1; min-width: 0; padding: 16px 16px calc(96px + var(--safe-b)); max-width: 960px; margin: 0 auto; }
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px;
  font-size: .72rem; color: var(--muted); text-decoration: none; position: relative;
}
.tabs a.active { color: var(--brand); font-weight: 600; }
.ic { width: 24px; height: 24px; display: inline-block; }
.badge-dot {
  position: absolute; top: 4px; left: calc(50% + 6px); background: var(--err); color: #fff; border-radius: 10px;
  font-size: .65rem; min-width: 17px; padding: 0 4px; line-height: 17px; text-align: center; font-weight: 700;
}
.side .badge-dot { position: static; margin-left: auto; }

@media (min-width: 900px) {
  .side { display: block; }
  .tabs { display: none; }
  main { padding: 28px 32px 48px; }
}

/* ---------- components ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; cursor: pointer;
  border-radius: 12px; padding: 12px 18px; font-weight: 600; background: var(--brand-soft); color: var(--brand);
  min-height: 46px; text-decoration: none; transition: transform .05s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #0F141A; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #0F141A; } }
.btn.danger { background: var(--err-soft); color: var(--err); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

label.f { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
input.i, select.i, textarea.i {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 12px 14px;
  min-height: 46px; outline: none;
}
input.i:focus, select.i:focus, textarea.i:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.upload {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.upload label {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  padding: 18px 10px; border-radius: var(--radius); font-weight: 600; text-align: center; min-height: 96px;
}
.upload .cam { background: var(--brand); color: #fff; }
:root[data-theme="dark"] .upload .cam { color: #0F141A; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .upload .cam { color: #0F141A; } }
.upload .gal { background: var(--card); color: var(--brand); box-shadow: var(--shadow); }
.upload input { display: none; }
.upload .ic { width: 30px; height: 30px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 14px;
  font-size: .88rem; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
:root[data-theme="dark"] .chip.on { color: #0F141A; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.on { color: #0F141A; } }

.list { display: flex; flex-direction: column; gap: 10px; }
.note {
  display: flex; gap: 12px; align-items: center; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 10px; cursor: pointer; border: 2px solid transparent;
}
.note.sel { border-color: var(--brand); }
.thumb {
  width: 58px; height: 72px; flex: none; border-radius: 10px; background: var(--bg) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.note .meta { flex: 1; min-width: 0; }
.note .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note .s { font-size: .85rem; color: var(--muted); }
.note .v { text-align: right; font-weight: 700; white-space: nowrap; }
.note .v small { display: block; font-weight: 500; color: var(--muted); font-size: .75rem; }

.pill { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-right: 4px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--err-soft); color: var(--err); }
.pill.info { background: var(--brand-soft); color: var(--brand); }

.sticky-cta {
  position: fixed; left: 0; right: 0; bottom: calc(58px + var(--safe-b)); padding: 10px 16px; z-index: 15;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.sticky-cta .btn { width: 100%; max-width: 928px; margin: 0 auto; display: flex; box-shadow: 0 6px 20px rgba(31,78,121,.3); }
@media (min-width: 900px) { .sticky-cta { left: 240px; bottom: 0; } }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty .ic { width: 48px; height: 48px; opacity: .5; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--brand-soft); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
.boot { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- sheet (modal) ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(10,18,28,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); width: 100%; max-width: 760px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); animation: up .18s ease-out;
}
@media (min-width: 900px) { .backdrop { align-items: center; } .sheet { border-radius: 20px; padding: 24px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.x { background: var(--bg); border: 0; border-radius: 50%; width: 36px; height: 36px; cursor: pointer; font-size: 20px; line-height: 1; }
.editor { display: grid; gap: 16px; }
@media (min-width: 700px) { .editor { grid-template-columns: 1fr 1fr; } }
.editor img { width: 100%; border-radius: 12px; background: var(--bg); max-height: 60vh; object-fit: contain; }

/* ---------- tables / stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.stat b { display: block; font-size: 1.35rem; }
.stat span { font-size: .8rem; color: var(--muted); }
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.scroll-x { overflow-x: auto; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px 22px; }
.auth .logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 14px; }

#toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: #16202B; color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 60; opacity: 0;
  pointer-events: none; transition: all .2s; max-width: calc(100% - 32px); font-size: .95rem;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--err); }

.install {
  display: flex; gap: 12px; align-items: center; background: var(--brand-soft); color: var(--text);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: .9rem;
}
.progress { height: 6px; background: var(--brand-soft); border-radius: 6px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--brand); transition: width .3s; }
.row > .btn.grow { flex: 1 1 140px; white-space: nowrap; }
.avatar { flex: none; width: 42px; height: 42px; border-radius: 50%; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; text-decoration: none; }
@media (min-width: 900px) { .avatar { display: none; } }
