:root {
  --bg: #0b0d12;
  --bg-elev: #10141c;
  --surface: #151a24;
  --surface-2: #1c222e;
  --surface-3: #232a38;
  --border: #262d3b;
  --border-strong: #333c4d;
  --text: #eef1f6;
  --muted: #98a2b3;
  --faint: #6b7688;
  --primary: #4f7cff;
  --primary-hover: #3f6ef0;
  --primary-soft: rgba(79, 124, 255, 0.14);
  --danger: #f26d6d;
  --danger-soft: rgba(242, 109, 109, 0.12);
  --ok: #34d399;
  --warn: #fbbf24;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --tap: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
a { color: var(--primary); text-decoration: none; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: .85em; }
hr { border: none; border-top: 1px solid var(--border); margin: 1.2rem 0; }
h1 { font-size: 1.6rem; letter-spacing: -0.02em; margin: 0 0 .3rem; }
h2 { font-size: 1.1rem; letter-spacing: -0.01em; }

.icon { display: inline-block; vertical-align: -0.18em; flex-shrink: 0; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem 1rem;
  padding-top: max(.7rem, env(safe-area-inset-top, 0px));
  background: rgba(16, 20, 28, 0.85);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--text); font-size: 1.05rem; white-space: nowrap; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #7c5cff); color: #fff; flex-shrink: 0;
}
.top-nav { display: none; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }

.icon-btn {
  display: inline-grid; place-items: center; width: var(--tap); height: var(--tap);
  border: 1px solid transparent; background: transparent; color: var(--muted);
  border-radius: 12px; cursor: pointer;
}
.icon-btn:hover, .icon-btn:active { background: var(--surface-2); color: var(--text); }

/* ---------- Layout ---------- */
.container { max-width: 780px; margin: 0 auto; padding: 1.1rem 1rem 2rem; }
.container.has-bottom-nav { padding-bottom: calc(76px + var(--safe-b) + 1rem); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Flash ---------- */
.flashes { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.flash {
  display: flex; align-items: flex-start; gap: .55rem;
  padding: .75rem .9rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); font-size: .92rem;
  box-shadow: var(--shadow-sm);
}
.flash-icon { display: inline-flex; margin-top: .1rem; }
.flash-success { border-color: rgba(52,211,153,.35); background: rgba(52,211,153,.08); color: #a7f3d0; }
.flash-success .flash-icon { color: var(--ok); }
.flash-error { border-color: rgba(242,109,109,.35); background: var(--danger-soft); color: #fecaca; }
.flash-error .flash-icon { color: var(--danger); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}
.card > h2:first-child { margin-top: 0; display: inline-flex; align-items: center; gap: .5rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: var(--tap); padding: .6rem 1rem;
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  border-radius: 12px; font-size: .95rem; font-weight: 600; cursor: pointer;
  transition: transform .05s ease, background .15s ease, border-color .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn:hover { border-color: var(--faint); }
.btn-sm { min-height: 38px; padding: .4rem .7rem; font-size: .85rem; border-radius: 10px; }
.btn-primary { background: linear-gradient(135deg, var(--primary), #6a7cff); border-color: transparent; color: #fff; box-shadow: 0 4px 14px rgba(79,124,255,.3); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-danger { background: transparent; border-color: rgba(242,109,109,.4); color: #ff9a9a; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { background: var(--surface-2); }
.btn-block { width: 100%; }
.inline { display: inline; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }

/* ---------- Badges / chips ---------- */
.badge { display: inline-flex; align-items: center; gap: .25rem; padding: .18rem .6rem; border-radius: 999px; font-size: .74rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.badge .icon { vertical-align: -0.15em; }
.badge-ok { color: var(--ok); border-color: rgba(52,211,153,.35); background: rgba(52,211,153,.08); }
.badge-warn { color: var(--warn); border-color: rgba(251,191,36,.35); background: rgba(251,191,36,.08); }
.chip { display: inline-flex; align-items: center; padding: .12rem .5rem; border-radius: 7px; font-size: .72rem; font-weight: 600; background: var(--primary-soft); color: #a9c0ff; }

/* ---------- Page head ---------- */
.page-head { margin-bottom: 1.2rem; }
.page-head h1 { margin-bottom: .35rem; }
.quota-line { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; color: var(--muted); font-size: .92rem; }

/* ---------- Forms ---------- */
.form-card { margin-top: .8rem; }
.grid { display: grid; grid-template-columns: 1fr; gap: .85rem; margin-bottom: 1rem; }
.grid .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: .35rem; font-size: .82rem; font-weight: 600; color: var(--muted); }
input, select {
  background: var(--bg-elev); border: 1px solid var(--border-strong); color: var(--text);
  padding: .7rem .8rem; border-radius: var(--radius-sm); font-size: 16px; width: 100%;
  min-height: var(--tap); -webkit-appearance: none; appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2398a2b3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2.2rem;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input::placeholder { color: var(--faint); }

/* ---------- Add panel (details/summary) ---------- */
details.add-panel { margin-top: .2rem; }
details summary { list-style: none; }
details summary::-webkit-details-marker { display: none; }
.add-panel > summary { cursor: pointer; }

/* ---------- Watch list ---------- */
.watch-list { display: flex; flex-direction: column; gap: .75rem; }
.watch {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .95rem 1rem; box-shadow: var(--shadow-sm);
}
.watch.inactive { opacity: .55; }
.watch-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .6rem; }
.watch-title { font-weight: 700; font-size: 1.02rem; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.watch-meta { margin-top: .4rem; display: flex; flex-wrap: wrap; gap: .35rem .7rem; color: var(--muted); font-size: .84rem; }
.watch-meta span { display: inline-flex; align-items: center; gap: .28rem; }
.watch-actions { display: flex; gap: .4rem; margin-top: .85rem; }
.watch-actions form { flex: 1; }
.watch-actions .btn { width: 100%; }
.edit-details { margin-top: .5rem; }
.edit-details > summary { width: 100%; cursor: pointer; }
.edit-details[open] > summary { display: none; }
.edit-form { margin-top: 0; background: var(--surface-2); }

.empty { text-align: center; color: var(--muted); padding: 3rem 1.2rem; border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface); }
.empty .icon { color: var(--faint); margin-bottom: .5rem; }

/* ---------- Login ---------- */
.login-wrap { min-height: 70vh; display: grid; place-items: center; }
.login-card {
  max-width: 400px; width: 100%; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 2.2rem 1.6rem; box-shadow: var(--shadow);
}
.login-logo { width: 60px; height: 60px; border-radius: 18px; margin: 0 auto 1rem; display: grid; place-items: center; background: linear-gradient(135deg, var(--primary), #7c5cff); color: #fff; box-shadow: 0 8px 24px rgba(79,124,255,.35); }
.login-card h1 { font-size: 1.5rem; }
.tg-login { margin: 1.6rem 0 .6rem; display: flex; justify-content: center; min-height: 48px; }
.dev-login { text-align: left; margin-top: 1rem; }
.dev-login .row { margin-top: .4rem; }

/* ---------- Key/value & settings ---------- */
table.kv { width: 100%; border-collapse: collapse; }
table.kv td { padding: .55rem 0; border-bottom: 1px solid var(--border); font-size: .92rem; }
table.kv tr:last-child td { border-bottom: none; }
table.kv td:first-child { color: var(--muted); width: 42%; }
.steps { color: var(--muted); font-size: .9rem; padding-left: 1.1rem; }
.steps li { margin: .3rem 0; }

/* ---------- Data lists (admin) → cards on mobile ---------- */
.data-cards { display: flex; flex-direction: column; gap: .7rem; }
.dc {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .85rem .9rem;
}
.dc.muted-row { opacity: .55; }
.dc-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.dc-title { font-weight: 700; }
.dc-row { display: flex; justify-content: space-between; gap: .8rem; font-size: .86rem; padding: .2rem 0; }
.dc-row .k { color: var(--faint); }
.dc-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.copy-input { font-size: .78rem; font-family: ui-monospace, monospace; }

.logs { background: #05070b; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .8rem; font-size: .76rem; line-height: 1.5; max-height: 300px; overflow-y: auto; white-space: pre-wrap; word-break: break-word; color: #9fb0c7; margin-top: .8rem; font-family: ui-monospace, monospace; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
  display: flex; align-items: stretch;
  background: rgba(16, 20, 28, 0.92);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}
.bottom-nav a, .bottom-nav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: .5rem 0 .55rem; min-height: 60px;
  color: var(--faint); font-size: .68rem; font-weight: 600;
  background: none; border: none; cursor: pointer; font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav form { flex: 1; display: flex; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a:active, .bottom-nav button:active { background: rgba(255,255,255,.03); }

/* ---------- Desktop ---------- */
@media (min-width: 720px) {
  .top-nav { display: flex; align-items: center; gap: .3rem; margin-left: .5rem; }
  .top-nav a { color: var(--muted); padding: .5rem .8rem; border-radius: 10px; font-weight: 600; font-size: .92rem; }
  .top-nav a:hover { color: var(--text); background: var(--surface-2); }
  .top-nav a.active { color: var(--text); background: var(--primary-soft); }
  .bottom-nav { display: none; }
  .container.has-bottom-nav { padding-bottom: 2rem; }
  .grid { grid-template-columns: 1fr 1fr; }
  .watch-actions { justify-content: flex-start; }
  .watch-actions form { flex: 0 0 auto; }
  .watch-actions .btn { width: auto; }
  .edit-details > summary { width: auto; display: inline-flex; }
  .add-panel > summary { width: auto; }
  h1 { font-size: 1.8rem; }
}
