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

:root {
  --font: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-ar: 'IBM Plex Sans Arabic', 'IBM Plex Sans', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;

  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-hover: #f1f5f9;

  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --text: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-text: #1e40af;

  --success: #16a34a;
  --success-light: #f0fdf4;
  --success-text: #166534;

  --warning: #d97706;
  --warning-light: #fffbeb;
  --warning-text: #92400e;

  --danger: #dc2626;
  --danger-light: #fef2f2;
  --danger-text: #991b1b;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);

  --sidebar-w: 240px;
  --header-h: 56px;
  --bottom-nav-h: 64px;
  --max-w: 1152px; /* 6xl */
}

html { font-size: 15px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ===== TYPOGRAPHY ===== */
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1.05rem; font-weight: 600; }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.7rem; }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-mono { font-family: var(--font-mono); font-size: 0.85em; }
.text-ar { font-family: var(--font-ar); direction: rtl; }
.text-center { text-align: center; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }

/* ===== SCREENS ===== */
.screen { display: none; }
.screen.active { display: flex; min-height: 100dvh; }

/* ===== LOGIN ===== */
.login-wrapper {
  width: 100%; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}
.login-card {
  background: var(--bg-card); border-radius: var(--radius-xl);
  padding: 40px 28px; width: 100%; max-width: 380px;
  box-shadow: var(--shadow-lg); text-align: center;
}
.login-logo { font-size: 2.5rem; color: var(--primary); margin-bottom: 12px; }
.login-title { margin-bottom: 4px; }
.login-subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 28px; }
.login-error { color: var(--danger); font-size: 0.85rem; margin-top: 12px; min-height: 20px; }

/* ===== INPUT ===== */
.input-group {
  position: relative; margin-bottom: 14px;
}
.input-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 1.1rem; pointer-events: none;
}
.input-group input, .input-group select, .input-group textarea {
  width: 100%; padding: 12px 14px 12px 42px;
  border: 1.5px solid var(--border); border-radius: var(--radius-md);
  font-size: 0.95rem; font-family: var(--font);
  background: var(--bg-subtle); transition: all 0.2s;
}
.input-group input:focus, .input-group select:focus, .input-group textarea:focus {
  outline: none; border-color: var(--primary); background: var(--bg-card);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Simple inputs (no icon) */
.form-input {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: var(--radius-md);
  font-size: 0.9rem; font-family: var(--font);
  background: var(--bg-card); transition: all 0.2s;
}
.form-input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-input.text-ar { font-family: var(--font-ar); direction: rtl; }
.form-label {
  display: block; font-size: 0.78rem; font-weight: 500;
  color: var(--text-secondary); margin-bottom: 4px;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border: none; border-radius: var(--radius-md);
  font-size: 0.9rem; font-weight: 500; font-family: var(--font);
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn-primary { background: var(--primary); color: var(--text-inverse); }
.btn-primary:hover { background: var(--primary-hover); }

.btn-danger { background: var(--danger); color: var(--text-inverse); }
.btn-danger:hover { background: #b91c1c; }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.btn-outline {
  background: transparent; color: var(--primary);
  border: 1.5px solid var(--border);
}
.btn-outline:hover { border-color: var(--primary); background: var(--primary-light); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; border-radius: var(--radius-sm); }
.btn-full { width: 100%; }
.btn-icon {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; border-radius: var(--radius-md);
  color: var(--text-secondary); font-size: 1.3rem; cursor: pointer;
}
.btn-icon:hover { background: var(--bg-hover); }

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w); background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 200; transform: translateX(-100%);
  transition: transform 0.25s ease;
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 199; display: none;
}
.sidebar-overlay.show { display: block; }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px; border-bottom: 1px solid var(--border-light);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 1.1rem; font-weight: 700; color: var(--primary);
}
.sidebar-brand i { font-size: 1.4rem; }
.sidebar-close { display: none; }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius-md);
  color: var(--text-secondary); font-size: 0.9rem; font-weight: 500;
  cursor: pointer; transition: all 0.15s; margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary-text); }
.nav-item i { font-size: 1.2rem; }
.nav-section {
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted);
  padding: 16px 14px 6px; margin-top: 4px;
}

.sidebar-footer {
  padding: 12px 16px; border-top: 1px solid var(--border-light);
}
.sidebar-user {
  font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 8px;
}

/* ===== TOP HEADER ===== */
.top-header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; height: var(--header-h);
  background: var(--bg-card); border-bottom: 1px solid var(--border-light);
}
.top-title { flex: 1; font-size: 1.05rem; font-weight: 600; }

/* ===== MAIN CONTENT ===== */
#screen-app { display: none; width: 100%; }
#screen-app.active { display: flex; }

.main-content { flex: 1; min-height: 100dvh; display: flex; flex-direction: column; }
.page-container {
  flex: 1; padding: 16px; padding-bottom: calc(var(--bottom-nav-h) + 20px);
  max-width: var(--max-w); width: 100%; margin: 0 auto;
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h); background: var(--bg-card);
  border-top: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-around;
  z-index: 100; padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 12px; border-radius: var(--radius-md);
  color: var(--text-muted); font-size: 0.65rem; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.bottom-nav-item i { font-size: 1.3rem; }
.bottom-nav-item.active { color: var(--primary); }

/* ===== CARDS ===== */
.card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  border: 1px solid var(--border-light); padding: 16px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 12px; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
}
.card-title {
  font-size: 0.8rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.3px; color: var(--text-secondary);
  display: flex; align-items: center; gap: 6px;
}
.card-title i { color: var(--primary); }

/* ===== STAT CARDS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: var(--bg-card); border-radius: var(--radius-md);
  padding: 14px; border: 1px solid var(--border-light);
}
.stat-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; font-weight: 500; letter-spacing: 0.3px; }
.stat-value { font-size: 1.6rem; font-weight: 700; margin-top: 2px; }
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }
.stat-value.danger { color: var(--danger); }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; padding: 3px 10px;
  border-radius: var(--radius-full); font-size: 0.7rem; font-weight: 600;
}
.badge-success { background: var(--success-light); color: var(--success-text); }
.badge-warning { background: var(--warning-light); color: var(--warning-text); }
.badge-danger { background: var(--danger-light); color: var(--danger-text); }
.badge-info { background: var(--primary-light); color: var(--primary-text); }

/* ===== LIST ITEMS ===== */
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: var(--radius-md);
  cursor: pointer; transition: background 0.15s;
  border-bottom: 1px solid var(--border-light);
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--bg-hover); }
.list-item:active { background: var(--bg-subtle); }

.list-avatar {
  width: 42px; height: 42px; border-radius: var(--radius-full);
  background: var(--primary-light); display: flex; align-items: center; justify-content: center;
  color: var(--primary); font-weight: 600; font-size: 0.9rem; flex-shrink: 0;
}
.list-body { flex: 1; min-width: 0; }
.list-title { font-weight: 500; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-subtitle { font-size: 0.78rem; color: var(--text-secondary); margin-top: 1px; }
.list-meta { text-align: right; flex-shrink: 0; }

/* ===== DETAIL SECTIONS ===== */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detail-item { }
.detail-label { font-size: 0.7rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.3px; }
.detail-value { font-size: 0.9rem; margin-top: 1px; word-break: break-word; }
.detail-full { grid-column: 1 / -1; }

/* ===== FORM GRID ===== */
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.form-group { }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ===== TABS ===== */
.tabs {
  display: flex; gap: 0; overflow-x: auto; -webkit-overflow-scrolling: touch;
  border-bottom: 1.5px solid var(--border-light); margin-bottom: 16px;
}
.tab {
  padding: 10px 16px; font-size: 0.82rem; font-weight: 500;
  color: var(--text-muted); white-space: nowrap; cursor: pointer;
  border-bottom: 2px solid transparent; transition: all 0.15s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.2s; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: calc(var(--bottom-nav-h) + 16px); left: 50%;
  transform: translateX(-50%) translateY(100px); opacity: 0;
  padding: 12px 20px; border-radius: var(--radius-full);
  font-size: 0.85rem; font-weight: 500; color: var(--text-inverse);
  z-index: 9999; transition: all 0.3s; pointer-events: none;
  box-shadow: var(--shadow-lg); max-width: 90%;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.danger { background: var(--danger); }
.toast.warning { background: var(--warning); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 500; display: none; align-items: flex-end; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal-content {
  background: var(--bg-card); border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%; max-width: 500px; max-height: 85dvh; overflow-y: auto;
  animation: slideUp 0.25s ease;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border-light);
  position: sticky; top: 0; background: var(--bg-card); z-index: 1;
}
.modal-body { padding: 20px; }

/* ===== DOCUMENT UPLOAD ===== */
.doc-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: var(--radius-md);
  border: 1px solid var(--border-light); margin-bottom: 8px;
}
.doc-icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: var(--primary-light); display: flex; align-items: center; justify-content: center;
  color: var(--primary); font-size: 1.1rem;
}
.doc-info { flex: 1; min-width: 0; }
.doc-name { font-size: 0.82rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: 0.7rem; color: var(--text-muted); }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center; padding: 40px 20px; color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; margin-bottom: 8px; display: block; }
.empty-state p { font-size: 0.9rem; }

/* ===== ANIMATIONS ===== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ===== SEARCH BAR ===== */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: var(--bg-subtle);
  border-radius: var(--radius-full); border: 1.5px solid var(--border);
  margin-bottom: 14px; transition: all 0.2s;
}
.search-bar:focus-within { border-color: var(--primary); background: var(--bg-card); }
.search-bar i { color: var(--text-muted); font-size: 1.1rem; }
.search-bar input {
  flex: 1; border: none; background: transparent; outline: none;
  font-size: 0.9rem; font-family: var(--font);
}

/* ===== FAB ===== */
.fab {
  position: fixed; bottom: calc(var(--bottom-nav-h) + 16px); right: 16px;
  width: 52px; height: 52px; border-radius: var(--radius-full);
  background: var(--primary); color: var(--text-inverse);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; box-shadow: var(--shadow-lg);
  border: none; cursor: pointer; z-index: 50;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.92); }

/* ===== RESPONSIVE ===== */

/* Tablet (768px+) */
@media (min-width: 768px) {
  .sidebar { transform: translateX(0); }
  .sidebar-close { display: none; }
  .sidebar-overlay { display: none !important; }
  .main-content { margin-left: var(--sidebar-w); }
  .bottom-nav { display: none; }
  .top-header .btn-icon:first-child { display: none; }
  .page-container { padding: 24px; padding-bottom: 24px; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr 1fr 1fr; }
  .fab { bottom: 24px; right: 24px; }
  .toast { bottom: 24px; }
  .modal-overlay { align-items: center; }
  .modal-content { border-radius: var(--radius-xl); max-height: 80dvh; }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
  .page-container { padding: 32px; }
}

/* Mobile only */
@media (max-width: 767px) {
  .sidebar-close { display: flex; }
}
