:root {
  --bg: #f3f6f4;
  --bg-elevated: #ffffff;
  --bg-muted: #e8eee9;
  --text: #14201a;
  --text-muted: #5a6b62;
  --border: #cfd9d3;
  --accent: #0f6b4c;
  --accent-hover: #0b553c;
  --danger: #b42318;
  --warning: #b54708;
  --success: #067647;
  --sidebar: #10241c;
  --sidebar-text: #d7e6de;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(16, 36, 28, 0.08);
  --font: "Vazirmatn", "Tahoma", sans-serif;
  --mono: "IBM Plex Mono", "Courier New", monospace;
}

[data-theme="dark"] {
  --bg: #0d1612;
  --bg-elevated: #15231c;
  --bg-muted: #1c2d24;
  --text: #e7f0eb;
  --text-muted: #9bb0a5;
  --border: #2a3d33;
  --accent: #3dba8a;
  --accent-hover: #56d0a0;
  --sidebar: #09140f;
  --sidebar-text: #d7e6de;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

@font-face {
  font-family: "Vazirmatn";
  src: url("/static/assets/fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/assets/fonts/Vazirmatn-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/assets/fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }
html { direction: rtl; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(circle at 10% 0%, rgba(15, 107, 76, 0.12), transparent 40%),
    radial-gradient(circle at 90% 10%, rgba(20, 32, 26, 0.06), transparent 35%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid rgba(15, 107, 76, 0.55);
  outline-offset: 2px;
}
[data-theme="dark"] :focus-visible {
  outline-color: rgba(61, 186, 138, 0.75);
}
.page-title:focus {
  outline: none;
}
.page-title:focus-visible {
  outline: 2px solid rgba(15, 107, 76, 0.45);
  outline-offset: 4px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  inset-inline-start: 1rem;
  top: -100px;
  z-index: 3000;
  background: var(--accent);
  color: #fff;
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
}
.skip-link:focus {
  top: 1rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.brand {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding: 0.5rem 0.75rem;
}

.nav-link {
  display: block;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  color: var(--sidebar-text);
  opacity: 0.85;
}
.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,0.08);
  opacity: 1;
}
.nav-link.active {
  font-weight: 700;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-inline-end: 0.15rem;
}
.nav-group {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}
.nav-group-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(215, 230, 222, 0.55);
  padding: 0.2rem 0.85rem 0.35rem;
  letter-spacing: 0.02em;
}

.sidebar-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-btn {
  appearance: none;
  width: 100%;
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  border: 1px solid rgba(215, 230, 222, 0.28);
  background: rgba(255, 255, 255, 0.06);
  color: var(--sidebar-text);
  cursor: pointer;
  text-align: center;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.sidebar-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(215, 230, 222, 0.45);
  color: #fff;
}
.sidebar-btn:focus-visible {
  outline: 2px solid rgba(61, 186, 138, 0.7);
  outline-offset: 2px;
}
.sidebar-btn-danger {
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
}
.sidebar-btn-danger:hover {
  background: rgba(180, 35, 24, 0.28);
  border-color: rgba(248, 113, 113, 0.55);
  color: #fff;
}

.main {
  padding: 1.25rem 1.5rem 2rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.page-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
}

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0.25rem 0;
}
.stat-label { color: var(--text-muted); font-size: 0.9rem; }

.quota-meter {
  margin-top: 1rem;
}
.quota-meter-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
}
.quota-meter-label { font-weight: 600; }
.quota-meter-pct {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
  direction: ltr;
}
.quota-track {
  height: 10px;
  border-radius: 999px;
  background: var(--bg-muted);
  overflow: hidden;
  border: 1px solid var(--border);
}
.quota-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--success);
  transition: width 0.35s ease, background 0.2s ease;
}
.quota-meter[data-tone="warn"] .quota-fill { background: var(--warning); }
.quota-meter[data-tone="critical"] .quota-fill { background: var(--danger); }
.quota-meter[data-tone="ok"] .quota-fill { background: var(--accent); }
.quota-meter-meta {
  margin-top: 0.45rem;
  font-size: 0.9rem;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled,
.btn.is-loading {
  opacity: 0.72;
  cursor: not-allowed;
  transform: none;
}
.btn.is-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}
.btn-spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.btn-secondary .btn-spinner {
  border-color: rgba(20, 32, 26, 0.2);
  border-top-color: var(--text);
}
[data-theme="dark"] .btn-secondary .btn-spinner {
  border-color: rgba(231, 240, 235, 0.25);
  border-top-color: var(--text);
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-danger { background: var(--danger); }

.form-group { margin-bottom: 0.9rem; }
.form-group label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
  font-size: 0.92rem;
}
.input, .select, .textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
}
.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid rgba(15, 107, 76, 0.35);
  border-color: var(--accent);
}

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: right;
  padding: 0.7rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
th { color: var(--text-muted); font-weight: 600; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  background: var(--bg-muted);
}
.badge-success { background: rgba(6, 118, 71, 0.15); color: var(--success); }
.badge-danger { background: rgba(180, 35, 24, 0.15); color: var(--danger); }
.badge-warning { background: rgba(181, 71, 8, 0.15); color: var(--warning); }

.toast-container {
  position: fixed;
  inset-inline-start: 1rem;
  bottom: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(360px, calc(100vw - 2rem));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-inline-start: 4px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
  min-width: 240px;
  animation: slideIn 0.25s ease;
}
.toast.is-leaving {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast-icon {
  width: 0.7rem;
  height: 0.7rem;
  margin-top: 0.35rem;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.toast-body { min-width: 0; }
.toast-message { display: block; line-height: 1.5; }
.toast-success {
  border-inline-start-color: var(--success);
}
.toast-success .toast-icon { background: var(--success); }
.toast-error {
  border-inline-start-color: var(--danger);
}
.toast-error .toast-icon { background: var(--danger); }
.toast-info {
  border-inline-start-color: var(--accent);
}
.toast-info .toast-icon { background: var(--accent); }
@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.auth-card {
  width: min(420px, 100%);
}
.auth-brand {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 0.35rem;
}
.auth-subtitle {
  margin: 0 0 1rem;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  padding: 0.3rem;
  margin-bottom: 1rem;
  background: var(--bg-muted);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.auth-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.is-active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(16, 36, 28, 0.08);
}
.auth-tab:focus-visible {
  outline: 2px solid rgba(15, 107, 76, 0.35);
  outline-offset: 1px;
}
.auth-panel[hidden] { display: none !important; }
.btn-block { width: 100%; }
.captcha-frame {
  background: var(--bg-muted);
  border-radius: 8px;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
}
.muted { color: var(--text-muted); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skeleton-panel { pointer-events: none; }
.skeleton {
  display: block;
  background: linear-gradient(
    90deg,
    var(--bg-muted) 0%,
    rgba(255, 255, 255, 0.45) 45%,
    var(--bg-muted) 90%
  );
  background-size: 200% 100%;
  animation: skeletonShine 1.2s ease-in-out infinite;
  border-radius: 6px;
}
[data-theme="dark"] .skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-muted) 0%,
    rgba(255, 255, 255, 0.08) 45%,
    var(--bg-muted) 90%
  );
  background-size: 200% 100%;
}
.skeleton-line { height: 0.85rem; width: 100%; }
.skeleton-lg { height: 1.55rem; margin-top: 0.55rem; }
.skeleton-row { height: 1rem; margin-bottom: 0.75rem; }
.skeleton-card { min-height: 4.5rem; }
.w-30 { width: 30%; }
.w-40 { width: 40%; }
.w-65 { width: 65%; }
@keyframes skeletonShine {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}
.empty-state {
  text-align: center;
  padding: 2.25rem 1.25rem;
}
.empty-state-mark {
  width: 2.75rem;
  height: 2.75rem;
  margin: 0 auto 0.85rem;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,0.35), transparent 45%),
    var(--bg-muted);
  border: 1px solid var(--border);
  position: relative;
}
.empty-state-mark::after {
  content: "";
  position: absolute;
  inset: 35% 28%;
  border: 2px solid var(--text-muted);
  border-radius: 4px;
  opacity: 0.55;
}
.empty-state-positive .empty-state-mark {
  background:
    radial-gradient(circle at 35% 30%, rgba(6, 118, 71, 0.18), transparent 50%),
    var(--bg-muted);
}
.empty-state-title {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
  font-weight: 700;
}
.empty-state-desc {
  margin: 0 auto;
  max-width: 28rem;
  line-height: 1.7;
}
.empty-state-action {
  margin-top: 1rem;
}
.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-bottom: 0.85rem;
}
.table-search {
  flex: 1 1 220px;
  min-width: 0;
}
.table-filter-select {
  flex: 0 1 180px;
  width: auto;
  min-width: 140px;
}
.table-pager {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.table-pager-actions {
  display: flex;
  gap: 0.4rem;
}

.row-actions {
  position: relative;
  display: inline-flex;
  justify-content: flex-start;
}
.row-actions-toggle {
  appearance: none;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  padding: 0;
}
.row-actions-toggle:hover,
.row-actions.is-open .row-actions-toggle {
  background: var(--bg-muted);
  border-color: var(--accent);
}
.row-actions-menu {
  position: absolute;
  top: calc(100% + 0.25rem);
  inset-inline-end: 0;
  z-index: 20;
  min-width: 10.5rem;
  padding: 0.3rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.row-actions-menu[hidden] { display: none !important; }
.row-actions-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: right;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  width: 100%;
}
.row-actions-item:hover {
  background: var(--bg-muted);
}
.row-actions-item.is-danger {
  color: var(--danger);
}
.row-actions-item.is-danger:hover {
  background: rgba(180, 35, 24, 0.1);
}
.code-block {
  background: var(--bg-muted);
  border-radius: 8px;
  padding: 0.85rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
}
.code-block-wrap {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin: 0.65rem 0;
}
.code-block-wrap .code-block {
  flex: 1;
  min-width: 0;
}
.btn-copy {
  flex-shrink: 0;
  white-space: nowrap;
}
.secret-key-card {
  margin-top: 1rem;
  border-color: var(--warning);
  background:
    linear-gradient(180deg, rgba(181, 71, 8, 0.08), transparent 48%),
    var(--bg-elevated);
}
.docs-card h3 { margin-top: 0; }
.docs-label {
  margin: 1rem 0 0.35rem;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.92rem;
}
.docs-card .docs-label:first-of-type { margin-top: 0.75rem; }
.mobile-toggle { display: none; }
.sidebar-backdrop {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(9, 20, 15, 0.55);
  animation: modalFade 0.18s ease;
}
.modal {
  width: min(440px, 100%);
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: modalPop 0.2s ease;
}
.modal-header {
  padding: 1rem 1.1rem 0.25rem;
}
.modal-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}
.modal-body {
  padding: 0.5rem 1.1rem 0.25rem;
}
.modal-message {
  margin: 0 0 0.75rem;
  line-height: 1.7;
}
.modal-field { margin-bottom: 0.25rem; }
.modal-footer {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.85rem 1.1rem 1.1rem;
}
@keyframes modalFade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modalPop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: min(80vw, 280px);
    transform: translateX(110%);
    transition: transform 0.2s ease;
    z-index: 60;
    box-shadow: -12px 0 28px rgba(0, 0, 0, 0.28);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 55;
    margin: 0;
    padding: 0;
    border: 0;
    background: rgba(9, 20, 15, 0.45);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    display: block;
  }
  .sidebar-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }
  body.sidebar-open { overflow: hidden; }
  .mobile-toggle { display: inline-flex; }
  .main { padding: 1rem; }
}
