@import url("https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700&display=swap");

:root {
  --primary: #2D6A4F;
  --primary-light: #52B788;
  --primary-pale: #D8F3DC;
  --accent: #B7E4C7;
  --gold: #C8963F;
  --gold-light: #F6E5C3;
  --bg: #F8FAF9;
  --panel: #FFFFFF;
  --text: #1B2D25;
  --muted: #6B8C7B;
  --line: #E0EDE5;
  --danger: #C0392B;
  --danger-light: #FDECEA;
  --warning: #E67E22;
  --warning-light: #FEF3E2;
  --success: #27AE60;
  --success-light: #E9F7EF;
  --info: #2980B9;
  --info-light: #EBF5FB;
  --purple: #8E44AD;
  --purple-light: #F4ECF7;
  --shadow: 0 2px 12px rgba(45, 106, 79, .08);
  --shadow-lg: 0 8px 32px rgba(45, 106, 79, .13);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 230px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Cairo", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.6;
  direction: rtl;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 22px; font-weight: 700; color: var(--primary); }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
.muted { color: var(--muted); }

.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: 400px;
  max-width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .20);
}

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

.login-card .brand {
  flex-direction: column;
  text-align: center;
  gap: 10px;
}

.brand-logo,
.brand-mark {
  width: 58px;
  height: 58px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--primary-pale);
}

.sidebar .brand-logo,
.sidebar .brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255,255,255,.15);
}

.version-badge {
  margin-top: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.app-version {
  margin-top: 3px;
  color: rgba(255,255,255,.7);
  font-size: 11px;
  font-weight: 600;
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

input, select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  background: #fff;
  outline: none;
  direction: rtl;
  transition: border .15s;
}

input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { min-height: 82px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 12px;
  font-weight: 500;
  transition: all .15s;
  background: var(--primary);
  color: #fff;
}

.btn:hover:not(:disabled) { background: #245A41; }
.btn.secondary { background: #fff; color: var(--primary); border: 1.5px solid var(--primary); }
.btn.secondary:hover:not(:disabled) { background: var(--primary-pale); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.alert {
  background: var(--danger-light);
  color: var(--danger);
  padding: 10px;
  border-radius: 8px;
  font-size: 12px;
  margin-bottom: 12px;
  text-align: center;
}

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
  padding: 0;
}

.sidebar .brand {
  padding: 24px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  margin: 0;
  align-items: flex-start;
}

.sidebar .brand h3 {
  color: #fff;
  font-size: 19px;
  font-weight: 700;
}

.nav {
  padding: 12px 0;
  flex: 1;
  display: block;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 400;
  opacity: .82;
  border: none;
  background: none;
  color: #fff;
  width: 100%;
  text-align: right;
  transition: all .15s;
}

.nav button:hover { background: rgba(255,255,255,.10); opacity: 1; }
.nav button.active {
  background: rgba(255,255,255,.18);
  opacity: 1;
  font-weight: 600;
  border-right: 3px solid var(--accent);
}

.user-box {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.12);
  display: grid;
  gap: 8px;
}

.user-box .btn.ghost {
  background: rgba(255,255,255,.15);
  color: #fff;
  border: none;
  padding: 7px 8px;
}

.main {
  margin-right: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0 32px;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-subtitle { font-size: 11px; margin-top: 2px; }
.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}
.language-picker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.language-picker select {
  width: auto;
  min-width: 92px;
  height: 38px;
  padding: 0 9px;
}
.content {
  padding: 20px 24px;
  flex: 1;
  display: grid;
  gap: 12px;
  align-content: start;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.toolbar input { width: 220px; }
.toolbar select { width: 150px; }

.grid { display: grid; gap: 12px; }
.stats {
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 86px;
  align-items: stretch;
  margin-bottom: 6px;
}

.content > .stats,
.report-content > .stats {
  align-self: start;
}

.card {
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  align-self: start;
}

.card h3 { margin-bottom: 10px; }

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  height: 86px;
  min-height: 0;
  max-height: 86px;
  overflow: hidden;
}

.stat-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.stat-icon.green { background: var(--primary-pale); }
.stat-icon.gold { background: var(--gold-light); }
.stat-icon.blue { background: var(--info-light); }
.stat-icon.red { background: var(--danger-light); }
.stat-icon.purple { background: var(--purple-light); }

.stats > .card { min-height: 0; }

.stat-value {
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
  color: var(--text);
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Unified compact page rhythm */
.content > .card,
.content > .table-wrap,
.content > .reports-shell,
.content > .toolbar {
  width: 100%;
}

.content .card + .table-wrap,
.content .toolbar + .card,
.content .toolbar + .table-wrap {
  margin-top: 0;
}

.content > .card .table-wrap {
  box-shadow: none;
  border-radius: var(--radius-sm);
}

.content > .card:has(.table-wrap) {
  padding: 12px;
}

.content > .card:has(.table-wrap) h3 {
  padding: 0 4px;
}

select,
input[type="date"],
input[type="time"],
input[type="number"] {
  min-height: 36px;
}

input,
textarea {
  min-height: 36px;
}

textarea {
  min-height: 72px;
}

.table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  align-self: start;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

tbody tr {
  height: 42px;
}

th {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-align: right;
  padding: 7px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #F4F9F6; }

.actions { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.actions .btn { padding: 4px 9px; font-size: 11.5px; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.pill.done { background: var(--success-light); color: var(--success); }
.pill.pending { background: var(--info-light); color: var(--info); }
.pill.cancelled { background: var(--danger-light); color: var(--danger); }

.rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.reports-shell .table-wrap,
.reports-shell .card {
  box-shadow: none;
}

.reports-shell .stats {
  margin-bottom: 0;
}

.rank-row:last-child { border-bottom: none; }
.rank-row span { flex: 1; font-size: 13px; font-weight: 500; }
.rank-row strong { font-size: 13px; font-weight: 600; color: var(--primary); }

.reports-shell {
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
  align-self: start;
}

.reports-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 16px 0;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  background: var(--bg);
}

.rtab {
  padding: 7px 12px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: none;
  transition: all .15s;
  background: transparent;
}

.rtab:hover { color: var(--primary); background: var(--primary-pale); }
.rtab.active {
  color: var(--primary);
  background: #fff;
  border-color: var(--line);
  font-weight: 600;
}

.filter-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.report-content {
  padding: 14px;
  display: grid;
  gap: 12px;
  align-content: start;
}
.report-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.export-btns { display: flex; gap: 8px; flex-wrap: wrap; }

.report-alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.report-alert.warning { background: var(--warning-light); color: var(--warning); border-right: 3px solid var(--warning); }
.report-alert.success { background: var(--success-light); color: var(--success); border-right: 3px solid var(--success); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.4);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-card {
  background: #fff;
  border-radius: var(--radius);
  width: 520px;
  max-width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  direction: rtl;
}

.modal-head {
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

.modal-body {
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}

.modal-body .full { grid-column: 1 / -1; }
.modal-foot {
  padding: 13px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  position: sticky;
  bottom: 0;
  background: #fff;
}

.hidden { display: none !important; }

.quick-search {
  position: relative;
  width: clamp(220px, 28vw, 360px);
  min-width: 0;
}

.quick-search input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
}

.quick-results {
  position: fixed;
  top: 72px;
  left: 12px;
  right: auto;
  width: min(420px, calc(100vw - var(--sidebar-w) - 64px));
  max-width: calc(100vw - var(--sidebar-w) - 64px);
  max-height: min(520px, calc(100vh - 88px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 20;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.quick-results button {
  min-width: 0;
  width: 100%;
  border: 0;
  background: #fff;
  padding: 10px 12px;
  display: grid;
  gap: 3px;
  text-align: right;
  cursor: pointer;
}

.quick-results button:hover { background: var(--surface); }
.quick-results span { color: var(--muted); font-size: 12px; }
.quick-group { border-bottom: 1px solid var(--line); padding: 6px; }
.quick-group:last-child { border-bottom: 0; }
.quick-title {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  padding: 5px 7px;
}
.quick-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: stretch;
}
.quick-item strong,
.quick-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quick-action {
  width: auto !important;
  min-width: 58px;
  border-radius: 7px;
  background: var(--primary-pale) !important;
  color: var(--primary);
  text-align: center !important;
}
.quick-empty {
  padding: 14px;
  color: var(--muted);
  font-size: 13px;
}

.calendar-shell { display: grid; gap: 14px; }
.calendar-toolbar { align-items: center; justify-content: space-between; }
.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 9px 14px;
  cursor: pointer;
}
.segmented button.active { background: var(--primary); color: #fff; }
.calendar-nav { display: flex; gap: 8px; }
.calendar-grid {
  display: grid;
  gap: 10px;
}
.calendar-grid.month { grid-template-columns: repeat(7, minmax(120px, 1fr)); }
.calendar-grid.week { grid-template-columns: repeat(7, minmax(140px, 1fr)); }
.calendar-grid.day { grid-template-columns: 1fr; }
.calendar-day {
  min-height: 138px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
}
.calendar-grid.day .calendar-day { min-height: 520px; }
.calendar-day.today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.calendar-day header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}
.calendar-day header strong { color: var(--text); font-size: 18px; }
.calendar-events { display: grid; align-content: start; gap: 6px; }
.calendar-event {
  border: 0;
  border-radius: 7px;
  padding: 8px;
  text-align: right;
  background: var(--primary-light);
  color: var(--text);
  cursor: pointer;
  display: grid;
  gap: 2px;
}
.calendar-event.done { background: var(--success-light); }
.calendar-event.cancelled { background: var(--danger-light); }
.calendar-event span, .calendar-event em { font-size: 11px; color: var(--muted); font-style: normal; }
.calendar-empty { color: var(--muted); font-size: 12px; }

.pill.paid { background: var(--success-light); color: var(--success); }
.pill.unpaid { background: var(--danger-light); color: var(--danger); }
.pill.deposit { background: var(--warning-light); color: var(--warning); }

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, .8fr);
  gap: 16px;
}
.settings-grid form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.settings-grid form .full, .settings-grid form button { grid-column: 1 / -1; }
.logo-upload {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 10px;
  align-items: center;
}
.logo-upload img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 6px;
}
.work-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(90px, 1fr));
  gap: 8px;
}
.work-days label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
}
.backup-panel {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
}
.modal-card.wide { width: min(980px, 96vw); }
.client-profile {
  grid-template-columns: repeat(3, 1fr);
}
.card.mini {
  box-shadow: none;
  padding: 12px;
  display: grid;
  gap: 5px;
}
.profile-section {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
}
.file-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.inline-form {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr auto;
  gap: 8px;
}
.inline-form input {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
}

@media (max-width: 900px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .sidebar { width: 64px; }
  .sidebar .brand h3,
  .sidebar .brand .muted,
  .nav button:not(.active)::after,
  .user-box strong,
  .user-box span,
  .user-box .btn { display: none; }
  .nav button { justify-content: center; padding: 12px; font-size: 0; }
  .nav button::first-letter { font-size: 16px; }
  .main { margin-right: 64px; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .report-grid-2 { grid-template-columns: 1fr; }
  .calendar-grid.month, .calendar-grid.week { grid-template-columns: 1fr 1fr; }
  .settings-grid, .client-profile { grid-template-columns: 1fr; }
  .inline-form, .file-row { grid-template-columns: 1fr; }
  .work-days { grid-template-columns: repeat(2, 1fr); }
  .quick-results {
    width: min(420px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
  }
}

@media (max-width: 600px) {
  .stats { grid-template-columns: 1fr; }
  .modal-body { grid-template-columns: 1fr; }
  .toolbar input, .toolbar select, .toolbar .btn { width: 100%; }
  .topbar { align-items: flex-start; flex-direction: column; padding-block: 12px; }
  .quick-search {
    width: 100%;
    min-width: 0;
  }
  .quick-results {
    width: calc(100vw - 32px);
    max-width: calc(100vw - 32px);
    left: 16px;
    right: auto;
  }
  .calendar-grid.month, .calendar-grid.week { grid-template-columns: 1fr; }
  .settings-grid form { grid-template-columns: 1fr; }
  .logo-upload, .work-days { grid-template-columns: 1fr; }
}
