:root {
  color-scheme: light;

  --primary-50: #eef2ff;
  --primary-100: #e0e7ff;
  --primary-500: #4f46e5;
  --primary-600: #4338ca;
  --primary-700: #3730a3;

  --success-50: #f0fdf4;
  --success-600: #16a34a;
  --success-700: #15803d;

  --danger-50: #fef2f2;
  --danger-600: #dc2626;
  --danger-700: #b91c1c;

  --warning-50: #fffbeb;
  --warning-600: #d97706;

  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --bg: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

  --font: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5 {
  font-weight: 700;
  color: var(--text);
  margin: 0 0 6px;
  line-height: 1.35;
}

h2 { font-size: 22px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; }

p { margin: 0 0 10px; }

a { color: var(--primary-600); }

:focus-visible {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Layout ---------- */

.container {
  max-width: 1040px;
  margin: 28px auto 60px;
  padding: 0 20px;
}

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

.page-header h2 {
  margin: 0;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: -8px;
  margin-bottom: 16px;
}

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 22px;
  height: 62px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary-500), var(--primary-700));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  color: var(--text);
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}

.nav::-webkit-scrollbar { display: none; }

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.nav-link:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.nav-link.active {
  background: var(--primary-50);
  color: var(--primary-700);
}

.topbar-end {
  flex-shrink: 0;
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.card > h3, .card > h4 {
  margin-bottom: 14px;
}

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

.card-row h3, .card-row h4 {
  margin-bottom: 0;
}

/* ---------- Stat cards ---------- */

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.stat-card .stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 600;
}

/* ---------- Tables ---------- */

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: right;
  padding: 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

thead th {
  padding: 10px 12px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-alt);
  white-space: nowrap;
}

thead th:first-child { border-radius: var(--radius-sm) 0 0 0; }
thead th:last-child { border-radius: 0 var(--radius-sm) 0 0; }

tbody td {
  text-align: right;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-alt); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 700;
  font-family: inherit;
  text-decoration: none;
  transition: filter 0.15s ease, background 0.15s ease, transform 0.05s ease;
}

.btn:active { transform: translateY(1px); }
.btn svg { width: 15px; height: 15px; }

.btn-primary { background: var(--primary-600); color: #fff; }
.btn-primary:hover { background: var(--primary-700); }

.btn-success { background: var(--success-600); color: #fff; }
.btn-success:hover { background: var(--success-700); }

.btn-danger { background: var(--danger-600); color: #fff; }
.btn-danger:hover { background: var(--danger-700); }

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

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }

.btn-sm { padding: 6px 12px; font-size: 12.5px; }

form.inline { display: inline-block; margin-left: 6px; }
form.inline:last-child { margin-left: 0; }

/* ---------- Forms ---------- */

label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  display: block;
  margin-bottom: 6px;
}

input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder, textarea::placeholder { color: var(--text-faint); }

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

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px var(--primary-100);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  padding-left: 36px;
}

input[type="checkbox"], input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0 0 0 8px;
  vertical-align: middle;
  accent-color: var(--primary-600);
}

label:has(input[type="checkbox"]), label:has(input[type="radio"]) {
  display: flex;
  align-items: flex-start;
  font-weight: 500;
  gap: 0;
  cursor: pointer;
}

td input, td select, td textarea {
  margin-bottom: 0;
}

td input[type="checkbox"] {
  width: 17px;
  height: 17px;
}

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

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px 4px;
  margin: 0 0 16px;
}

fieldset legend {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0 6px;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge-draft { background: #f1f5f9; color: #475569; }
.badge-open { background: var(--success-50); color: var(--success-700); }
.badge-closed { background: var(--danger-50); color: var(--danger-700); }
.badge-in_progress { background: var(--warning-50); color: #92400e; }
.badge-submitted { background: var(--primary-50); color: var(--primary-700); }
.badge-accepted { background: var(--success-50); color: var(--success-700); }
.badge-rejected { background: var(--danger-50); color: var(--danger-700); }

/* ---------- Alerts ---------- */

.error {
  background: var(--danger-50);
  color: var(--danger-700);
  border: 1px solid #fecaca;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  font-size: 14px;
  font-weight: 600;
}

.muted { color: var(--text-muted); font-size: 13px; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 8px;
}

/* ---------- Auth pages ---------- */

.auth-shell {
  min-height: calc(100vh - 40px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
}

.auth-card .brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  font-size: 17px;
  margin-bottom: 16px;
}

.auth-card h2 {
  margin-bottom: 4px;
}

.auth-card .page-subtitle {
  margin-bottom: 20px;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .container { padding: 0 14px; margin-top: 18px; }
  .topbar-inner { height: auto; flex-wrap: wrap; padding: 12px 14px; gap: 10px; }
  .nav { order: 3; width: 100%; }
  .card { padding: 16px; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    padding: 10px 14px;
  }
  tbody td {
    border-bottom: none;
    padding: 5px 0;
  }
}
