/* ========================================================================
   Waslni - Shared design system
   Dark theme, emerald accent, Arabic/RTL first
   ======================================================================== */

/* ---------- Design tokens ---------- */
:root {
  /* Surfaces */
  --bg-base:        #0A0A0B;
  --bg-secondary:   #121214;
  --bg-elevated:    #17171A;
  --bg-card:        #1C1C1F;
  --bg-hover:       #222226;

  /* Borders */
  --border-subtle:  #242428;
  --border:         #2D2D32;
  --border-strong:  #3A3A40;

  /* Text */
  --text-primary:   #F4F4F5;
  --text-secondary: #A1A1A6;
  --text-tertiary:  #6E6E73;
  --text-muted:     #4A4A50;

  /* Accent - emerald */
  --accent:         #10B981;
  --accent-bright:  #34D399;
  --accent-dim:     #047857;
  --accent-glow:    rgba(16, 185, 129, 0.12);
  --accent-border:  rgba(16, 185, 129, 0.3);

  /* Semantic */
  --danger:         #EF4444;
  --danger-glow:    rgba(239, 68, 68, 0.12);
  --warning:        #F59E0B;
  --warning-glow:   rgba(245, 158, 11, 0.12);
  --info:           #60A5FA;

  /* Typography */
  --font-sans:      "IBM Plex Sans Arabic", "Tajawal", system-ui, sans-serif;
  --font-mono:      "IBM Plex Mono", "SF Mono", Menlo, monospace;

  /* Radii */
  --radius-sm:      6px;
  --radius:         10px;
  --radius-lg:      14px;
  --radius-xl:      20px;

  /* Transitions */
  --transition:     150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Reset ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

html[dir="rtl"] {
  text-align: right;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  font-weight: 400;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "ss02";
}

/* Subtle gradient backdrop */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at top left, rgba(16, 185, 129, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(16, 185, 129, 0.02) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

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

a { color: inherit; text-decoration: none; }

ul, ol { list-style: none; }

/* ---------- Layout ---------- */
.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(10, 10, 11, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dim) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0A0A0B;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.02em;
}

.brand-title {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  font-size: 13px;
}

.user-chip .avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent-bright);
}

.main {
  flex: 1;
  padding: 32px 24px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 640px) {
  .main { padding: 20px 16px; }
  .topbar { padding: 12px 16px; }
}

/* ---------- Page headers ---------- */
.page-header {
  margin-bottom: 28px;
}

.page-title {
  font-size: 24px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: border-color var(--transition);
}

.card:hover { border-color: var(--border); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.card-meta {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* Stat card */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.stat-value {
  font-size: 26px;
  font-weight: 500;
  font-family: var(--font-sans);
  letter-spacing: -0.02em;
  line-height: 1;
}

.stat-value .unit {
  font-size: 14px;
  color: var(--text-tertiary);
  margin-right: 4px;
  font-weight: 400;
}

.stat-delta {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 8px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

/* Hero card - the big status card */
.hero-card {
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-elevated) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px;
  position: relative;
  overflow: hidden;
}

.hero-card::before {
  content: "";
  position: absolute;
  top: -60px;
  inset-inline-end: -60px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  pointer-events: none;
}

.hero-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}

.hero-value {
  font-size: 32px;
  font-weight: 500;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.hero-meta {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
  border: 1px solid transparent;
  line-height: 1;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #0A0A0B;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-bright); }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }

.btn-secondary {
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--text-primary);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-card);
  color: var(--text-primary);
}

.btn-danger {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-glow);
}

.btn-large {
  padding: 16px 24px;
  font-size: 15px;
  border-radius: var(--radius-lg);
}

.btn-block { width: 100%; }

.btn-icon {
  padding: 8px;
  border-radius: var(--radius);
}

/* ---------- Forms ---------- */
.field {
  margin-bottom: 18px;
}

.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 500;
}

.input,
.select,
.textarea {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 11px 14px;
  color: var(--text-primary);
  font-size: 14px;
  transition: all var(--transition);
  font-family: var(--font-sans);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--border);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

.field-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 6px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 520px) {
  .field-grid { grid-template-columns: 1fr; }
}

/* ---------- Badges & pills ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  border: 1px solid transparent;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-success {
  background: var(--accent-glow);
  color: var(--accent-bright);
  border-color: var(--accent-border);
}

.badge-warning {
  background: var(--warning-glow);
  color: var(--warning);
  border-color: rgba(245, 158, 11, 0.3);
}

.badge-danger {
  background: var(--danger-glow);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}

.badge-neutral {
  background: var(--bg-card);
  color: var(--text-secondary);
  border-color: var(--border);
}

.badge-active {
  background: var(--accent-glow);
  color: var(--accent-bright);
  border-color: var(--accent-border);
}
.badge-active .badge-dot {
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.3); }
}

/* ---------- Lists ---------- */
.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  transition: all var(--transition);
}

.list-item:hover {
  border-color: var(--border);
  background: var(--bg-hover);
}

.list-item-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.list-item-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.list-item-subtitle {
  font-size: 12px;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.list-item-meta {
  color: var(--text-tertiary);
}

.list-dot {
  color: var(--text-muted);
}

.list-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: start;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}

.table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-hover); }

.table .mono { font-family: var(--font-mono); font-size: 12px; color: var(--text-secondary); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-slow);
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(12px);
  transition: transform var(--transition-slow);
}

.modal-backdrop.open .modal { transform: translateY(0); }

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 16px;
  font-weight: 500;
}

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  transition: all var(--transition);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body { padding: 24px; }

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-tertiary);
}

.empty-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
}

.empty-title {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 4px;
}

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

/* ---------- Section ---------- */
.section {
  margin-bottom: 32px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow-x: auto;
}

.tab {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
  white-space: nowrap;
}

.tab:hover { color: var(--text-primary); }

.tab.active {
  background: var(--bg-hover);
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: 20px;
  inset-inline-start: 50%;
  transform: translateX(50%) translateY(-20px);
  padding: 12px 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition-slow);
}

html[dir="rtl"] .toast { transform: translateX(-50%) translateY(-20px); }
html[dir="rtl"] .toast.show { transform: translateX(-50%) translateY(0); }

.toast.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(50%) translateY(0);
}

.toast.success { border-color: var(--accent-border); color: var(--accent-bright); }
.toast.error { border-color: rgba(239, 68, 68, 0.3); color: var(--danger); }

/* ---------- Utilities ---------- */
.mono { font-family: var(--font-mono); }
.muted { color: var(--text-tertiary); }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }

.split {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
}

/* ---------- Login page specific ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  z-index: 1;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 32px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.login-brand .brand-mark {
  width: 40px;
  height: 40px;
  font-size: 16px;
}

.login-brand .brand-title { font-size: 20px; }
