:root {
  --bg: #080b10;
  --surface: #11161f;
  --surface-2: #171e29;
  --border: rgba(255, 255, 255, 0.09);
  --text: #f3f5f8;
  --muted: #9aa6b8;
  --accent: #10b981;
  --accent-2: #d4a373;
  --danger: #f43f5e;
  --amber: #f59e0b;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

html[data-theme="light"] {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --border: rgba(15, 23, 42, 0.1);
  --text: #0f172a;
  --muted: #64748b;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(16, 185, 129, 0.08), transparent 40%),
    radial-gradient(circle at top right, rgba(212, 163, 115, 0.08), transparent 36%), var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", Tahoma, system-ui, sans-serif;
  line-height: 1.6;
}

.hidden {
  display: none !important;
}

.ltr {
  direction: ltr;
  unicode-bidi: isolate;
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease,
    background 0.15s ease;
}
.btn:hover {
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}
.btn-primary {
  background: linear-gradient(135deg, #10b981, #059669);
  border-color: transparent;
  color: #03150e;
}
.btn-secondary {
  background: rgba(212, 163, 115, 0.15);
  border-color: rgba(212, 163, 115, 0.4);
  color: #f3d2a8;
}
html[data-theme="light"] .btn-secondary {
  color: #854d0e;
}
.btn-ghost {
  background: transparent;
}
.btn-ghost.active {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
}
.btn-danger-ghost {
  background: rgba(244, 63, 94, 0.1);
  border-color: rgba(244, 63, 94, 0.35);
  color: #fda4af;
}
.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 8px;
}
.btn-full {
  width: 100%;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}
.field > span {
  color: var(--muted);
  font-weight: 500;
}
.field input,
.field select,
.field textarea,
.search-input,
.select-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.field input:focus,
.field select:focus,
.field textarea:focus,
.search-input:focus {
  border-color: var(--accent);
}
.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}
.checkbox-field input {
  width: 18px;
  height: 18px;
}

.domain-input-group {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
}
.domain-input-group input {
  border: 0;
  border-radius: 0;
}
.domain-input-group span {
  padding: 0 12px;
  color: var(--muted);
  font-size: 13px;
  border-left: 1px solid var(--border);
}

/* Login */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 440px;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: linear-gradient(135deg, #10b981, #d4a373);
  color: #08100d;
}
.eyebrow {
  margin: 14px 0 4px;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--accent-2);
  direction: ltr;
  text-align: right;
}
.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}
.login-sub {
  margin: 0 0 22px;
  font-size: 13px;
  color: var(--muted);
}
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.alert-error {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(244, 63, 94, 0.14);
  border: 1px solid rgba(244, 63, 94, 0.4);
  color: #fda4af;
  font-size: 13px;
}
.muted-note {
  font-size: 12px;
  color: var(--muted);
}

/* Dashboard Layout */
.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 24px 60px;
}
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  margin-bottom: 20px;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-title {
  font-weight: 800;
  font-size: 16px;
}
.topbar-sub {
  font-size: 12px;
  color: var(--muted);
}
.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
}
.pill-info {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.35);
  color: #7dd3fc;
}
.pill-success {
  background: rgba(16, 185, 129, 0.14);
  border-color: rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}
.pill-warn {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fcd34d;
}
.pill-danger {
  background: rgba(244, 63, 94, 0.15);
  border-color: rgba(244, 63, 94, 0.4);
  color: #fda4af;
}
.pill-muted {
  background: var(--surface-2);
  color: var(--muted);
}
html[data-theme="light"] .pill-success {
  color: #047857;
}
html[data-theme="light"] .pill-warn {
  color: #b45309;
}
html[data-theme="light"] .pill-danger {
  color: #be123c;
}
html[data-theme="light"] .pill-info {
  color: #0369a1;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-label {
  font-size: 12px;
  color: var(--muted);
}
.kpi-val {
  font-size: 28px;
  font-weight: 800;
}
.kpi-hint {
  font-size: 11px;
  color: var(--muted);
}
.text-emerald {
  color: var(--accent);
}
.text-amber {
  color: var(--amber);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.toolbar-filters {
  display: flex;
  flex: 1;
  min-width: 260px;
  gap: 10px;
}
.search-input {
  max-width: 380px;
}
.select-input {
  width: auto;
  min-width: 170px;
}
.toolbar-actions {
  display: flex;
  gap: 10px;
}

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
}
.table-wrap {
  overflow-x: auto;
}
.sites-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.sites-table th,
.sites-table td {
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: middle;
}
.sites-table th {
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-2);
  font-weight: 700;
  white-space: nowrap;
}
.sites-table tr:last-child td {
  border-bottom: 0;
}
.site-name-main {
  font-weight: 700;
  display: block;
}
.site-name-sub {
  font-size: 11px;
  color: var(--muted);
}
.domain-link {
  color: #7dd3fc;
  text-decoration: none;
  font-family: monospace;
  font-size: 12px;
}
html[data-theme="light"] .domain-link {
  color: #0369a1;
}
.domain-link:hover {
  text-decoration: underline;
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  inset: 0;
  background: rgba(148, 163, 184, 0.3);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.switch input:checked + .slider {
  background: var(--accent);
}
.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Drawer */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  justify-content: flex-end;
}
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.drawer-panel {
  position: relative;
  z-index: 2;
  width: 680px;
  max-width: 100vw;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.drawer-header h2 {
  margin: 0;
  font-size: 18px;
}
.drawer-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}
.drawer-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 22px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn.active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.drawer-body {
  padding: 20px 22px 40px;
  overflow-y: auto;
  flex: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.span-2 {
  grid-column: span 2;
}
.expiry-actions,
.meta-dates {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 12px;
}
.meta-dates {
  justify-content: space-between;
}
.panel-box {
  margin-top: 18px;
  padding: 16px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.panel-box h3 {
  margin: 0 0 8px;
  font-size: 15px;
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.code-box {
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 10px;
  background: #06090d;
  color: #cbd5e1;
  font-size: 12px;
  overflow-x: auto;
  max-height: 360px;
}

.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}
.timeline-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.timeline-title {
  font-weight: 700;
  font-size: 13px;
}
.timeline-meta {
  font-size: 11px;
  color: var(--muted);
}

.qr-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  align-items: center;
  padding: 16px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.qr-preview-box {
  background: #ffffff;
  padding: 12px;
  border-radius: 14px;
  display: grid;
  place-items: center;
}
.qr-preview-box svg {
  width: 180px;
  height: 180px;
  display: block;
}
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 10px 0 16px;
}
.stats-row > div {
  padding: 10px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
}
.stats-row span {
  display: block;
  font-size: 11px;
  color: var(--muted);
}
.stats-row strong {
  font-size: 20px;
}
.stats-bars {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  align-items: end;
  height: 110px;
  padding-top: 12px;
}
.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
  justify-content: flex-end;
}
.bar-fill {
  width: 100%;
  min-height: 4px;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, #10b981, #047857);
}
.bar-label {
  font-size: 10px;
  color: var(--muted);
  direction: ltr;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  z-index: 2;
  width: 520px;
  max-width: 100%;
  max-height: 92vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.modal-lg {
  width: 780px;
}
.modal-xl {
  width: min(1260px, 96vw);
  height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.modal-header h3 {
  margin: 0;
}
.preview-stage {
  flex: 1;
  min-height: 480px;
  display: flex;
  justify-content: center;
  background: #05070a;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  padding: 10px;
}
.preview-frame {
  border: 0;
  height: 100%;
  background: #0b0d10;
  border-radius: 10px;
  transition: width 0.25s ease;
}
.preview-frame.desktop {
  width: 100%;
}
.preview-frame.mobile {
  width: 390px;
  border: 2px solid rgba(255, 255, 255, 0.16);
}

/* Toast */
.toast-root {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow);
}
.toast.error {
  border-color: var(--danger);
}

@media (max-width: 960px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .qr-layout {
    grid-template-columns: 1fr;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .span-2 {
    grid-column: span 1;
  }
}
