:root {
  --bg: #f3f7f2;
  --panel: #ffffff;
  --ink: #10231b;
  --muted: #5d766b;
  --line: #d7e4dc;
  --forest: #0b3d2e;
  --emerald: #1b8f62;
  --mint: #3ddc97;
  --danger: #d45242;
  --warn: #d99212;
  --info: #2b7de9;
  --shadow: 0 16px 40px rgba(11, 61, 46, 0.08);
  --tab-h: 64px;
}

:root[data-theme="dark"] {
  --bg: #051912;
  --panel: #0e2f24;
  --ink: #eef7f2;
  --muted: #93b3a5;
  --line: #1b4336;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(61, 220, 151, 0.16), transparent 50%),
    var(--bg);
  color: var(--ink);
}

.hidden { display: none !important; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card, .panel, .stat, table {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.login-card { width: min(420px, 100%); padding: 32px; }
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}
.mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--forest);
  color: #FAF7F2;
  display: grid;
  place-items: center;
  font-weight: 800;
}
h1, h2, h3 { margin: 0 0 8px; }
.muted { color: var(--muted); }

label { display: block; font-weight: 600; margin: 16px 0 6px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
}
textarea { min-height: 80px; resize: vertical; }

button, .btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: var(--forest);
  color: white;
}
button.secondary, .btn.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.danger { background: var(--danger); }
button.ghost { background: transparent; color: var(--emerald); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

/* ── Desktop layout ─────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}
.side {
  background: var(--forest);
  color: white;
  padding: 22px 16px;
}
.side a {
  display: block;
  color: white;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
  margin-top: 6px;
}
.side a.active, .side a:hover { background: rgba(255,255,255,0.12); }
.main { padding: 24px; }
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.stat { padding: 16px; }
.stat b { font-size: 28px; display: block; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1; min-width: 180px; }
.toolbar { display: flex; justify-content: space-between; gap: 12px; margin: 8px 0 14px; }
table { width: 100%; border-collapse: collapse; overflow: hidden; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
th { color: var(--muted); font-weight: 700; }
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
}
.bound { background: #d9f7e8; color: #0b3d2e; }
.unbound { background: #fff3d6; color: #8a5a00; }
.revoked { background: #ffd9d4; color: #8a1f14; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.error { color: var(--danger); font-weight: 700; min-height: 1.2em; }
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: var(--ink);
  color: white;
  padding: 12px 16px;
  border-radius: 12px;
  z-index: 999;
}

/* ── Bottom tab bar (mobile-only, hidden on desktop) ───────────────────── */
.bottom-tab-bar { display: none; }

/* ── Mobile card list (hides tables on small screens) ──────────────────── */
.card-list { display: none; }

/* ── Tablet: collapse sidebar to top strip ─────────────────────────────── */
@media (max-width: 960px) and (min-width: 601px) {
  .app { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .side {
    display: flex;
    gap: 8px;
    overflow: auto;
    align-items: center;
    padding: 12px 16px;
  }
  .side nav { display: flex; gap: 8px; }
}

/* ── Mobile: bottom tab bar + card layout ──────────────────────────────── */
@media (max-width: 600px) {
  /* Kill sidebar */
  .side { display: none !important; }

  /* App fills screen, leaves room for tab bar */
  .app {
    display: block;
    min-height: 100vh;
    padding-bottom: var(--tab-h);
  }

  .main { padding: 16px 12px; }

  /* Single-column stats */
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
  .stat { padding: 12px; }
  .stat b { font-size: 22px; }

  /* Top bar: title left, action buttons right */
  .top { margin-bottom: 14px; flex-wrap: wrap; }
  .top .actions button { padding: 8px 10px; font-size: 13px; }

  /* Row inputs stack */
  .row { flex-direction: column; }
  .row > * { min-width: 0; }

  /* Hide real tables; show card lists instead */
  table.mobile-hide { display: none !important; }
  .card-list { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
  .m-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px;
    box-shadow: var(--shadow);
  }
  .m-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
  }
  .m-card-row:last-child { margin-bottom: 0; }
  .m-card-label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
  .m-card-val { font-size: 14px; font-weight: 500; }
  .m-card-key { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; }
  .m-card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
  .m-card-actions button { padding: 8px 12px; font-size: 13px; }

  /* Bottom tab bar */
  .bottom-tab-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--tab-h);
    background: var(--forest);
    border-top: 1px solid rgba(255,255,255,0.08);
    z-index: 100;
    justify-content: space-around;
    align-items: stretch;
  }
  .tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: rgba(255,255,255,0.55);
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: color .15s;
  }
  .tab-btn svg { width: 22px; height: 22px; }
  .tab-btn.active { color: var(--forest); }
  .tab-btn.active svg { stroke: var(--forest); }
  :root[data-theme="dark"] .tab-btn.active { color: #52e3a0; }
  :root[data-theme="dark"] .tab-btn.active svg { stroke: #52e3a0; }

  /* Move toast above tab bar */
  .toast { bottom: calc(var(--tab-h) + 10px); }
}

/* ── v1.1.59 plan & access editor ─────────────────────────────────────── */
.access-box {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid rgba(127, 127, 127, 0.25);
  border-radius: 14px;
}
.access-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 700;
}
.access-box label { display: block; margin: 6px 0 4px; font-size: 13px; }
.access-box select { width: 100%; padding: 9px 10px; border-radius: 10px; }
.access-box h4 { margin: 12px 0 6px; font-size: 13px; opacity: 0.85; }
.access-cols { display: grid; gap: 12px; }
.chk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 6px 14px;
}
.chk {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 5px 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.chk:hover { background: rgba(127, 127, 127, 0.1); }
.chk input { width: 16px; height: 16px; accent-color: var(--mint, #3ddc97); }
.badge.plan { letter-spacing: 0.4px; }
.badge.plan-starter { background: rgba(230, 195, 92, 0.16); color: #b78e1f; border: 1px solid rgba(230, 195, 92, 0.5); }
.badge.plan-growth { background: rgba(61, 220, 151, 0.14); color: #1d9e6e; border: 1px solid rgba(61, 220, 151, 0.5); }
.badge.plan-custom, .badge.plan-full { background: rgba(90, 140, 255, 0.14); color: #4a6fd6; border: 1px solid rgba(90, 140, 255, 0.45); }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }
html[data-theme="dark"] .badge.plan-starter { color: #e6c35c; }
html[data-theme="dark"] .badge.plan-growth { color: #3ddc97; }
html[data-theme="dark"] .badge.plan-custom,
html[data-theme="dark"] .badge.plan-full { color: #8fb0ff; }
@media (max-width: 600px) {
  .chk-grid { grid-template-columns: 1fr; }
  .access-box .toolbar { flex-wrap: wrap; }
}
