:root {
  /* Astek brand — https://astek.net/ (#009c49, #2d2927, Poppins + Big Shoulders Display) */
  --g-950: #2d2927;
  --g-900: #2d2927;
  --g-800: #3f3a37;
  --g-700: #009c49;
  --g-600: #00a864;
  --g-500: #00c072;
  --g-400: #5ed39a;
  --g-200: #c8f0dc;
  --g-100: #e8f8ef;
  --g-50: #f4fbf7;
  --black: #2d2927;
  --white: #ffffff;
  --muted: #6b6562;
  --line: rgba(45, 41, 39, 0.12);
  --shadow: 0 8px 24px rgba(45, 41, 39, 0.06);
  --radius: 6px;
  --font: "Poppins", "Cairo", Helvetica, Arial, sans-serif;
  --display: "Big Shoulders Display", "Cairo", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--black);
  background: #f6f6f6;
  min-height: 100vh;
  font-size: 15px;
  letter-spacing: 0.01em;
}
html[dir="rtl"] body,
html[dir="rtl"] button,
html[dir="rtl"] input,
html[dir="rtl"] select {
  font-family: "Cairo", "Poppins", sans-serif;
}
h1, h2, h3, .topbar h1, .panel h2, .brand strong, .auth-card h1, .card .value {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
html[dir="rtl"] h1,
html[dir="rtl"] h2,
html[dir="rtl"] h3,
html[dir="rtl"] .topbar h1,
html[dir="rtl"] .panel h2,
html[dir="rtl"] .brand strong,
html[dir="rtl"] .auth-card h1 {
  font-family: "Cairo", sans-serif;
  text-transform: none;
  letter-spacing: 0;
}

a { color: var(--g-700); text-decoration: none; }
button, input, select { font: inherit; }

.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  background: #fff;
  color: var(--g-900);
  padding: 1.4rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  border-inline-end: 1px solid var(--line);
}
.brand { display: flex; gap: 0.8rem; align-items: center; padding: 0.4rem 0.6rem; }
.brand-link {
  text-decoration: none;
  color: inherit;
  border-radius: 12px;
  transition: background 0.15s ease;
}
.brand-link:hover { background: rgba(255,255,255,0.06); color: inherit; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--g-700); color: var(--white);
  font-family: var(--display); font-weight: 800; font-size: 1.2rem;
  flex-shrink: 0;
}
.brand-logo {
  height: 36px; width: auto; max-width: 140px;
  border-radius: 8px;
  object-fit: contain; background: #fff; padding: 4px 6px;
  flex-shrink: 0;
}
.auth-logo {
  max-height: 48px; max-width: 200px;
  object-fit: contain; border-radius: 10px;
  background: #fff; padding: 6px 8px;
}
.logo-preview {
  margin-bottom: 0.7rem;
  display: inline-flex;
  padding: 0.7rem;
  border-radius: 14px;
  background: var(--g-50);
  border: 1px solid var(--line);
}
.logo-preview img {
  max-height: 72px; max-width: 220px; object-fit: contain;
}
.brand strong { display: block; font-family: var(--display); letter-spacing: 0.02em; }
.brand small { opacity: 0.7; }
.sidebar nav { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }
.sidebar nav a {
  color: var(--g-900);
  padding: 0.75rem 0.9rem;
  border-radius: 4px;
  transition: 0.2s ease;
  font-weight: 500;
  font-size: 0.92rem;
}
.sidebar nav a:hover, .sidebar nav a.active {
  background: var(--g-700);
  color: var(--white);
}
.sidebar-user {
  display: flex; gap: 0.7rem; align-items: center;
  padding: 0.8rem; border-radius: 6px;
  background: var(--g-50);
  border: 1px solid var(--line);
}
.sidebar-user .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--g-400); box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.2);
}
.sidebar-user strong, .sidebar-user small { display: block; }
.sidebar-user small { opacity: 0.65; font-size: 0.8rem; }

.main { padding: 1.4rem 1.6rem 2rem; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}
.topbar h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.5rem, 2vw, 2rem);
  color: var(--g-900);
}
.topbar-actions { display: flex; gap: 0.4rem; }
.lang-switch { display: flex; gap: 0.4rem; padding: 0 0.6rem; flex-wrap: wrap; }
.pref-chips {
  display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center;
}
.pref-sep {
  width: 1px; height: 18px; background: var(--line);
  margin: 0 0.15rem;
  display: inline-block;
}
.sidebar .pref-sep { background: var(--line); }
.topbar-actions .pref-chips { justify-content: flex-end; }

.period-filter {
  display: flex; flex-direction: column; gap: 0.75rem;
  background: rgba(255,255,255,0.88);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
}
.period-filter select { min-width: 220px; }
.period-label {
  font-weight: 600; color: var(--g-900); font-size: 0.92rem;
}
.period-chips {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
}
.period-between {
  display: flex; flex-wrap: wrap; gap: 0.7rem; align-items: end;
  padding-top: 0.35rem;
  border-top: 1px dashed var(--line);
}
.period-hint {
  width: 100%;
  color: var(--muted);
  font-size: 0.82rem;
}
.widget-head {
  display: flex; justify-content: space-between; align-items: start; gap: 0.5rem;
}
.chip { text-decoration: none; color: var(--g-900); }
.settings-tabs {
  display: flex; gap: 0.5rem; flex-wrap: wrap;
  margin-bottom: 0.2rem;
}
.settings-tabs .chip {
  padding: 0.55rem 1rem;
  font-weight: 600;
}
.content { display: flex; flex-direction: column; gap: 1.2rem; }

.grid { display: grid; gap: 1rem; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card {
  background: rgba(255,255,255,0.88);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 500;
}
.card .value {
  font-family: var(--display);
  font-size: 1.8rem;
  color: var(--g-900);
  font-weight: 700;
}
.card .sub { color: var(--muted); font-size: 0.85rem; margin-top: 0.35rem; }

.panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem;
  box-shadow: var(--shadow);
}
.panel h2 {
  margin: 0 0 1rem;
  font-family: var(--display);
  color: var(--g-900);
  font-size: 1.15rem;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border: 0; border-radius: 4px; padding: 0.7rem 1.15rem;
  background: var(--g-700); color: var(--white); cursor: pointer;
  font-weight: 600; letter-spacing: 0.02em; transition: 0.15s ease;
}
.btn:hover { background: #007a3a; }
.btn-ghost {
  background: transparent; color: var(--g-900);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: var(--g-50); }
.btn-danger { background: var(--g-950); }
.btn-danger:hover { background: #1a1716; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.85rem; border-radius: 4px; }

.table-wrap { overflow-x: auto; overflow-y: visible; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.75rem 0.6rem; text-align: right; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
tr:hover td { background: var(--g-50); }

/* Columns hug content — no stretched empty gaps */
table.table-fit {
  width: max-content;
  max-width: 100%;
  table-layout: auto;
}
table.table-fit th,
table.table-fit td {
  width: 1%;
  white-space: nowrap;
  padding-inline: 0.75rem 1.35rem;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}
.panel-head h2 { margin: 0; }

.auth-page {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: #f6f6f6;
}
.auth-card {
  width: min(420px, 100%);
  background: var(--white);
  border-radius: 8px;
  padding: 2rem 1.6rem;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.auth-card .logo {
  width: 56px; height: 56px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--g-700); color: var(--white);
  font-family: var(--display); font-weight: 700; font-size: 1.4rem;
  margin-bottom: 1rem;
}
.auth-card h1 {
  margin: 0 0 0.3rem;
  font-family: var(--display);
  color: var(--g-950);
}
.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 1rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--g-900);
}
.check-inline input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--g-700);
  cursor: pointer;
  flex-shrink: 0;
}
.form-group { margin-bottom: 0.9rem; }
.form-group label { display: block; margin-bottom: 0.35rem; font-weight: 600; color: var(--g-900); }
.form-group input, .form-group select {
  width: 100%; padding: 0.75rem 0.9rem;
  border: 1px solid var(--line); border-radius: 12px; background: var(--g-50);
}
.form-group input:focus, .form-group select:focus { outline: 2px solid rgba(0, 156, 73, 0.28); border-color: var(--g-700); }

/* Whole date field is clickable — not only the calendar icon */
input[type="date"],
input[type="datetime-local"],
input[type="month"],
input[type="week"],
input[type="time"],
.date-input-fullclick {
  cursor: pointer;
  position: relative;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator,
input[type="week"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.error {
  background: #111; color: #fff; padding: 0.7rem 0.9rem; border-radius: 12px; margin-bottom: 1rem;
}
.success {
  background: var(--g-100); color: var(--g-900); padding: 0.7rem 0.9rem; border-radius: 12px; margin-bottom: 1rem;
}

.widget { position: relative; }
.widget-tools {
  display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.chip {
  border: 1px solid var(--line); background: var(--white);
  color: var(--g-900);
  border-radius: 4px; padding: 0.35rem 0.75rem; cursor: pointer; font-size: 0.85rem;
  font-weight: 500;
}
.chip.on { background: var(--g-700); color: var(--white); border-color: var(--g-700); }

.sidebar .pref-chips .chip,
.sidebar .chip {
  background: transparent !important;
  color: var(--g-900) !important;
  border: 1px solid var(--line) !important;
}
.sidebar .pref-chips .chip:hover,
.sidebar .chip:hover {
  background: var(--g-50) !important;
  color: var(--g-900) !important;
}
.sidebar .pref-chips .chip.on,
.sidebar .chip.on {
  background: var(--g-700) !important;
  color: #fff !important;
  border-color: var(--g-700) !important;
  font-weight: 600;
}
.auth-page .chip {
  background: #fff;
  color: var(--g-900);
  border-color: var(--line);
}
.auth-page .chip.on {
  background: var(--g-700);
  color: #fff;
  border-color: var(--g-700);
}
.topbar-actions .chip {
  color: var(--g-900);
}
.topbar-actions .chip.on {
  color: var(--white);
}
.auth-page .chip {
  background: #fff;
  color: var(--g-900);
  border-color: var(--line);
}
.auth-page .chip.on {
  background: var(--g-700);
  color: #fff;
  border-color: var(--g-700);
}

/* All bars start on one line, after the longest name */
.bar-chart {
  display: grid;
  grid-template-columns: max-content minmax(48px, 1fr) auto;
  column-gap: 0.7rem;
  row-gap: 0.55rem;
  align-items: center;
}
.bar-chart .bar-row { display: contents; }
.bar-row { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.55rem; }
.bar-row .label,
.bar-chart .label {
  width: auto; font-size: 0.85rem; white-space: nowrap;
  display: flex; align-items: center; gap: 0.45rem;
}
.bar-row .label-text { overflow: visible; text-overflow: unset; }
.bar-track { flex: 1; min-width: 48px; height: 10px; background: var(--g-100); border-radius: 999px; overflow: hidden; }
.bar-chart .bar-track { width: 100%; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--g-700), var(--g-400)); }
.bar-row .num { width: 48px; text-align: end; font-weight: 700; color: var(--g-800); }
.bar-chart .num { width: auto; min-width: 1.5rem; }

.user-avatar-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  vertical-align: middle;
  overflow: visible;
}
.user-avatar-wrap.user-avatar-md { width: 40px; height: 40px; }
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  background: var(--g-100);
  border: 1px solid var(--line);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  transform-origin: center center;
  position: relative;
}
.user-avatar-md .user-avatar { width: 40px; height: 40px; }
.user-avatar-default {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--g-700);
  background: linear-gradient(145deg, #e8eef5, #d5dde8);
}
.user-avatar-wrap:hover { z-index: 40; }
.user-avatar-wrap:hover .user-avatar {
  transform: scale(2.35);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.28);
  border-color: rgba(255,255,255,0.9);
}
.panel:has(.user-avatar-wrap:hover) { overflow: visible; z-index: 2; }
.table-wrap td .user-avatar-wrap { margin-inline-end: 0.45rem; }
.name-with-avatar {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}
.avatar-preview { display: flex; align-items: center; gap: 0.85rem; margin-bottom: 0.7rem; }

.calendar {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.35rem;
}
.calendar .day {
  aspect-ratio: 1; border-radius: 10px; display: grid; place-items: center;
  font-size: 0.8rem; background: var(--g-50); color: var(--muted);
}
.calendar .day.present { background: var(--g-700); color: var(--white); font-weight: 700; }
.calendar .day.today { outline: 2px solid var(--g-500); }

.password-cell { font-family: ui-monospace, monospace; background: var(--g-50); padding: 0.25rem 0.45rem; border-radius: 8px; }
.secret-line { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.secret-field { position: relative; display: flex; align-items: center; }
.secret-field input { width: 100%; padding-inline-end: 2.6rem; }
.eye-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; padding: 0; margin: 0;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--g-900); cursor: pointer;
}
.eye-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.secret-field .eye-btn { position: absolute; inset-inline-end: 4px; }
.eye-btn[aria-pressed="true"] { background: var(--g-50); color: var(--g-700); }

/* Mobile chrome (hidden on desktop) */
.mobile-bar,
.sidebar-mobile-head,
.nav-overlay,
.nav-close { display: none; }
.sidebar-brand-desktop { display: flex; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  body.nav-lock { overflow: hidden; }

  .app-shell { grid-template-columns: 1fr; min-height: 100dvh; }

  .nav-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(4, 22, 15, 0.45);
    z-index: 80;
    backdrop-filter: blur(2px);
  }
  .nav-overlay[hidden] { display: none !important; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    height: 100dvh;
    z-index: 90;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    padding: 1rem 0.85rem 1.2rem;
    gap: 1rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 12px 0 40px rgba(0,0,0,0.25);
  }
  html[dir="rtl"] .sidebar {
    inset: 0 0 0 auto;
    transform: translateX(105%);
    box-shadow: -12px 0 40px rgba(0,0,0,0.25);
  }
  .app-shell.nav-open .sidebar { transform: translateX(0); }

  .sidebar-brand-desktop { display: none; }
  .sidebar-mobile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }
  .sidebar-mobile-head .brand { flex: 1; min-width: 0; }
  .nav-close {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 12px;
    background: var(--g-50);
    color: var(--g-900);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
  }

  .sidebar .lang-switch { display: none; }

  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 0.15rem 0.85rem;
    margin: 0 0 0.35rem;
    position: sticky;
    top: 0;
    z-index: 40;
    background: linear-gradient(180deg, rgba(247,251,248,0.96), rgba(247,251,248,0.88));
    backdrop-filter: blur(8px);
  }
  .nav-toggle {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    flex-shrink: 0;
  }
  .nav-toggle span {
    display: block;
    height: 2px;
    width: 100%;
    background: var(--g-900);
    border-radius: 2px;
  }
  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
    color: inherit;
    text-decoration: none;
    flex: 1;
  }
  .mobile-brand img {
    height: 30px;
    width: auto;
    max-width: 84px;
    object-fit: contain;
    background: #fff;
    border-radius: 8px;
    padding: 3px 5px;
  }
  .mobile-brand .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }
  .mobile-brand strong {
    font-family: var(--display);
    font-size: 0.95rem;
    color: var(--g-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mobile-prefs {
    display: flex;
    flex-shrink: 0;
    max-width: 46%;
  }
  .mobile-prefs .pref-chips {
    justify-content: flex-end;
  }
  .mobile-prefs .chip {
    padding: 0.3rem 0.55rem;
    font-size: 0.75rem;
  }
  .mobile-prefs .pref-sep { display: none; }
  /* On very small screens keep only language + active tz via wrapping */
  .topbar-actions-desktop { display: none !important; }

  .main {
    padding: 0.55rem 0.85rem 1.6rem;
    padding-bottom: calc(1.6rem + env(safe-area-inset-bottom, 0px));
  }
  .topbar {
    margin-bottom: 0.85rem;
    align-items: flex-start;
  }
  .topbar h1 {
    font-size: 1.35rem;
    line-height: 1.25;
  }

  .grid-4, .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 0.85rem; }
  .card, .panel { padding: 1rem; border-radius: 16px; }
  .card .value { font-size: 1.55rem; }

  .period-filter { padding: 0.8rem; }
  .period-chips .chip { padding: 0.45rem 0.7rem; }
  .period-between { flex-direction: column; align-items: stretch; }
  .period-between .form-group { width: 100%; }
  .period-between input[type="date"],
  .period-between select { width: 100%; min-height: 46px; }
  .period-filter select { min-width: 0; width: 100%; }

  .table-wrap {
    margin: 0 -0.15rem;
    border-radius: 12px;
    -webkit-overflow-scrolling: touch;
  }
  table { font-size: 0.9rem; }
  th, td { padding: 0.7rem 0.55rem; white-space: nowrap; }

  .settings-tabs { gap: 0.4rem; }
  .settings-tabs .chip { flex: 1 1 auto; text-align: center; }

  .bar-chart { column-gap: 0.45rem; }
  .bar-row { gap: 0.45rem; }

  .btn, .btn-sm { min-height: 42px; }
  .form-group input, .form-group select {
    min-height: 46px;
    font-size: 16px; /* prevent iOS zoom */
  }

  .auth-page { padding: 1rem; align-items: flex-start; padding-top: 8vh; }
  .auth-card {
    width: 100%;
    max-width: 440px;
    padding: 1.25rem;
    border-radius: 18px;
  }
  .auth-card h1 { font-size: 1.55rem; }

  .user-avatar-wrap:hover .user-avatar { transform: none; box-shadow: none; }
  .user-avatar-wrap:active .user-avatar {
    transform: scale(1.8);
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.28);
  }
}

@media (max-width: 420px) {
  .mobile-prefs .chip[title] { display: none; }
  .mobile-prefs .chip.on[title],
  .mobile-prefs a.chip[href*="tz="] {
    /* keep active tz visible: show only on chips that are .on among tz */
  }
  .mobile-prefs a.chip[href*="tz=cairo"]:not(.on),
  .mobile-prefs a.chip[href*="tz=riyadh"]:not(.on) {
    display: none;
  }
  .calendar { gap: 0.25rem; }
  .calendar .day { font-size: 0.72rem; border-radius: 8px; }
}
