:root {
  --bg: #F4F7FB;
  --surface: #FFFFFF;
  --border: #E3E9F0;
  --text: #1F2A37;
  --muted: #7C8B9E;
  --primary: #1E3A5F;
  --primary-hover: #28496F;
  --amber: #D9A441;
  --amber-soft: #FBF0DC;
  --danger: #C1473E;
  --success: #227A57;
  --warning: #D9A441;
  --radius: 9px;
  --radius-card: 14px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }

html, body { overflow-x: hidden; }

body {
  margin: 0;
  font-family: 'Cairo', "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.num-font { font-family: 'Manrope', sans-serif; }

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

/* App shell: sidebar icon rail + topbar + content */
.app-shell { display: flex; min-height: 100vh; }

.rail {
  width: 72px;
  flex-shrink: 0;
  background: var(--primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
  gap: 10px;
}

.rail-logo {
  width: 36px;
  height: 36px;
  border: 2px dashed var(--amber);
  border-radius: 50%;
  opacity: 0.7;
  margin-bottom: 14px;
  flex-shrink: 0;
}

.rail-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #A9BAD0;
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
  position: relative;
}

.rail-btn svg,
details.rail-flyout > summary svg { width: 20px; height: 20px; stroke: currentColor; fill: none; }

a.rail-btn:hover { color: #fff; }

.rail-btn.active { background: var(--amber); color: var(--primary); }
.rail-btn.active svg { stroke: var(--primary); }

details.rail-flyout { list-style: none; position: relative; }
details.rail-flyout > summary {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #A9BAD0;
  cursor: pointer;
  list-style: none;
}
details.rail-flyout[open] > summary,
details.rail-flyout > summary:hover { color: #fff; }
details.rail-flyout.active > summary { background: var(--amber); color: var(--primary); }
details.rail-flyout.active > summary svg { stroke: var(--primary); }
details.rail-flyout > summary::-webkit-details-marker { display: none; }
details.rail-flyout > summary::marker { content: ""; }

.flyout-menu {
  position: absolute;
  inset-inline-start: 100%;
  top: 0;
  margin-inline-start: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem;
  min-width: 190px;
  box-shadow: 0 10px 24px rgba(30, 58, 95, 0.14);
  z-index: 30;
  display: flex;
  flex-direction: column;
}
.flyout-menu a {
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.9rem;
}
.flyout-menu a:hover { background: var(--bg); color: var(--primary); }

/* Rail tooltips (desktop only, hover) */
.rail-btn[data-tooltip]::after,
details.rail-flyout > summary[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  inset-inline-start: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-inline-start: 10px;
  background: var(--text);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s;
  z-index: 40;
}
.rail-btn[data-tooltip]:hover::after,
details.rail-flyout > summary[data-tooltip]:hover::after { opacity: 1; }
details.rail-flyout[open] > summary::after { opacity: 0 !important; }

.shell { flex: 1; display: flex; flex-direction: column; min-width: 0; }

header.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 30px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.breadcrumb { font-size: 13px; color: var(--muted); }
.breadcrumb b { color: var(--primary); font-weight: 700; }

.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }
.lang-form { display: inline-flex; }
.lang-toggle-app {
  border: 1px solid var(--border);
  background: none;
  padding: 7px 14px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 8px;
  color: var(--primary);
  font-family: inherit;
  font-weight: 600;
}
.lang-toggle-app:hover { border-color: var(--primary); }

main {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 26px 30px;
}

body.auth-shell main { max-width: none; margin: 0; padding: 0; min-height: 100vh; }

.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: 0 6px 20px rgba(30, 58, 95, 0.06);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.75rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 14.5px; font-weight: 700; color: var(--primary); margin: 0; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius-card);
  overflow: hidden;
}

th, td {
  padding: 0.6rem 0.8rem;
  text-align: start;
  border-bottom: 1px solid var(--border);
}

th { background: #FAFCFE; font-weight: 600; color: var(--muted); font-size: 0.75rem; }
th a.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
th a.sort-link:hover { color: var(--primary); }

tr:last-child td { border-bottom: none; }

.totals-row td { background: #FAFCFE; border-top: 2px solid var(--border); }

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 600;
}

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

.btn.secondary {
  background: var(--surface);
  color: var(--primary);
}

.btn.danger {
  border-color: var(--danger);
  background: var(--danger);
}

.btn.danger:hover { background: #a53c34; border-color: #a53c34; }

.btn:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.7rem;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 700;
  background: #e5e7eb;
}

.badge.open { background: var(--amber-soft); color: #8A6216; }
.badge.closed { background: #E1F3EA; color: var(--success); }

.badge.pending { background: var(--amber-soft); color: #8A6216; }
.badge.approved { background: #E1F3EA; color: var(--success); }
.badge.rejected { background: #FBE6E4; color: var(--danger); }
.badge.cancelled { background: #e5e7eb; color: #4b5563; }

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li {
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
}
.messages li.success { background: #E1F3EA; color: var(--success); }
.messages li.error { background: #FBE6E4; color: var(--danger); }

.errorlist { list-style: none; padding: 0; margin: 0.3rem 0; }
.errorlist li { color: var(--danger); font-size: 0.85rem; font-weight: 600; }

form p { margin: 0.6rem 0; }
label { display: block; font-weight: 600; margin-bottom: 0.25rem; font-size: 0.9rem; color: #4E5D70; }
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--bg);
}
input:not([type="checkbox"]):not([type="radio"]):focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
}
input[type="checkbox"], input[type="radio"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--primary);
  cursor: pointer;
  vertical-align: middle;
}

/* Pill-style toggle for RadioSelect/CheckboxSelectMultiple groups (e.g. period
   filter, export type/mode choices) — Django renders these as a <div> per field
   containing one <div><label><input>text</label></div> per option. */
.toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.toggle-group > div { margin: 0; }
.toggle-group label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
.toggle-group input[type="radio"], .toggle-group input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
}
.toggle-group label:has(input:checked) {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.muted { color: var(--muted); font-size: 0.9rem; }

.activity-log { list-style: none; padding: 0; }
.activity-log li {
  border-inline-start: 3px solid var(--primary);
  padding: 0.4rem 0.8rem;
  margin-bottom: 0.4rem;
  background: var(--bg);
}

.page-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.page-actions form { display: inline-flex; }
.back-btn { font-size: 0.9rem; padding: 0.4rem 0.9rem; }

.date-shortcuts { display: inline-flex; gap: 0.4rem; margin-inline-start: 0.5rem; }
.date-shortcuts .btn { width: auto; padding: 0.4rem 0.7rem; font-size: 0.85rem; }

.date-filter-toggle { align-self: flex-end; }
.date-filter-toggle > summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.date-filter-toggle > summary::-webkit-details-marker { display: none; }
.date-filter-toggle > summary::marker { content: ""; }
.date-filter-toggle .date-filter-fields { display: flex; gap: 0.75rem; margin-top: 0.5rem; flex-wrap: wrap; }
.date-filter-toggle .date-filter-fields label { min-width: 150px; }

/* Month/year period filter (reports/_period_filter.html) — compact single-row layout
   instead of the default block <label> stacking its text above a full-width <select>. */
.filter-fields {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  margin-bottom: 0.75rem;
}
.filter-fields label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-size: 0.9rem;
  white-space: nowrap;
}
.filter-fields select {
  width: auto;
  min-width: 100px;
}
.period-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
.period-pill input[type="radio"] { width: 1rem; height: 1rem; margin: 0; }
.period-pill:has(input:checked) { background: var(--primary); border-color: var(--primary); color: #fff; }
.month-year-fields { display: none; align-items: center; gap: 0.6rem 1rem; flex-wrap: wrap; }
/* Hidden by default — including on a fresh page load where no radio is checked yet —
   and shown only once "شهر محدد" (a specific month) is explicitly selected. Pure CSS,
   no JS. */
.filter-fields:has(input[name="period"][value="month"]:checked) .month-year-fields { display: flex; }

/* Column-activity filter row (reports/employee_totals.html only) — sits below the
   date-filter row as its own visually separated line of pill buttons. */
.column-filter-row {
  padding-top: 0.6rem;
  margin-top: 0.15rem;
  border-top: 1px dashed var(--border);
}
.hidden-note { font-size: 0.85rem; color: var(--muted); }
.hidden-note a { margin-inline-start: 0.3rem; font-weight: 600; }

.row-actions { display: inline-flex; gap: 0.3rem; flex-wrap: wrap; }
.row-actions .btn { width: auto; padding: 0.35rem 0.6rem; font-size: 0.8rem; }

.reorder-list { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.reorder-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(30, 58, 95, 0.04);
}
.reorder-list li.dragging { opacity: 0.6; box-shadow: 0 8px 20px rgba(30, 58, 95, 0.15); }
.reorder-name { flex: 1; font-weight: 600; }
.drag-handle { cursor: grab; color: var(--muted); font-size: 1.2rem; line-height: 1; padding: 0.2rem 0.4rem; touch-action: none; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.dashboard-header h1 { margin: 0; }

.stat-group { margin-bottom: 1.75rem; }
.stat-group h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  color: var(--text);
  font-weight: 600;
  margin: 0 0 0.75rem;
}
.stat-group h2::before {
  content: "";
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 999px;
  background: var(--stat-accent, var(--primary));
  flex-shrink: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 220px));
  gap: 0.9rem;
}

.stat-tile {
  --stat-accent: var(--primary);
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 1rem 1.25rem;
  box-shadow: 0 6px 20px rgba(30, 58, 95, 0.06);
  border-inline-start: 4px solid var(--stat-accent);
}

.stat-tile.warning { --stat-accent: var(--amber); }
.stat-group.warning h2 { --stat-accent: var(--amber); }

.stat-label { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.4rem; font-weight: 600; }
.stat-value {
  font-family: 'Manrope', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}
.stat-value.compact { font-size: 1.3rem; }
.stat-sub { font-size: 0.8rem; color: var(--muted); margin-top: 0.5rem; }
.stat-chip {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.68rem;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--amber-soft);
  color: #8A6216;
  font-weight: 700;
}

.stat-tile-link { display: block; color: inherit; text-decoration: none; }
.stat-tile-link:hover .stat-label, .stat-tile-link:hover .stat-value { color: var(--amber); }
.stat-sub a { color: inherit; text-decoration: underline dotted; }
.stat-sub a:hover { color: var(--primary); }

/* Employee profile header */
.profile-head { display: flex; gap: 1.1rem; align-items: center; }
.avatar {
  width: 60px;
  height: 60px;
  border-radius: 16px;
  background: var(--primary);
  color: var(--amber);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.3rem;
  flex-shrink: 0;
}
.profile-head h2 { margin: 0; font-size: 1.15rem; color: var(--primary); }

/* Leave request page: form fields + info box */
.leave-request-card .field { margin-bottom: 1rem; }
.info-box {
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius);
  margin: -0.5rem 0 1rem;
  font-size: 0.9rem;
}
.info-box.hidden-box { display: none; }
.info-box.loading { background: var(--bg); color: var(--muted); }
.info-box.success { background: #E1F3EA; color: var(--success); }
.info-box.error { background: #FBE6E4; color: var(--danger); }

.date-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: start;
}

.days-box { margin: 0.75rem 0 1rem; font-weight: 600; }

.message { margin-top: 0.75rem; font-weight: 600; }
.message.loading { color: var(--muted); }
.message.success { color: var(--success); }
.message.error { color: var(--danger); }

/* Leave request: dynamic availability calendar */
.calendar-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-top: 0.5rem;
  background: var(--surface);
}
.calendar-panel.hidden-calendar { display: none; }

.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.calendar-toolbar .nav-btn { padding: 0.3rem 0.75rem; }
.calendar-title { font-weight: 700; color: var(--primary); }

.calendar-months {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
}
.month { flex: 1 1 260px; min-width: 240px; }
.month-title { font-weight: 600; text-align: center; margin-bottom: 0.4rem; color: var(--primary); }

.weekdays, .days-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.2rem;
}
.weekday { text-align: center; font-size: 0.75rem; color: var(--muted); padding: 0.2rem 0; }

.day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: 'Manrope', sans-serif;
  padding: 0;
}
.day:hover:not(:disabled) { border-color: var(--primary); }
.day.empty { visibility: hidden; border: none; }
.day.weekend { background: var(--bg); }

.day.disabled { background: var(--bg); color: var(--muted); cursor: not-allowed; opacity: 0.6; }
.day.full { background: #FBE6E4; color: var(--danger); border-color: var(--danger); cursor: not-allowed; }
.day.rule-blocked { background: var(--amber-soft); color: #8A6216; border-color: var(--amber); cursor: not-allowed; }
.day.start-blocked { border: 1px dashed var(--amber); color: #8A6216; }

.day.in-range { background: #E5EBFA; border-color: var(--primary); }
.day.start, .day.end {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 700;
}

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.legend-item { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.8rem; color: var(--muted); }
.legend-swatch {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 3px;
  border: 1px solid var(--border);
}
.legend-swatch.available { background: var(--surface); }
.legend-swatch.full { background: #FBE6E4; border-color: var(--danger); }
.legend-swatch.rule-blocked { background: var(--amber-soft); border-color: var(--amber); }
.legend-swatch.start-blocked { background: var(--surface); border: 1px dashed var(--amber); }
.legend-swatch.disabled { background: var(--bg); }

/* Login screen */
#page-login { min-height: 100vh; display: flex; }
.login-side {
  flex: 1;
  background: linear-gradient(160deg, var(--primary), var(--primary-hover));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 44px;
  color: #fff;
}
.login-side .rail-logo { margin-bottom: 0; opacity: 0.8; }
.login-side .tagline { font-size: 24px; font-weight: 700; line-height: 1.6; max-width: 380px; }
.login-side .foot { font-size: 12px; color: #A9BAD0; }

.login-form-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  position: relative;
  background: var(--surface);
}
.login-form-wrap .lang-form { position: absolute; top: 22px; inset-inline-start: 22px; }
.login-card { width: min(360px, 100%); }
.login-card h1 { font-size: 23px; font-weight: 800; color: var(--primary); margin: 0 0 5px; }
.login-sub { font-size: 13px; color: var(--muted); margin-bottom: 28px; }
.login-card .btn { width: 100%; padding: 12px; font-size: 14.5px; margin-top: 4px; }

@media (max-width: 640px) {
  .app-shell { flex-direction: column; }
  .rail {
    width: 100%;
    flex-direction: row;
    padding: 10px 14px;
    gap: 8px;
    overflow-x: auto;
  }
  .flyout-menu {
    position: fixed;
    inset-inline-start: 12px;
    inset-inline-end: 12px;
    top: 66px;
    margin-inline-start: 0;
    margin-top: 0;
    width: auto;
    max-height: calc(100vh - 90px);
    overflow-y: auto;
    z-index: 40;
  }
  .rail-btn[data-tooltip]::after, details.rail-flyout > summary[data-tooltip]::after { display: none; }

  header.topbar { padding: 0.75rem 1rem; height: auto; }
  .breadcrumb { font-size: 12px; }

  main { padding: 1rem 0.75rem; }
  .card { padding: 1rem; }

  table { font-size: 0.85rem; }
  th, td { padding: 0.5rem; }

  form p { margin: 0.75rem 0; }
  .card form button.btn[type="submit"] { width: 100%; }

  .page-actions .btn, .page-actions button.btn { flex: 1; text-align: center; }

  .date-shortcuts { display: flex; margin-inline-start: 0; margin-top: 0.4rem; }
  .date-shortcuts .btn { flex: 1; text-align: center; }

  .dashboard-header .btn { flex: 1; text-align: center; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
  .stat-tile { padding: 0.75rem 0.9rem; }
  .stat-value { font-size: 1.5rem; }

  .calendar-months { gap: 0.75rem; }
  .month { min-width: 0; }
  .day { font-size: 0.8rem; }

  .toggle-group { flex-direction: column; }
  .toggle-group label { width: 100%; }

  #page-login { flex-direction: column; }
  .login-side { padding: 28px; flex: none; }
  .login-side .tagline { font-size: 19px; }
  .login-form-wrap { padding: 28px; }
}
