/* Self-hosted Vazirmatn (variable font - one file covers the whole 100-900
   weight range used across the panel, no external Google Fonts request). */
@font-face {
  font-family: 'Vazirmatn';
  src: url('../vendor/fonts/Vazirmatn-VariableFont_wght.ttf') format('truetype-variations'),
       url('../vendor/fonts/Vazirmatn-VariableFont_wght.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* =========================================================
   Design tokens
   ========================================================= */
:root,
html[data-theme="light"] {
  color-scheme: light;
  --bg: #e9f2fc;
  --surface: #f7fbff;
  --surface-2: #e2eefa;
  --surface-hover: #d8e9f8;
  --text: #14172b;
  --text-muted: #5f7186;
  --border: #cde0f2;

  --primary: #4338ca;
  --primary-hover: #372ea8;
  --primary-soft: #eeedfd;
  --header-soft: #ded9f8;  /* card/widget title-bar tint - noticeably deeper than --primary-soft so it reads against the pale surfaces */
  --accent: #0d9488;      /* signature teal - "network live" color */
  --accent-soft: #e3f5f2;
  --title-accent: #6366f1;

  --success: #059669;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0284c7;

  --sidebar-bg: linear-gradient(180deg, #163061 0%, #0c1c3a 100%);
  --sidebar-text: #a9c0dd;
  --sidebar-active-bg: rgba(96, 165, 250, .18);
  --sidebar-accent: #60a5fa;

  --shadow-sm: 0 1px 2px rgba(20, 23, 43, .06);
  --shadow-md: 0 6px 20px -4px rgba(20, 23, 43, .10), 0 2px 6px -2px rgba(20, 23, 43, .06);
  --radius: 16px;
  --radius-sm: 10px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090b14;
  --surface: #121425;
  --surface-2: #171a2e;
  --surface-hover: #1c2038;
  --text: #e9eaf4;
  --text-muted: #8c90ab;
  --border: #232645;

  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-soft: rgba(99, 102, 241, .14);
  --header-soft: rgba(99, 102, 241, .20);
  --accent: #2dd4bf;
  --accent-soft: rgba(45, 212, 191, .12);
  --title-accent: #818cf8;

  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --info: #38bdf8;

  --sidebar-bg: linear-gradient(180deg, #0b0c18 0%, #060710 100%);
  --sidebar-text: #8c90ab;
  --sidebar-active-bg: rgba(99, 102, 241, .18);
  --sidebar-accent: #a5b4fc;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 10px 26px -6px rgba(0, 0, 0, .5), 0 2px 8px -2px rgba(0, 0, 0, .35);
  --radius: 16px;
  --radius-sm: 10px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .2s ease, color .2s ease;
  font-feature-settings: 'tnum' 1;
}

a { text-decoration: none; }
h1, h2, h3, h4, h5, h6 { font-weight: 700; letter-spacing: -.01em; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* =========================================================
   Login page
   ========================================================= */
.login-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 20%, rgba(67, 56, 202, .16), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(13, 148, 136, .14), transparent 45%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
}
.login-brand-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  margin: 0 auto 1rem;
  box-shadow: var(--shadow-md);
}
.login-card label { color: var(--text-muted); font-size: .85rem; }
.login-card .form-control {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
  border-radius: var(--radius-sm);
  padding: .65rem .9rem;
}

.theme-toggle-floating {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 50;
}

/* =========================================================
   App shell (sidebar + content)
   ========================================================= */
.app-shell { min-height: 100vh; }

.sidebar {
  width: 100px;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 1.1rem 0;
  position: sticky;
  top: 0;
  flex-shrink: 0;
  transition: transform .25s ease;
  border-left: 1px solid rgba(255,255,255,.05);
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 8px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.3); }
.sidebar { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent; }
.sidebar-brand {
  font-size: .72rem;
  font-weight: 800;
  padding: .25rem .4rem 1rem;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: .35rem;
  letter-spacing: -.01em;
}
.sidebar-brand .brand-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.sidebar-brand .brand-icon-logo {
  width: 72px; height: 72px;
  border-radius: 14px;
  background: transparent;
  overflow: hidden;
}
.sidebar-brand .brand-icon-logo img {
  width: 100%; height: 100%;
  object-fit: contain;
}

/* Compact square-ish icon tiles, stacked in a single column to keep the
   sidebar narrow and leave more room for the page content. */
.sidebar-nav-grid {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  padding: 0 .5rem;
}
.sidebar-nav-grid a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  min-height: 64px;
  border-radius: var(--radius-sm);
  padding: .5rem .2rem;
  color: var(--sidebar-text);
  font-size: .64rem;
  font-weight: 500;
  line-height: 1.15;
  text-align: center;
  transition: background .15s ease, color .15s ease;
}
.sidebar-nav-grid a i { font-size: 1.3rem; }
.sidebar-nav-grid a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.sidebar-nav-grid a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav-grid a.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-accent);
}

.content { background: var(--bg); min-height: 100vh; flex: 1; min-width: 0; }

.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar .brand { font-weight: 700; color: var(--text); }
.burger-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 15, .6);
  backdrop-filter: blur(2px);
  z-index: 39;
}

.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .35rem .8rem;
  cursor: pointer;
  color: var(--text);
  font-size: .82rem;
  font-weight: 500;
  user-select: none;
  transition: background .15s ease;
}
.theme-switch:hover { background: var(--surface-hover); }

/* =========================================================
   Cards / surfaces
   ========================================================= */
.card {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* Full-width title bar for every card/widget section - a subtly different
   background than the card body, spanning edge-to-edge at the top (not just
   a thin accent line). Bleeds out of the card's own p-3 (1rem) padding. */
.card > h6:first-child {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .4rem;
  margin: -1rem -1rem 1rem -1rem;
  padding: .65rem 1rem;
  background: var(--header-soft);
  border-radius: var(--radius) var(--radius) 0 0;
}

.widget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: -1rem -1rem .75rem -1rem;
  padding: .6rem 1rem;
  background: var(--header-soft);
  border-radius: var(--radius) var(--radius) 0 0;
}
@media (min-width: 1200px) {
  .widget-header { margin: -.5rem -.5rem .75rem -.5rem; }
}

/* Page title bar (the h4 + theme-toggle/username row at the top of every page,
   including the dashboard) - bleeds to the edges of <main>'s own padding. */
.page-title-bar {
  margin: -1rem -1rem 1.5rem -1rem;
  padding: .85rem 1rem;
  background: var(--header-soft);
  border-radius: 0 0 var(--radius) var(--radius);
}
@media (min-width: 768px) {
  .page-title-bar {
    margin: -1.5rem -1.5rem 1.5rem -1.5rem;
    padding: 1rem 1.5rem;
  }
}

.widget-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: none;
  height: 100%;
}
.widget-drag-handle { cursor: move; color: var(--text-muted); }
.widget-remove-btn { color: var(--text-muted); cursor: pointer; transition: color .15s ease; }
.widget-remove-btn:hover { color: var(--danger); }

/* Stat chip - small colored icon square used in summary widgets */
.stat-chip {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: .95rem;
  margin: 0 auto .4rem;
}

/* =========================================================
   KPI tiles - dashboard "status summary" widget
   ========================================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem;
}
.kpi-tile {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .65rem .7rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid transparent;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease, background .15s ease;
}
.kpi-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: var(--kpi-color, var(--primary));
  background: var(--surface);
}
.kpi-icon {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.05rem;
  background: var(--kpi-soft, var(--primary-soft));
  color: var(--kpi-color, var(--primary));
}
.kpi-body { min-width: 0; }
.kpi-label {
  font-size: .74rem;
  color: var(--text-muted);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: .3rem;
}
.kpi-value {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--kpi-color, var(--text));
}

.kpi-meter-wrap { margin-top: .85rem; }

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: .88rem;
  transition: transform .06s ease, box-shadow .15s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn-sm { border-radius: 9px; }

.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-primary:not(:disabled):not(.disabled):active { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-outline-secondary { color: var(--text-muted); border-color: var(--border); }
.btn-outline-secondary:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }

.form-control:focus, .form-select:focus, .btn:focus {
  box-shadow: 0 0 0 .18rem var(--primary-soft);
}

/* =========================================================
   Forms
   ========================================================= */
.form-control, .form-select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.form-control:focus, .form-select:focus {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--primary);
}
label, .form-label { color: var(--text-muted); font-size: .85rem; font-weight: 500; }

.text-muted, .form-text, small.text-muted { color: var(--text-muted) !important; }
::placeholder { color: var(--text-muted); opacity: .7; }

select.form-select option { background: var(--surface); color: var(--text); }

.dropdown-menu {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}
.dropdown-item { color: var(--text); border-radius: 8px; margin: 0 4px; width: calc(100% - 8px); }
.dropdown-item:hover, .dropdown-item:focus { background: var(--surface-2); color: var(--text); }

/* =========================================================
   Tables
   ========================================================= */
.table { color: var(--text); border-collapse: separate; border-spacing: 0; }
.table thead th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom-color: var(--border);
  background: transparent;
}
.table td, .table th { border-color: var(--border); vertical-align: middle; }
.table tbody tr:hover > * { background-color: var(--surface-hover); }

html[data-theme="dark"] .table,
html[data-theme="dark"] .table > :not(caption) > * > * {
  background-color: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
html[data-theme="dark"] .table tbody tr:hover > * { background-color: var(--surface-hover) !important; }
html[data-theme="light"] .table,
html[data-theme="light"] .table > :not(caption) > * > * {
  background-color: var(--surface) !important;
  color: var(--text) !important;
}
html[data-theme="light"] .table tbody tr:hover > * { background-color: var(--surface-hover) !important; }

code { color: var(--primary); background: var(--primary-soft); padding: .15rem .45rem; border-radius: 6px; font-size: .85em; }

/* =========================================================
   Badges / status
   ========================================================= */
.badge { border-radius: 999px; font-weight: 500; padding: .38em .7em; font-size: .74rem; }
.badge-active { background: var(--accent-soft); color: var(--accent); }
.badge-disabled { background: var(--surface-2); color: var(--text-muted); }
.badge-expired { background: rgba(220, 38, 38, .12); color: var(--danger); }
.badge-pending { background: rgba(217, 119, 6, .14); color: var(--warning); }
.badge-confirmed { background: var(--accent-soft); color: var(--accent); }
.badge-rejected { background: rgba(220, 38, 38, .12); color: var(--danger); }

/* Live status dot with signature soft pulse for "online" - reflects real-time network state */
.status-dot {
  position: relative;
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-left: 6px;
}
.status-dot.online { background: var(--accent); }
.status-dot.online::after {
  content: '';
  position: absolute; inset: -4px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  animation: pulse-ring 1.8s cubic-bezier(.2,.6,.4,1) infinite;
}
.status-dot.offline { background: var(--danger); }
.status-dot.unknown { background: var(--text-muted); opacity: .5; }

@keyframes pulse-ring {
  0%   { transform: scale(.6); opacity: .9; }
  100% { transform: scale(1.8); opacity: 0; }
}

.alert { border: 1px solid transparent; border-radius: var(--radius-sm); }

/* =========================================================
   Resource / progress bars
   ========================================================= */
.resource-bar {
  height: 7px;
  border-radius: 5px;
  background: var(--surface-2);
  overflow: hidden;
}
.resource-bar > span { display: block; height: 100%; border-radius: 5px; transition: width .4s ease; }

/* Circular progress ring (system resources widget: CPU/RAM/disk) */
.circular-progress {
  --size: 56px;
  --thickness: 6px;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  transition: background .4s ease;
}
.circular-progress-inner {
  position: absolute;
  inset: var(--thickness);
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .72rem;
  color: var(--text);
}

/* =========================================================
   Modal
   ========================================================= */
.modal-content {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.modal-header, .modal-footer { border-color: var(--border); }
.btn-close { filter: var(--bs-btn-close-white-filter, none); }
html[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

/* =========================================================
   Mobile responsive
   ========================================================= */
@media (max-width: 991.98px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
    transform: translateX(100%);
    z-index: 40;
    box-shadow: -8px 0 24px rgba(0,0,0,.25);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; }
  .content { width: 100%; }
}

@media (max-width: 575.98px) {
  .card { border-radius: 14px; }
  .fs-3 { font-size: 1.4rem !important; }
}

/* ---------------- Floating flash-message toasts (replace the old full-width inline alerts) ---------------- */
.flash-toast-container {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 460px;
  padding: 0 12px;
  pointer-events: none;
}
.flash-toast {
  pointer-events: auto;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-inline-start: 4px solid var(--info);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0,0,0,.22);
  padding: 12px 16px;
  font-size: .9rem;
  color: var(--text);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: flashToastIn .3s ease both, flashToastOut .35s ease 4.15s both;
}
.flash-toast i { font-size: 1.05rem; margin-top: .1rem; }
.flash-toast-success { border-inline-start-color: var(--accent); }
.flash-toast-success i { color: var(--accent); }
.flash-toast-danger { border-inline-start-color: var(--danger); }
.flash-toast-danger i { color: var(--danger); }
.flash-toast-warning { border-inline-start-color: var(--warning); }
.flash-toast-warning i { color: var(--warning); }
.flash-toast-info { border-inline-start-color: var(--info); }
.flash-toast-info i { color: var(--info); }

@keyframes flashToastIn {
  from { opacity: 0; transform: translateY(-14px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes flashToastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(-10px) scale(.98); }
}
