/* "Command console" — a fixed dark identity, deliberately not adapted to Telegram's own
   light/dark theme. Chosen direction; see src/miniapp/assets/README-less design note in the
   handover: right-side section rail on wide viewports, bottom tab bar on phone widths. */

:root {
  --bg: oklch(0.155 0.014 250);
  --panel: oklch(0.195 0.016 250);
  --card: oklch(0.215 0.017 250);
  --card-2: oklch(0.185 0.015 250);
  --border: oklch(1 0 0 / 0.08);
  --border-2: oklch(1 0 0 / 0.12);
  --text: oklch(0.94 0.008 250);
  --muted: oklch(0.60 0.018 250);
  --muted-2: oklch(0.48 0.016 250);
  --accent: oklch(0.78 0.13 195);
  --accent-ink: oklch(0.16 0.02 250);
  --accent-soft: oklch(0.78 0.13 195 / 0.14);
  --accent-text: oklch(0.86 0.11 195);
  --success: oklch(0.72 0.15 152);
  --success-soft: oklch(0.72 0.15 152 / 0.14);
  --danger: oklch(0.68 0.19 26);
  --danger-soft: oklch(0.68 0.19 26 / 0.13);
  --rail-w: 236px;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace; letter-spacing: -0.01em; }

a { color: var(--accent-text); text-decoration: none; }
a:hover { color: var(--accent); }
::selection { background: var(--accent-soft); }

button { font-family: inherit; }

#app { display: flex; min-height: 100%; }

.state {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
  width: 100%;
}
.state.error { color: var(--danger); }
.state a.button, button.button, a.button {
  display: inline-block;
  margin-top: 12px;
  padding: 10px 20px;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  border: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

/* ===== rail (wide) / tab bar (narrow) ===== */

#rail {
  width: var(--rail-w);
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}

#rail .brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 18px 16px;
}
#rail .brand .mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
}
#rail .brand .name {
  font-weight: 600; font-size: 13.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#rail .brand .sub { font-size: 11px; color: var(--muted); margin-top: 1px; }

#rail .sep { height: 1px; background: var(--border); margin: 2px 18px 12px; }

#rail nav { display: flex; flex-direction: column; gap: 2px; padding: 0 12px; flex: 1; overflow-y: auto; }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--muted);
  cursor: pointer; border: none; background: none;
  font-size: 13.5px; font-family: inherit; text-align: right;
  position: relative;
  width: 100%;
}
.nav-item svg { flex-shrink: 0; }
.nav-item .nav-label { flex: 1; }
.nav-item .nav-badge {
  font-size: 10.5px; color: var(--muted-2);
  background: var(--card-2); border-radius: 6px; padding: 2px 6px;
}
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}
.nav-item.active::before {
  content: ""; position: absolute; right: 0; top: 8px; bottom: 8px;
  width: 3px; border-radius: 3px; background: var(--accent);
}

#rail .foot {
  padding: 14px 18px 18px; font-size: 11px; color: var(--muted-2);
  display: flex; align-items: center; gap: 6px;
}

/* The bottom-sheet "بیشتر" list — only ever opened from the mobile tab bar, but defined
   unconditionally since it costs nothing unused on a wide screen. */
#nav-more { display: none; }
#more-sheet-backdrop {
  position: fixed; inset: 0; background: oklch(0 0 0 / 0.5);
  z-index: 29; opacity: 0; pointer-events: none; transition: opacity 0.15s;
}
#more-sheet-backdrop.open { opacity: 1; pointer-events: auto; }
#more-sheet {
  position: fixed; right: 0; left: 0; bottom: 0;
  background: var(--panel); border-radius: 18px 18px 0 0;
  padding: 10px 10px calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 30; transform: translateY(100%); transition: transform 0.2s;
}
#more-sheet.open { transform: translateY(0); }
#more-sheet .handle {
  width: 36px; height: 4px; border-radius: 2px; background: var(--border-2);
  margin: 6px auto 14px;
}
#more-sheet .sheet-item {
  display: flex; align-items: center; gap: 14px; padding: 14px;
  border-radius: 12px; color: var(--text); font-size: 14px; width: 100%;
  border: none; background: none; text-align: right; font-family: inherit;
}
#more-sheet .sheet-item.active { color: var(--accent-text); background: var(--accent-soft); }

/* narrow: collapse rail into a fixed bottom tab bar. Eight destinations crammed into one row
   is what made this feel cramped and tiny — five is the iOS/Android ceiling for a bottom bar
   before it needs a "More" overflow, so only the four most-used pages (تنظیمات، قفل ها، لیست
   ها، ادمین ها) get a permanent slot; the rest live behind «بیشتر», a bottom sheet. That
   leaves five items instead of eight, so each one gets real width for a properly-sized icon
   and a label that's always visible, not just on the active tab.
   `env(safe-area-inset-bottom)` keeps the bar clear of the device's own home-indicator area,
   which Telegram's WebView does not account for on its own. */
@media (max-width: 720px) {
  :root { --tabbar-h: 66px; }

  #rail {
    position: fixed; inset: auto 0 0 0; top: auto;
    width: 100%;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    flex-direction: row;
    border-left: none; border-top: 1px solid var(--border);
    background: var(--panel);
    z-index: 20;
  }
  #rail .brand, #rail .sep, #rail .foot { display: none; }
  #rail nav {
    flex-direction: row; padding: 0 2px; gap: 0;
    align-items: stretch; width: 100%;
  }
  .nav-item.secondary { display: none; }
  .nav-item {
    flex-direction: column; justify-content: center; gap: 4px;
    flex: 1; min-width: 0; padding: 9px 4px;
    text-align: center; align-items: center;
    border-radius: 0;
  }
  .nav-item svg { width: 23px; height: 23px; }
  .nav-item.active { background: none; }
  .nav-item .nav-label {
    font-size: 10.5px; flex: none; max-width: 100%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .nav-item .nav-badge {
    position: absolute; top: 4px; left: 50%; transform: translateX(10px);
    font-size: 9px; padding: 1px 5px;
  }
  .nav-item.active::before {
    right: auto; left: 50%; top: 5px; bottom: auto;
    width: 4px; height: 4px; border-radius: 50%; transform: translateX(50%);
  }

  #nav-more {
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    gap: 4px; flex: 1; min-width: 0; padding: 9px 4px;
    border: none; background: none; color: var(--muted); font-family: inherit;
    cursor: pointer; position: relative;
  }
  #nav-more svg { width: 23px; height: 23px; }
  #nav-more .nav-label { font-size: 10.5px; }
  #nav-more.active { color: var(--accent-text); font-weight: 600; }
  #nav-more.active::before {
    content: ""; position: absolute; left: 50%; top: 5px;
    width: 4px; height: 4px; border-radius: 50%; background: var(--accent);
    transform: translateX(50%);
  }

  #main {
    padding: 16px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px) !important;
  }
  .stat-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-strip .stat-card:last-child { grid-column: 1 / -1; }
  .page-head .title { font-size: 17px; }
}

/* ===== main content ===== */

#main { flex: 1; min-width: 0; padding: 30px 36px 48px; }

.page-head { margin-bottom: 22px; }
.page-head .title { font-size: 19px; font-weight: 700; }
.page-head .subtitle { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.page-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

.back-btn {
  border: none; background: var(--card); color: var(--accent-text);
  font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 8px 14px; border-radius: 10px; margin-bottom: 16px;
}

.stat-strip {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px; margin-bottom: 24px;
}
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px 16px;
}
.stat-card .label { font-size: 11px; color: var(--muted); margin-bottom: 7px; }
.stat-card .value { font-size: 21px; font-weight: 600; }
.stat-card .value .of { font-size: 12px; color: var(--muted-2); margin-right: 2px; }

/* ===== cards ===== */

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; margin-bottom: 10px; overflow: hidden;
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 15px 18px; cursor: pointer; border: none; background: none;
  width: 100%; text-align: right; font-family: inherit; color: inherit;
}
.card-header .left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.card-header .icon {
  width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: oklch(1 0 0 / 0.05); color: var(--muted);
}
.card-header .icon.on { background: var(--success-soft); color: var(--success); }
.card-header .titles { min-width: 0; }
.card-header .t { font-weight: 600; font-size: 13.5px; }
.card-header .s { font-size: 12px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-header .chev { color: var(--muted-2); transition: transform 0.15s; flex-shrink: 0; }
.card-header.expanded .chev { transform: rotate(90deg); }

.card-body { padding: 4px 18px 16px; border-top: 1px solid var(--border); }
.card-body .field { padding-top: 14px; }
.card-body .field-label { font-size: 12px; color: var(--muted); margin-bottom: 9px; }

/* ===== controls ===== */

.switch {
  width: 42px; height: 24px; border-radius: 12px; border: none;
  background: oklch(1 0 0 / 0.12); position: relative; flex-shrink: 0; cursor: pointer;
  transition: background 0.15s;
}
.switch.on { background: var(--success); }
.switch::after {
  content: ""; position: absolute; top: 3px; right: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: oklch(0.98 0 0);
  transition: transform 0.15s;
}
.switch.on::after { transform: translateX(-18px); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 15px; border-radius: 999px; border: 1px solid var(--border-2);
  background: transparent; color: var(--muted); font-size: 13px; cursor: pointer;
  font-family: inherit;
}
.chip.selected { background: var(--accent); color: var(--accent-ink); font-weight: 600; border-color: var(--accent); }
.chip.danger { border-color: var(--danger); color: var(--danger); }
.chip.danger.selected { background: var(--danger); color: oklch(0.98 0 0); border-color: var(--danger); }

.number-input-row { margin-top: 12px; }
.number-input-row input[type="number"] {
  width: 100%; padding: 9px 12px; border-radius: 9px;
  border: 1px solid var(--border-2); background: var(--card-2); color: var(--text);
  font-family: inherit; font-size: 14px;
}

.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row .icon {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: oklch(1 0 0 / 0.05); color: var(--muted);
}
.list-row .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 8px; flex: 1; }
.list-row button.remove {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border: none; background: none; color: var(--danger); font-size: 15px; cursor: pointer;
}
.list-row button.remove:active { background: var(--danger-soft); }

.list-search {
  margin: 12px 14px; padding: 9px 13px; border-radius: 10px;
  border: 1px solid var(--border-2); background: var(--card-2); color: var(--text);
  font-size: 13px; font-family: inherit; width: calc(100% - 28px);
}
.list-meta { padding: 2px 2px 12px; font-size: 12px; color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; flex-shrink: 0;
  font-size: 10.5px; padding: 2px 9px; border-radius: 999px;
}
.badge.owner { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.badge.bot { background: var(--card-2); color: var(--muted-2); }

.danger-action {
  width: 100%; margin-top: 10px; padding: 11px; border-radius: 11px;
  border: 1px solid var(--danger); background: var(--danger-soft); color: var(--danger);
  cursor: pointer; font-family: inherit; font-weight: 600; font-size: 13.5px;
}

.hint-text { padding: 12px 0 0; color: var(--muted); font-size: 12px; }

.text-input, textarea.text-input {
  width: 100%; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--border-2); background: var(--card-2); color: var(--text);
  font-size: 14px; font-family: inherit; min-height: 44px;
}
textarea.text-input { min-height: 90px; resize: vertical; }

.field-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 18px; border-bottom: 1px solid var(--border); }
.field-row:last-child { border-bottom: none; }
