:root {
  --navy: #0b1f33;
  --navy-2: #123a5a;
  --blue: #1677ff;
  --blue-hover: #0958d9;
  --blue-soft: #eaf3ff;
  --green: #12805c;
  --green-soft: #e8f7f1;
  --amber: #a96100;
  --amber-soft: #fff4dd;
  --red: #c53636;
  --red-soft: #ffeded;
  --ink: #16202a;
  --muted: #657180;
  --line: #dde4ec;
  --surface: #ffffff;
  --bg: #f3f6fa;
  --radius: 16px;
  --shadow: 0 10px 28px rgba(19, 43, 66, .08);
}

* { box-sizing: border-box; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

/* Base Typography: LTR defaults to modern sans-serif, RTL to clean Arabic font */
html[dir="ltr"] body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", "Helvetica Neue", Arial, sans-serif;
}
html[dir="rtl"] body {
  font-family: "Tajawal", Tahoma, Arial, "Segoe UI", sans-serif;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.layout { min-height: 100vh; position: relative; }

/* Sidebar Positioning (Default LTR = Left) */
.sidebar {
  background: var(--navy);
  color: white;
  padding: 28px 18px;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: auto;
  width: 250px;
  z-index: 100;
  border-right: 1px solid rgba(255,255,255,.08);
  border-left: none;
}

html[dir="ltr"] .sidebar {
  left: 0 !important;
  right: auto !important;
  border-right: 1px solid rgba(255,255,255,.08) !important;
  border-left: none !important;
}
html[dir="rtl"] .sidebar {
  right: 0 !important;
  left: auto !important;
  border-left: 1px solid rgba(255,255,255,.08) !important;
  border-right: none !important;
}

/* Brand */
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px 24px; }
.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  object-fit: contain;
  flex-shrink: 0;
}
.brand strong { display: block; font-size: 1.15rem; font-weight: 800; letter-spacing: -0.01em; }
.brand small { color: #a9bdd0; font-size: .82rem; }

/* Navigation */
.nav { display: grid; gap: 7px; }
.nav a {
  padding: 11px 14px;
  border-radius: 11px;
  color: #c8d5e1;
  font-weight: 600;
  transition: all .15s ease;
}
.nav a:hover, .nav a.active {
  background: rgba(255,255,255,.12);
  color: white;
}

/* Sidebar Footer */
.sidebar-foot {
  position: absolute;
  right: 18px;
  left: 18px;
  bottom: 22px;
  border-top: 1px solid rgba(255,255,255,.12);
  padding-top: 16px;
}
.sidebar-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.user-badge {
  color: #a9bdd0;
  font-weight: 700;
  font-size: .85rem;
  max-width: 125px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lang-switch-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #c8d5e1;
  font-size: .78rem;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 8px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  transition: all .15s ease;
}
.lang-switch-link:hover {
  background: rgba(255,255,255,.2);
  color: white;
}

/* Main Content Area */
.main {
  padding: 30px 34px 60px;
  min-width: 0;
  transition: margin .2s ease;
  margin-left: 250px;
  margin-right: 0;
}
html[dir="ltr"] .main { margin-left: 250px !important; margin-right: 0 !important; }
html[dir="rtl"] .main { margin-right: 250px !important; margin-left: 0 !important; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 25px;
}
.topbar h1 { margin: 0; font-size: clamp(1.45rem, 3vw, 2rem); font-weight: 800; letter-spacing: -0.02em; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: .95rem; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.menu-button { display: none; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 9px 16px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  transition: all .15s ease;
}
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: var(--blue-hover); }
.btn-secondary { background: white; color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-success { background: var(--green); color: white; }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: #ffd6d6; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: .86rem; }
.full-width { width: 100%; }

/* Language Switcher Buttons */
.lang-btn {
  border-radius: 999px;
  font-size: .86rem;
  padding: 7px 14px;
}
.lang-switch-wrap {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}
.card-top-action {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
.lang-switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 700;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--ink);
  transition: all .15s ease;
}
.lang-switch-btn:hover {
  background: var(--blue-soft);
  border-color: var(--blue);
  color: var(--blue);
}

/* Statistics */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat { padding: 20px; }
.stat .label { color: var(--muted); font-size: .88rem; font-weight: 600; }
.stat .value { font-size: 1.85rem; font-weight: 800; margin-top: 8px; color: var(--ink); }
.stat .hint { font-size: .8rem; color: var(--muted); margin-top: 2px; }

/* Grid & Sections */
.grid-2 { display: grid; grid-template-columns: 1.4fr .8fr; gap: 20px; }
.section { padding: 22px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 16px; }
.section h2 { margin: 0; font-size: 1.15rem; font-weight: 800; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 13px 12px; border-bottom: 1px solid #edf0f4; }
html[dir="ltr"] th, html[dir="ltr"] td { text-align: left; }
html[dir="rtl"] th, html[dir="rtl"] td { text-align: right; }
th { color: var(--muted); font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:last-child td { border-bottom: 0; }
.service strong { display: block; font-weight: 700; }
.service small { color: var(--muted); }

/* Badges */
.badge { display: inline-flex; border-radius: 999px; padding: 5px 10px; font-size: .78rem; font-weight: 700; }
.badge-overdue { color: var(--red); background: var(--red-soft); }
.badge-today { color: var(--amber); background: var(--amber-soft); }
.badge-soon { color: #165db8; background: var(--blue-soft); }
.badge-upcoming { color: var(--green); background: var(--green-soft); }
.actions { display: flex; gap: 6px; }

/* Alerts */
.alert { padding: 13px 16px; border-radius: 11px; margin-bottom: 18px; font-weight: 600; font-size: .92rem; }
.alert-success { background: var(--green-soft); color: #0d6548; border: 1px solid #b7ebd8; }
.alert-error { background: var(--red-soft); color: #982828; border: 1px solid #ffd0d0; }
.alert ul { margin: 0; }
html[dir="ltr"] .alert ul { padding-left: 20px; padding-right: 0; }
html[dir="rtl"] .alert ul { padding-right: 20px; padding-left: 0; }

/* Forms */
.form-card { max-width: 860px; padding: 26px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.field { display: grid; gap: 7px; }
.field-full { grid-column: 1 / -1; }
label { font-weight: 700; font-size: .88rem; color: #22303e; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  color: var(--ink);
  background: white;
  border: 1px solid #cfd8e3;
  border-radius: 10px;
  outline: none;
  transition: all .15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(22,119,255,.12);
}
textarea { min-height: 100px; resize: vertical; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; }
.empty { text-align: center; padding: 40px 15px; color: var(--muted); font-weight: 600; }

/* Login & Setup Page */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 20px;
}
html[dir="ltr"] .login-page {
  background: radial-gradient(circle at top left, #174e76, var(--navy) 65%);
}
html[dir="rtl"] .login-page {
  background: radial-gradient(circle at top right, #174e76, var(--navy) 65%);
}

.login-card {
  width: min(440px, 100%);
  background: white;
  border-radius: 22px;
  padding: 32px 30px;
  box-shadow: 0 24px 70px rgba(0,0,0,.25);
}
.login-card .brand { color: var(--ink); padding: 0 0 20px; }
.login-card .brand small { color: var(--muted); }
.login-card h1 { margin: 0 0 6px; font-size: 1.5rem; font-weight: 800; }
.login-card > p { margin: 0 0 22px; color: var(--muted); font-size: .92rem; }
.login-card .field { margin-bottom: 16px; }
.login-card .btn { width: 100%; margin-top: 8px; }

/* Summary List */
.summary-list { display: grid; gap: 14px; }
.summary-row { display: flex; align-items: center; justify-content: space-between; padding-bottom: 12px; border-bottom: 1px solid #edf0f4; }
.summary-row:last-child { border-bottom: 0; padding-bottom: 0; }
.summary-row span { color: var(--muted); }
.inline-form { display: inline; }
.muted { color: var(--muted); font-size: .84rem; }

/* Responsive Styles */
@media (max-width: 980px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .layout { display: block; }
  .sidebar {
    transition: transform .25s ease;
    z-index: 200;
  }
  html[dir="ltr"] .sidebar {
    transform: translateX(-105%);
    box-shadow: 15px 0 40px rgba(0,0,0,.25);
  }
  html[dir="rtl"] .sidebar {
    transform: translateX(105%);
    box-shadow: -15px 0 40px rgba(0,0,0,.25);
  }
  .menu-open .sidebar { transform: translateX(0) !important; }

  .main { margin-right: 0 !important; margin-left: 0 !important; padding: 20px 16px 45px; }
  .menu-button { display: inline-flex; }
  .topbar { align-items: flex-start; }
  .topbar-actions { display: flex; gap: 8px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 15px; }
  .stat .value { font-size: 1.4rem; }
  .form-grid { grid-template-columns: 1fr; }
  .field-full { grid-column: auto; }
  .table-wrap { overflow: visible; }
  table { white-space: normal; }
  table thead { display: none; }
  table, table tbody, table tr, table td { display: block; width: 100%; }
  table tbody { display: grid; gap: 12px; }
  table tr { padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: #fff; }
  table td { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0; border: 0; }
  table td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 700; }
  table td.service { align-items: flex-start; flex-direction: column; gap: 0; border-bottom: 1px solid #edf0f4; padding-bottom: 12px; margin-bottom: 4px; }
  table td.service::before { display: none; }
  table td .actions { flex-wrap: wrap; justify-content: flex-end; }
}

@media (max-width: 440px) {
  .stats { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .topbar-actions .btn-primary { flex: 1; }
}
