/* =============================================
   DESIGN TOKENS -- three lightness modes, one
   brand hue (orange) throughout.
   ============================================= */
[data-theme="dark"] {
  --bg-primary: #0f1417;
  --bg-secondary: #1a2126;
  --text-primary: #f5f2ee;
  --text-secondary: #9aa5ab;
  --accent: #f97316;
  --accent-hover: #ea580c;
  --accent-subtle: rgba(249, 115, 22, 0.14);
  --accent-ink: #ffedd5;
  --border: rgba(255, 255, 255, 0.08);
  --glass-bg: rgba(26, 33, 38, 0.7);
  --danger: #ef4444;
  --danger-subtle: rgba(239, 68, 68, 0.14);
  --success: #22c55e;
  --success-subtle: rgba(34, 197, 94, 0.14);
  --warn: #eab308;
  --warn-subtle: rgba(234, 179, 8, 0.14);
}

[data-theme="black"] {
  --bg-primary: #000000;
  --bg-secondary: #121212;
  --text-primary: #ffffff;
  --text-secondary: #8a8a8a;
  --accent: #fb923c;
  --accent-hover: #f97316;
  --accent-subtle: rgba(251, 146, 60, 0.16);
  --accent-ink: #ffedd5;
  --border: rgba(255, 255, 255, 0.14);
  --glass-bg: rgba(10, 10, 10, 0.75);
  --danger: #f87171;
  --danger-subtle: rgba(248, 113, 113, 0.14);
  --success: #4ade80;
  --success-subtle: rgba(74, 222, 128, 0.14);
  --warn: #facc15;
  --warn-subtle: rgba(250, 204, 21, 0.14);
}

[data-theme="sunny"] {
  --bg-primary: #fffaf5;
  --bg-secondary: #fdefdf;
  --text-primary: #3a2a18;
  --text-secondary: #7a6249;
  --accent: #ea580c;
  --accent-hover: #c2410c;
  --accent-subtle: rgba(234, 88, 12, 0.14);
  --accent-ink: #7c2d12;
  --border: rgba(194, 149, 96, 0.35);
  --glass-bg: rgba(255, 250, 245, 0.85);
  --danger: #dc2626;
  --danger-subtle: rgba(220, 38, 38, 0.12);
  --success: #15803d;
  --success-subtle: rgba(21, 128, 61, 0.12);
  --warn: #a16207;
  --warn-subtle: rgba(161, 98, 7, 0.12);
}

.theme-btn:hover, .theme-btn.active,
.lang-btn:hover, .lang-btn.active {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 0.0625rem var(--accent);
}

/* Persian needs its own font stack -- the Latin system-ui stack has
   no real Farsi glyphs to fall back on. */
[dir="rtl"] {
  font-family: Tahoma, "Vazirmatn", "IRANSans", system-ui, sans-serif;
}

/* =============================================
   RESET & BASE
   ============================================= */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html { color-scheme: light dark; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

button, input, select, textarea {
  font-family: inherit;
}

a { color: inherit; }

code, .mono {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

/* =============================================
   PAGE WRAPPER
   ============================================= */
.page { display: flex; flex-direction: column; min-height: 100vh; }

/* =============================================
   UNFUNDED BANNER (persistent, account-wide notice)
   ============================================= */
.unfunded-banner {
  background: linear-gradient(90deg, var(--danger), var(--accent));
  color: #fff;
  text-shadow: 0 0.0625rem 0.15rem rgba(0, 0, 0, 0.55);
  padding: 0.65rem 1.25rem;
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.4;
}
.unfunded-banner strong { font-weight: 700; }

/* =============================================
   NAV
   ============================================= */
.nav {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--bg-primary);
  border-bottom: 0.0625rem solid var(--border);
}

.nav-container {
  max-width: 75rem;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.nav-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.nav-brand .brand-dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0.5rem var(--accent);
  flex-shrink: 0;
}

.nav-center {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.nav-center a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  border-radius: 0.6rem;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.nav-center a .icon { width: 1.05rem; height: 1.05rem; flex-shrink: 0; }
.nav-center a:hover { background: var(--accent-subtle); color: var(--text-primary); }
.nav-center a.active { background: var(--accent-subtle); color: var(--accent); font-weight: 600; }

.nav-right { display: flex; align-items: center; gap: 0.6rem; }

/* =============================================
   MAIN CONTENT
   ============================================= */
.content {
  flex: 1;
  width: 100%;
  max-width: 75rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

#page-actions { display: flex; align-items: center; gap: 0.6rem; }

#main-view { display: flex; flex-direction: column; gap: 1.5rem; }

/* =============================================
   SPACING UTILITIES (small, one-off overrides only --
   prefer a real component class when a pattern repeats)
   ============================================= */
.mt-sm { margin-top: 0.75rem; }
.mb-xs { margin-bottom: 0.5rem; }
.mb-sm { margin-bottom: 0.75rem; }
.mb-md { margin-bottom: 1rem; }

.card-narrow { max-width: 28rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-row { display: flex; gap: 0.5rem; }
.btn-compact { padding: 0.35rem 0.6rem; font-size: 0.75rem; }
.checkbox-list { display: flex; flex-direction: column; gap: 0.4rem; max-height: 8rem; overflow-y: auto; }
.loading-card { display: flex; justify-content: center; padding: 3rem; }

h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; font-weight: 700; }
p.subtitle { color: var(--text-secondary); font-size: 0.9rem; }

/* =============================================
   GLASS CARD / SURFACES
   ============================================= */
.glass-card {
  background: var(--bg-secondary);
  border: 0.0625rem solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.2);
}

.icon {
  width: 1em; height: 1em;
  display: inline-block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.125em;
}

/* =============================================
   MONITOR CARDS (Dashboard)
   ============================================= */
.monitor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 1rem;
}
.monitor-card { padding: 1.1rem 1.25rem; }
.monitor-title { font-size: 0.95rem; font-weight: 600; }
.monitor-meta { display: flex; align-items: center; gap: 0.4rem; margin: 0.5rem 0 0.6rem; }

/* =============================================
   STAT TILES
   ============================================= */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1px;
  background: var(--border);
  border: 0.0625rem solid var(--border);
  border-radius: 1rem;
  overflow: hidden;
}

.stat-tile { background: var(--bg-secondary); padding: 1.1rem 1.25rem; }
.stat-tile .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-secondary); font-weight: 600; }
.stat-tile .value { font-size: 1.5rem; font-weight: 700; margin-top: 0.3rem; font-variant-numeric: tabular-nums; }
.stat-tile .value small { font-size: 0.65em; color: var(--text-secondary); font-weight: 500; }
.stat-tile .value-badge { font-size: 1.1rem; }

/* =============================================
   BUTTONS
   ============================================= */
.primary-btn {
  background-color: var(--accent);
  color: #fff;
  border: none;
  padding: 0.6rem 1.15rem;
  border-radius: 0.65rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 0.2rem 0.6rem rgba(249, 115, 22, 0.3);
  white-space: nowrap;
}
.primary-btn:hover:not(:disabled) {
  background-color: var(--accent-hover);
  transform: translateY(-0.0625rem);
  box-shadow: 0 0.3rem 0.9rem rgba(249, 115, 22, 0.4);
}
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.ghost-btn {
  background: transparent;
  color: var(--text-primary);
  border: 0.0625rem solid var(--border);
  padding: 0.55rem 1rem;
  border-radius: 0.65rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: background 0.15s, border-color 0.15s;
}
.ghost-btn:hover { background: var(--accent-subtle); border-color: var(--accent); }
.ghost-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.danger-btn { color: var(--danger); border-color: var(--danger); }
.danger-btn:hover { background: var(--danger-subtle); }

.icon-btn {
  width: 2rem; height: 2rem; flex-shrink: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 0.0625rem solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 0.95rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.12); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.link-btn {
  background: none; border: none; color: var(--accent);
  font-weight: 600; font-size: 0.85rem; cursor: pointer; padding: 0;
}
.link-btn:hover { text-decoration: underline; }

/* =============================================
   BADGES (status pills)
   ============================================= */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  background: rgba(255, 255, 255, 0.07);
  padding: 0.15rem 0.5rem;
  border-radius: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before {
  content: ""; width: 0.4rem; height: 0.4rem; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}
.badge-active, .badge-ok { background: var(--success-subtle); color: var(--success); }
.badge-inactive, .badge-fail, .badge-suspended { background: var(--danger-subtle); color: var(--danger); }
.badge-paused, .badge-pending { background: var(--warn-subtle); color: var(--warn); }
.badge-neutral { background: rgba(255,255,255,0.07); color: var(--text-secondary); }
.badge-accent { background: var(--accent-subtle); color: var(--accent); }

/* =============================================
   LIST / TABLE
   ============================================= */
.list-container {
  display: flex; flex-direction: column;
  background: var(--bg-secondary);
  border-radius: 0.75rem;
  border: 0.0625rem solid var(--border);
  overflow: hidden;
}

.list-item {
  border-bottom: 0.0625rem solid var(--border);
  padding: 0.9rem 1.15rem;
  transition: background 0.15s;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--glass-bg); }

.list-item-row { display: flex; align-items: center; gap: 0.75rem; width: 100%; }
.list-item-info { flex: 1; min-width: 0; }
.list-item-info h3 {
  font-size: 0.925rem; font-weight: 600; margin-bottom: 0.2rem;
  display: flex; align-items: center; gap: 0.4rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-item-info small {
  color: var(--text-secondary); font-size: 0.76rem;
  display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap;
}
.list-item-actions { display: flex; align-items: center; gap: 0.35rem; flex-shrink: 0; }

.table-wrap { overflow-x: auto; border-radius: 0.75rem; border: 0.0625rem solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; min-width: 40rem; }
thead th {
  text-align: start; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-secondary); font-weight: 600;
  padding: 0.6rem 0.85rem; border-bottom: 0.0625rem solid var(--border);
  background: var(--bg-secondary); white-space: nowrap;
}
thead th.num, td.num { text-align: end; }
tbody td { padding: 0.6rem 0.85rem; border-bottom: 0.0625rem solid var(--border); vertical-align: top; }
tbody td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--glass-bg); }

.ledger-delta-positive { color: var(--success); }
.ledger-delta-negative { color: var(--danger); }
.log-message { font-size: 0.75rem; max-width: 20rem; overflow-wrap: anywhere; }

.empty-state {
  padding: 3rem 1.5rem; text-align: center; color: var(--text-secondary);
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
}
.empty-state .icon { width: 2.25rem; height: 2.25rem; opacity: 0.5; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 0.75rem; padding-top: 0.25rem; }
.pagination span { font-size: 0.8rem; color: var(--text-secondary); }

/* =============================================
   FORMS
   ============================================= */
.form-group { margin-bottom: 1rem; }
.form-group:last-child { margin-bottom: 0; }
.form-group label {
  display: block; font-size: 0.8rem; font-weight: 600;
  color: var(--text-secondary); margin-bottom: 0.4rem;
}
.form-input, select.form-input {
  width: 100%;
  background: var(--bg-primary);
  border: 0.0625rem solid var(--border);
  color: var(--text-primary);
  padding: 0.6rem 0.8rem;
  border-radius: 0.6rem;
  font-size: 0.875rem;
  transition: border-color 0.15s;
}
.form-input:focus { outline: none; border-color: var(--accent); }
.form-hint { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.3rem; }
.form-row { display: flex; gap: 0.75rem; }
.form-row .form-group { flex: 1; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }

.secret-field { display: flex; gap: 0.5rem; align-items: center; }
.secret-field .secret-input { flex: 1; min-width: 0; }
.secret-field .icon-btn { border-radius: 0.6rem; width: auto; height: auto; padding: 0.5rem 0.65rem; }

fieldset { border: none; padding: 0; margin: 0; }

/* =============================================
   MODAL
   ============================================= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  z-index: 2000; display: flex; justify-content: center; align-items: center;
  padding: 1rem;
  opacity: 0; visibility: hidden; transition: opacity 0.2s;
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal { width: 100%; max-width: 28rem; max-height: 85vh; overflow-y: auto; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.1rem;
}
.modal-header h2 { font-size: 1.15rem; font-weight: 700; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.3rem; }

/* =============================================
   TOAST
   ============================================= */
#toast-container {
  position: fixed; top: 1rem; inset-inline-end: 1rem; z-index: 3000;
  display: flex; flex-direction: column; gap: 0.5rem;
  max-width: 22rem;
}
.toast {
  background: var(--bg-secondary);
  border: 0.0625rem solid var(--border);
  border-inline-start: 0.2rem solid var(--accent);
  border-radius: 0.6rem;
  padding: 0.75rem 1rem;
  box-shadow: 0 0.5rem 1.5rem rgba(0,0,0,0.3);
  font-size: 0.85rem;
  animation: toastIn 0.2s ease-out;
}
.toast.error { border-inline-start-color: var(--danger); }
.toast.success { border-inline-start-color: var(--success); }
@keyframes toastIn { from { opacity: 0; transform: translateX(1rem); } to { opacity: 1; transform: translateX(0); } }

/* =============================================
   SPINNER / SKELETON
   ============================================= */
.spinner {
  width: 2rem; height: 2rem; border-radius: 50%;
  border: 0.2rem solid var(--border); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
.spinner-sm { width: 1rem; height: 1rem; border-width: 0.15rem; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton-line {
  height: 0.9rem; border-radius: 0.25rem;
  background: linear-gradient(90deg, var(--border) 25%, rgba(255,255,255,0.12) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* =============================================
   LOGIN / SIGNUP
   ============================================= */
#boot-spinner {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg-primary); z-index: 9998; transition: opacity 0.2s;
}
#boot-spinner.hidden { opacity: 0; pointer-events: none; }

#auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.auth-card { width: 100%; max-width: 25rem; text-align: center; }
.auth-card h1 {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  margin-bottom: 0.4rem; font-size: 1.4rem;
}
.auth-card .subtitle { margin-bottom: 1.75rem; }
.auth-tabs { display: flex; gap: 0.4rem; margin-bottom: 1.5rem; background: var(--bg-primary); padding: 0.25rem; border-radius: 0.65rem; }
.auth-tab {
  flex: 1; padding: 0.5rem; border: none; background: transparent; color: var(--text-secondary);
  border-radius: 0.5rem; font-weight: 600; font-size: 0.85rem; cursor: pointer; transition: 0.15s;
}
.auth-tab.active { background: var(--accent); color: #fff; }
#auth-error {
  color: var(--danger); font-size: 0.82rem; margin-bottom: 1rem; min-height: 1rem;
}
.pow-progress {
  margin-top: 1rem; font-size: 0.8rem; color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.picker-row { display: flex; gap: 1.5rem; margin-top: 1.75rem; }
.picker-col { flex: 1; text-align: start; }
.picker-label { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.5rem; display: block; }

.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.theme-btn {
  padding: 0.5rem; border-radius: 0.5rem; border: 0.0625rem solid var(--border);
  cursor: pointer; display: flex; align-items: center; justify-content: center; transition: 0.15s;
  background: var(--bg-primary); color: var(--text-primary);
}
.lang-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
.lang-btn {
  padding: 0.5rem 0.7rem; border-radius: 0.5rem; border: 0.0625rem solid var(--border);
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 0.4rem;
  background: var(--bg-primary); color: var(--text-primary); font-size: 0.85rem; font-weight: 600; transition: 0.15s;
}

/* Settings dropdown (main app nav) -- theme + language pickers,
   reused from the auth screen's inline layout instead of duplicating
   markup differently. inset-inline-end (not right) so it stays
   anchored to the trailing edge in both LTR and RTL. */
.custom-dropdown { position: relative; display: inline-flex; }
.dropdown-menu {
  position: absolute; top: calc(100% + 0.5rem); inset-inline-end: 0;
  background: var(--bg-secondary); border: 0.0625rem solid var(--border); border-radius: 0.65rem;
  padding: 0.85rem; min-width: 14rem; box-shadow: 0 0.5rem 1.5rem rgba(0,0,0,0.3);
  opacity: 0; visibility: hidden; transform: translateY(-0.5rem);
  transition: opacity 0.15s, transform 0.15s; z-index: 1500;
}
.custom-dropdown.active .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }

/* =============================================
   MISC
   ============================================= */
.hidden { display: none !important; }
.text-secondary { color: var(--text-secondary); }
.mt-1 { margin-top: 0.75rem; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }

/* =============================================
   BOTTOM NAV (mobile only -- see RESPONSIVE below)
   ============================================= */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  inset-inline: 0;
  z-index: 1000;
  background: var(--bg-primary);
  border-top: 0.0625rem solid var(--border);
  padding: 0.35rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.35rem 0.2rem;
  border-radius: 0.6rem;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.68rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.bottom-nav a .icon { width: 1.25rem; height: 1.25rem; }
.bottom-nav a:hover, .bottom-nav a.active { color: var(--accent); }
.bottom-nav a.active { background: var(--accent-subtle); }

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 52rem) {
  .nav-center { display: none; }
  .bottom-nav { display: flex; }
  .content { padding: 1.25rem 1rem calc(4.5rem + env(safe-area-inset-bottom, 0px)); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
