:root {
  --font-ui: 'Noto Kufi Arabic', sans-serif;
  --bg-base: #f5f4f0;
  --bg-surface: #faf9f7;
  --bg-elevated: #ffffff;
  --bg-overlay: #f0ede8;
  --border: #e4e1db;
  --border-subtle: #ede9e3;
  --accent: #5b4fff;
  --accent-hover: #4a3dee;
  --accent-muted: rgba(91, 79, 255, 0.08);
  --text-primary: #1a1825;
  --text-secondary: #5c5870;
  --text-tertiary: #9e9ab0;
  --success: #1a9e6a;
  --success-muted: rgba(26, 158, 106, 0.09);
  --warning: #c97c10;
  --warning-muted: rgba(201, 124, 16, 0.09);
  --danger: #d93636;
  --danger-muted: rgba(217, 54, 54, 0.08);
  --pending: #5b4fff;
  --pending-muted: rgba(91, 79, 255, 0.08);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-card: 0 1px 4px rgba(0,0,0,0.05);
}

html.theme-dark {
  --bg-base: #0a0a0f;
  --bg-surface: #111118;
  --bg-elevated: #1a1a24;
  --bg-overlay: #22222f;
  --border: #2a2a3a;
  --border-subtle: #1e1e2a;
  --accent: #6c63ff;
  --accent-hover: #8079ff;
  --accent-muted: rgba(108,99,255,0.12);
  --text-primary: #f0effe;
  --text-secondary: #9898b0;
  --text-tertiary: #5a5a72;
  --success: #34c98a;
  --success-muted: rgba(52,201,138,0.1);
  --warning: #f5a623;
  --warning-muted: rgba(245,166,35,0.1);
  --danger: #f04040;
  --danger-muted: rgba(240,64,64,0.1);
  --pending: #6c63ff;
  --pending-muted: rgba(108,99,255,0.1);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.35), 0 1px 2px rgba(0,0,0,0.22);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.38), 0 2px 4px rgba(0,0,0,0.24);
  --shadow-card: 0 1px 4px rgba(0,0,0,0.28);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg-base); color: var(--text-primary); font-family: var(--font-ui); font-size: 15px; }
a { color: inherit; text-decoration: none; }
.app-layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--bg-surface); border-right: 1px solid var(--border); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; padding: 24px 0; position: fixed; top: 0; left: 0; height: 100vh; }
.sidebar-top { display: contents; }
.sidebar-toggle { display: none; box-shadow: var(--shadow-sm); }
.sidebar-menu { display: flex; flex-direction: column; flex: 1; }
.main-content { margin-left: 220px; flex: 1; padding: 40px 48px; max-width: 1100px; width: 100%; }
.page-header { margin-bottom: 32px; display:flex; justify-content:space-between; gap:16px; align-items:flex-start; }
.page-title { font-family: var(--font-ui); font-size: 26px; font-weight: 600; color: var(--text-primary); }
.page-subtitle { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }
.card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; box-shadow: var(--shadow-card); }
.card-sm { padding: 16px; box-shadow: var(--shadow-sm); }
.responsive-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.responsive-grid-3 { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
.responsive-grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.dashboard-home-grid { display: grid; grid-template-columns: minmax(0, 3.4fr) minmax(280px, 1fr); gap: 16px; }
.responsive-form-grid { display: grid; gap: 16px; }
.btn { display: inline-flex; align-items: center; justify-content:center; gap: 8px; padding: 9px 18px; border-radius: 8px; font-family: var(--font-ui); font-size: 14px; font-weight: 500; cursor: pointer; border: none; transition: all 0.15s; text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--bg-elevated); box-shadow: 0 2px 8px rgba(91,79,255,0.25); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-overlay); color: var(--text-primary); }
.btn-danger { background: var(--danger-muted); color: var(--danger); border: 1px solid rgba(217,54,54,0.2); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-xs { padding: 4px 10px; font-size: 12px; }
.btn-success { background: var(--success-muted); color: var(--success); border: 1px solid rgba(26,158,106,0.2); }
.btn .badge { background: var(--bg-overlay) !important; color: var(--text-secondary) !important; }
.btn-primary .badge { background: rgba(255,255,255,0.18) !important; color: var(--bg-elevated) !important; }
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-pending { background: var(--pending-muted); color: var(--pending); }
.badge-approved { background: var(--success-muted); color: var(--success); }
.badge-declined, .badge-rejected { background: var(--danger-muted); color: var(--danger); }
.badge-active { background: var(--success-muted); color: var(--success); }
.badge-inactive { background: var(--bg-overlay); color: var(--text-tertiary); border: 1px solid var(--border); }
.badge-expired { background: var(--bg-overlay); color: var(--text-tertiary); border: 1px solid var(--border); }
input, select, textarea { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; color: var(--text-primary); padding: 10px 14px; font-family: var(--font-ui); font-size: 14px; width: 100%; transition: border-color 0.15s, box-shadow 0.15s; }
input::placeholder, textarea::placeholder { color: var(--text-tertiary); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,79,255,0.1); outline: none; }
label { font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; display: block; font-weight: 500; }
.form-group { margin-bottom: 20px; }
.form-help { color: var(--text-tertiary); font-size: 12px; margin-top: 6px; }
table { width: 100%; border-collapse: collapse; }
.table-scroll { width: 100%; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
th { font-size: 12px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 500; padding: 10px 16px; border-bottom: 1px solid var(--border); text-align: left; }
th a.sort-link { display: inline-flex; align-items: center; gap: 6px; color: inherit; text-transform: none; letter-spacing: 0; }
th a.sort-link:hover { color: var(--text-primary); }
th a.sort-link.is-active { color: var(--accent); }
td { padding: 14px 16px; border-bottom: 1px solid var(--border-subtle); color: var(--text-secondary); font-size: 14px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-overlay); }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 32px; }
.stat-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px 24px; box-shadow: var(--shadow-sm); }
.stat-label { font-size: 12px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 10px; }
.stat-value { font-family: var(--font-ui); font-size: 28px; font-weight: 600; color: var(--text-primary); }
.stat-sub { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.empty-state { text-align: center; padding: 64px 24px; color: var(--text-tertiary); }
.empty-state h3 { font-size: 16px; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { font-size: 14px; margin-bottom: 18px; }
.dashboard-category-card { align-self: start; }
.recent-submissions-card { overflow: visible; }
.recent-submissions-table {
  table-layout: auto;
  min-width: 900px;
}
.recent-submissions-table th,
.recent-submissions-table td {
  white-space: nowrap;
  vertical-align: middle;
  font-size: 12px;
  line-height: 1.35;
  padding: 12px 14px;
}
.recent-submissions-table th:first-child,
.recent-submissions-table td:first-child {
  min-width: 260px;
  white-space: normal;
}
.recent-submissions-table th:nth-child(2),
.recent-submissions-table td:nth-child(2) {
  min-width: 180px;
}
.recent-submissions-table th:nth-child(3),
.recent-submissions-table td:nth-child(3) {
  min-width: 120px;
}
.recent-submissions-table th:nth-child(4),
.recent-submissions-table td:nth-child(4) {
  min-width: 120px;
}
.recent-submissions-table th:nth-child(5),
.recent-submissions-table td:nth-child(5) {
  min-width: 110px;
}
.recent-submissions-table th:nth-child(6),
.recent-submissions-table td:nth-child(6) {
  min-width: 100px;
  text-align: center;
}
.recent-submissions-table td div {
  display: block;
  min-width: 0;
  white-space: normal;
}
.submissions-filter-bar { display:flex; gap:8px; margin-bottom:18px; flex-wrap:wrap; }
.bulk-actions-bar {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}
.bulk-actions-summary { color: var(--text-secondary); font-size: 13px; }
.bulk-actions-buttons { display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
.submissions-table { min-width: 980px; }
.selection-head,
.selection-cell {
  width: 48px;
  text-align: center;
}
.table-checkbox-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  cursor: pointer;
}
.table-checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}
.category-list { display: grid; gap: 10px; max-height: 420px; overflow: auto; padding-right: 4px; }
.category-item { margin-bottom: 0; }
.category-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--text-secondary); }
.category-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.category-count { flex: none; }
.category-bar { height: 5px; background: var(--bg-elevated); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.category-fill { height: 100%; background: var(--accent); border-radius: 99px; }
.flash-stack { margin-bottom: 16px; display: grid; gap: 10px; }
.flash-banner { border-left: 3px solid; padding: 10px 14px; border-radius: 8px; font-size: 14px; }
.flash-banner.success { background: var(--success-muted); border-color: var(--success); color: var(--success); }
.flash-banner.error { background: var(--danger-muted); border-color: var(--danger); color: var(--danger); }
.sidebar-logo { display:flex; align-items:center; gap:10px; padding:0 20px 20px; margin-bottom:12px; font-family:var(--font-ui); font-weight:600; font-size:24px; color:var(--accent); }
.nav-list { list-style:none; display:grid; gap:4px; padding: 0 12px; }
.nav-link { display:flex; align-items:center; gap:10px; color:var(--text-secondary); padding:10px 12px; border-radius:10px; position:relative; font-family:var(--font-ui); font-weight:500; }
.nav-link:hover { background: var(--bg-overlay); color: var(--text-primary); }
.nav-link.active { background: var(--accent-muted); color: var(--accent); }
.nav-link.active::before { content:''; position:absolute; left:-12px; top:0; bottom:0; width:3px; background:var(--accent); border-radius:0 3px 3px 0; }
.sidebar-bottom { margin-top:auto; padding:16px 20px 0; border-top:1px solid var(--border-subtle); color:var(--text-tertiary); }
.user-name { color:var(--text-secondary); font-size:14px; font-weight:500; }
.user-email { color:var(--text-tertiary); font-size:12px; margin-top:2px; }
.logout-link { color:var(--danger); font-size:13px; display:inline-block; margin-top:10px; }

html[dir="rtl"] body {
  direction: rtl;
}

html[dir="rtl"] .sidebar {
  left: auto;
  right: 0;
}

html[dir="rtl"] .main-content {
  margin-left: 0;
  margin-right: 220px;
}

html[dir="rtl"] .sidebar-logo,
html[dir="rtl"] .nav-link,
html[dir="rtl"] .page-header,
html[dir="rtl"] .submissions-filter-bar,
html[dir="rtl"] .bulk-actions-bar {
  direction: rtl;
}

html[dir="rtl"] .nav-link.active::before {
  left: auto;
  right: -12px;
  border-radius: 3px 0 0 3px;
}

html[dir="rtl"] .theme-toggle {
  right: auto;
  left: 18px;
}

html[dir="rtl"] .copy-btn {
  margin-left: 0;
  margin-right: 8px;
}

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

.theme-toggle {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  width: auto;
  padding: 9px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
}
html.theme-dark .theme-toggle {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
html.theme-dark .bg-shape circle {
  fill: rgba(108,99,255,0.03) !important;
}

form .form-group > label[style*="position:relative"] > input[type="checkbox"] + span {
  background: var(--border);
  border: 1px solid var(--border);
}

form .form-group > label[style*="position:relative"] > input[type="checkbox"]:checked + span {
  background: var(--accent);
  border-color: var(--accent);
}

form .form-group > label[style*="position:relative"] > input[type="checkbox"] + span + span {
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
}

@media (max-width: 992px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-header > a.btn,
  .page-header > button.btn { width: 100%; }
  .responsive-grid-3,
  .responsive-grid-4 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app-layout { display: block; }
  .sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    height: auto;
    z-index: 20;
    padding: 0;
  }
  .sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 14px 12px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-surface);
  }
  .sidebar-logo { padding: 0; margin: 0; font-size: 20px; }
  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: auto;
    padding: 8px 12px;
    margin: 0;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 10px;
  }
  .sidebar-toggle-icon {
    transition: transform 0.15s ease;
  }
  .sidebar-menu {
    display: none;
    padding: 12px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-surface);
  }
  .sidebar-menu.is-open {
    display: flex;
  }
  .sidebar-menu.is-open .sidebar-toggle-icon {
    transform: rotate(180deg);
  }
  .nav-list {
    display: grid;
    gap: 8px;
    padding: 0;
  }
  .nav-link {
    justify-content: flex-start;
    text-align: left;
    padding: 11px 12px;
  }
  .nav-link.active::before { display: none; }
  .sidebar-bottom {
    display: block;
    margin-top: 12px;
    padding: 16px 4px 4px;
  }
  .main-content { margin-left: 0; padding: 20px 14px 28px; max-width: 100%; }
  html[dir="rtl"] .main-content { margin-right: 0; }
  .page-title { font-size: 22px; }
  .card { padding: 18px; }
  .responsive-grid-2,
  .responsive-grid-3,
  .responsive-grid-4 { grid-template-columns: 1fr; }
  .dashboard-home-grid { grid-template-columns: 1fr; }
  .dashboard-home-grid > * {
    min-width: 0;
    max-width: 100%;
  }
  .recent-submissions-card { padding: 0 !important; }
  .recent-submissions-card > div:first-child { padding: 18px 18px 12px !important; }
  .recent-submissions-card,
  .dashboard-category-card {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
  }
  .recent-submissions-table {
    width: 100%;
    min-width: 900px;
  }
  .recent-submissions-table th,
  .recent-submissions-table td {
    font-size: 13px;
    line-height: 1.3;
    padding: 10px 12px;
    overflow: visible;
  }
  .recent-submissions-table td div {
    overflow: visible;
    max-width: 100%;
  }
  .responsive-form-grid { grid-template-columns: 1fr !important; }
  .dashboard-category-card {
    padding: 12px 12px 10px;
    align-self: stretch;
  }
  .dashboard-category-card h2 {
    font-size: 16px !important;
    margin-bottom: 12px !important;
  }
  .category-list {
    max-height: 180px;
    gap: 8px;
    padding-right: 2px;
    min-width: 0;
  }
  .category-row {
    font-size: 12px;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
  }
  .category-name {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .category-bar { height: 4px; margin-top: 5px; }
  .stat-grid { grid-template-columns: 1fr; gap: 12px; margin-bottom: 24px; }
  .btn { width: 100%; }
  .btn-sm, .btn-xs { width: auto; }
  .submissions-filter-bar { margin-bottom: 14px; }
  .bulk-actions-bar {
    padding: 14px 16px;
    flex-direction: column;
    align-items: stretch;
  }
  .bulk-actions-buttons {
    flex-direction: column;
    align-items: stretch;
  }
  .table-scroll {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-scroll table {
    width: max-content;
    min-width: 900px;
  }
  table { font-size: 13px; }
  th, td { padding-left: 12px; padding-right: 12px; }
  .empty-state { padding: 40px 16px; }
}

@media (max-width: 640px) {
  .page-header { margin-bottom: 22px; }
  .card { padding: 16px; border-radius: 10px; }
  .dashboard-category-card {
    padding: 12px 12px 10px;
  }
  .dashboard-category-card h2 {
    font-size: 15px !important;
    margin-bottom: 10px !important;
  }
  input, select, textarea { padding: 10px 12px; }
  .badge { font-size: 11px; padding: 3px 8px; }
  .form-group { margin-bottom: 16px; }
  .responsive-form-grid { gap: 12px; }
  .sidebar-top { padding: 12px 12px 10px; }
}
