  @import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@500;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

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

  :root {
    --bg: #F5F6F8;
    --bg-night: #0F1F3D;
    --bg-night-light: #16294D;
    --card: #F5F6F8;
    --card-white: #FFFFFF;
    --accent: #E8A020;
    --entry-color: #2E6B4F;
    --exit-color: #7A8FA6;
    --incident-color: #B3402D;
    --text-dark: #22293A;
    --text-light: #FFFFFF;
    --text-muted: #9AA4B8;
    --text-soft: rgba(34,41,58,0.62);
    --border: #2A3B5F;
    --border-light: #DDE1E8;
  }

  /* ===== NIGHT MODE (manual toggle, remembered per device) =====
     Softer, low-glare palette for overnight use after a long shift —
     no pure white, no pure black, warm amber accent kept as-is since
     warm tones cause less eye strain in the dark than cool ones. */
  body.night-mode {
    --bg: #12161f;
    --card: #1a1f2b;
    --card-white: #1c222f;
    --text-dark: #E4E7EE;
    --text-light: #12161f;
    --text-muted: #8791A3;
    --text-soft: rgba(228,231,238,0.66);
    --border: #3A4457;
    --border-light: #2C3342;
  }

  html { font-size: 16px; }

  body {
    background: var(--bg);
    font-family: 'Inter', sans-serif;
    color: var(--text-dark);
    min-height: 100vh;
    font-size: 1rem;
    line-height: 1.5;
  }

  /* ===== HEADER ===== */
  header {
    background: var(--bg-night);
    color: #fff;
    border-bottom: 1px solid var(--border);
    padding: 1.25rem;
    position: sticky;
    top: 0;
    z-index: 100;
  }

  #mainContent {
    display: none; /* shown only after successful login */
  }

  /* ===== LOGIN SCREEN ===== */
  .login-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 1.5rem;
    min-height: calc(100vh - 90px);
    background:
      radial-gradient(circle at 15% 20%, rgba(232,160,32,0.10), transparent 45%),
      radial-gradient(circle at 85% 80%, rgba(15,31,61,0.06), transparent 45%);
  }

  .login-box {
    background: var(--card-white);
    border: 1px solid var(--border-light);
    border-radius: 18px;
    padding: 2.25rem 2rem 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 12px 40px rgba(15,31,61,0.12);
    text-align: center;
  }

  .login-icon {
    width: 52px;
    height: 52px;
    margin: 0 auto 1.1rem;
    border-radius: 50%;
    background: var(--bg-night);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .login-title {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-dark);
    margin-bottom: 0.35rem;
  }

  .login-box .field { text-align: left; }

  .login-subtitle {
    font-size: 0.8rem;
    color: var(--text-soft);
    margin: 0 0 1.5rem;
    text-align: center;
  }

  .field {
    margin-bottom: 1rem;
  }

  .login-box label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-soft);
    margin-bottom: 0.35rem;
  }

  .login-box input {
    width: 100%;
    padding: 0.65rem 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--border-light);
    background: var(--card-white);
    color: var(--text-dark);
    font-size: 0.95rem;
  }

  .login-box input:focus {
    outline: none;
    border-color: var(--accent);
  }

  .password-wrap {
    position: relative;
  }

  .password-wrap input {
    padding-right: 2.6rem;
  }

  .password-toggle {
    position: absolute;
    top: 50%;
    right: 0.55rem;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 0.3rem;
    margin: 0;
    width: auto;
    height: auto;
    color: var(--text-soft);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: color 0.15s;
  }

  .password-toggle:hover {
    color: var(--accent);
  }

  .password-toggle svg {
    display: block;
  }

  .login-error {
    color: var(--incident-color);
    font-size: 0.8rem;
    margin-top: 0.6rem;
    min-height: 1rem;
  }

  .login-btn {
    width: 100%;
    margin-top: 0.5rem;
    justify-content: center;
  }

  .header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
  }

  .logo-text h1 {
    font-family: 'Georgia', serif;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.02em;
  }

  .logo-text p {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .lang-switch {
    display: flex;
    background: var(--bg-night-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
  }

  .logout-btn {
    display: none; /* shown only after successful login */
    align-items: center;
    justify-content: center;
    background: var(--bg-night-light);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    width: 34px;
    height: 34px;
    font-size: 1.05rem;
    cursor: pointer;
    flex-shrink: 0;
  }

  .logout-btn:hover {
    color: var(--incident-color);
    border-color: var(--incident-color);
  }

  .theme-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-night-light);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    width: 34px;
    height: 34px;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s ease, border-color 0.15s ease;
  }

  .theme-toggle-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
  }

  /* ===== HAMBURGER BUTTON (mobile & tablet nav) ===== */
  .hamburger-btn {
    display: none; /* shown via body.app-authenticated below 1024px */
    align-items: center;
    justify-content: center;
    background: var(--bg-night-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    transition: background-color 0.15s ease, border-color 0.15s ease;
  }
  .hamburger-btn:hover {
    background: var(--bg-night);
    border-color: var(--accent);
  }

  @media (max-width: 1023px) {
    body.app-authenticated .hamburger-btn { display: flex; }
  }

  .hamburger-icon {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 20px;
    height: 16px;
  }
  .hamburger-icon span {
    display: block;
    height: 2px;
    width: 100%;
    background: var(--text-light);
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }
  .hamburger-btn.is-open .hamburger-icon span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
  }
  .hamburger-btn.is-open .hamburger-icon span:nth-child(2) { opacity: 0; }
  .hamburger-btn.is-open .hamburger-icon span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
  }

  /* ===== MOBILE NAV DRAWER ===== */
  .mobile-nav-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15,31,61,0.45);
    z-index: 400;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .mobile-nav-overlay.show {
    display: block;
    opacity: 1;
    pointer-events: all;
  }

  .mobile-nav-drawer {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--card-white);
    z-index: 500;
    padding: 5.5rem 1rem 1.25rem;
    transform: translateY(-100%);
    transition: transform 0.25s ease;
    box-shadow: 0 12px 30px rgba(15,31,61,0.25);
    max-height: 100vh;
    overflow-y: auto;
  }

  @media (max-width: 1023px) {
    body.app-authenticated .mobile-nav-drawer { display: block; }
  }

  .mobile-nav-drawer.open {
    transform: translateY(0);
  }

  .mobile-nav-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    background: transparent;
    border: none;
    border-radius: 10px;
    padding: 0.95rem 1rem;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    color: var(--text-dark);
    cursor: pointer;
    text-align: left;
    min-height: 48px;
  }
  .mobile-nav-item .tab-icon { font-size: 1.3rem; }
  .mobile-nav-item:hover { background: var(--card); }
  .mobile-nav-item.active {
    background: rgba(232,160,32,0.15);
    color: var(--text-dark);
  }
  .mobile-nav-item + .mobile-nav-item { margin-top: 0.25rem; }

  .header-right {
    display: flex;
    align-items: center;
    gap: 0.85rem;
  }

  .live-clock {
    text-align: right;
    flex-shrink: 0;
    line-height: 1.3;
  }

  .clock-time {
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
  }

  .clock-date {
    font-size: 0.68rem;
    color: var(--text-muted);
    letter-spacing: 0.03em;
    white-space: nowrap;
  }

  .lang-btn {
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
  }

  .lang-btn.active {
    background: var(--accent);
    color: var(--bg-night);
  }

  .lang-btn:hover:not(.active) {
    background: var(--bg-night-light);
    color: #fff;
  }

  /* ===== TABS (desktop / large tablet only — see hamburger nav above) ===== */
  .tabs {
    display: none;
    gap: 0.5rem;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--border-light);
  }

  body.app-authenticated .tabs {
    display: flex;
  }

  @media (max-width: 1023px) {
    body.app-authenticated .tabs { display: none; }
  }

  .tab {
    flex: 1;
    min-width: 0;
    padding: 0.85rem 0.5rem;
    text-align: center;
    background: transparent;
    border: none;
    border-radius: 8px 8px 0 0;
    border-bottom: 3px solid transparent;
    color: var(--text-soft);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
  }

  .tab span:last-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .tab .tab-icon { font-size: 1.3rem; }

  .tab.active {
    color: var(--text-dark);
    border-bottom-color: var(--accent);
  }

  .tab:hover:not(.active) {
    color: var(--text-dark);
    background: var(--card);
  }

  /* ===== MAIN CONTAINER ===== */
  main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
  }

  .panel { display: none; }
  .panel.active { display: block; animation: fadeIn 0.3s ease; }

  @keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .panel-header {
    margin-bottom: 1.5rem;
  }

  .panel-header h2 {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 1.6rem;
    font-weight: 800;
    margin-bottom: 0.25rem;
  }

  .panel-header p {
    color: var(--text-soft);
    font-size: 0.95rem;
  }

  .panel-note {
    font-size: 0.85rem !important;
    font-style: italic;
    margin-top: 0.25rem;
    opacity: 0.8;
  }

  /* ===== CARDS ===== */
  .card {
    background: var(--card-white);
    border: 1px solid var(--border-light);
    border-radius: 14px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 10px rgba(15,31,61,0.05);
  }

  .card-title {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  /* ===== FORM ELEMENTS ===== */
  .form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.85rem;
    margin-bottom: 0.85rem;
  }

  .form-row > div {
    min-width: 0;
  }

  .form-row.two-col {
    grid-template-columns: 1fr 1fr;
  }

  .form-row.two-col label {
    min-height: 2.3rem;
  }

  @media (max-width: 540px) {
    .form-row.two-col { grid-template-columns: 1fr; }
    .form-row.two-col label { min-height: 0; }
  }

  label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    color: var(--text-soft);
  }

  input, select, textarea {
    width: 100%;
    background: var(--card-white);
    border: 1.5px solid var(--border-light);
    border-radius: 8px;
    padding: 0.7rem 0.85rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text-dark);
    outline: none;
    transition: border-color 0.2s;
  }

  input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
  }

  textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.6;
  }

  /* ===== CUSTOM DATE PICKER ===== */
  .datepicker-field {
    position: relative;
  }

  .datepicker-trigger {
    width: 100%;
    text-align: left;
    background: var(--card-white);
    border: 1.5px solid var(--border-light);
    border-radius: 8px;
    padding: 0.7rem 0.85rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text-dark);
    cursor: pointer;
    transition: border-color 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .datepicker-trigger:hover,
  .datepicker-trigger:focus {
    border-color: var(--accent);
    outline: none;
  }

  .datepicker-popover {
    position: absolute;
    z-index: 3000;
    background: var(--card-white);
    border: 1px solid var(--border-light);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(15,31,61,0.22);
    padding: 0.85rem;
    width: 300px;
    max-width: calc(100vw - 1.5rem);
  }

  .dp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
  }

  .dp-month-label {
    font-weight: 700;
    font-size: 0.95rem;
    text-transform: capitalize;
  }

  .dp-label-group {
    display: flex;
    gap: 0.35rem;
  }

  .dp-label-btn {
    background: transparent;
    border: none;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.95rem;
    text-transform: capitalize;
    color: var(--text-dark);
    cursor: pointer;
    padding: 0.25rem 0.4rem;
    border-radius: 6px;
  }
  .dp-label-btn:hover { background: var(--border-light); }

  .dp-grid.dp-grid-alt {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.4rem;
    padding: 0.25rem 0;
  }

  .dp-grid-cell {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0.75rem 0.25rem;
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text-dark);
    cursor: pointer;
    min-height: 44px;
    min-width: 0;
    text-transform: capitalize;
  }
  .dp-grid-cell:hover { background: var(--border-light); }
  .dp-grid-cell-selected {
    background: var(--bg-night);
    color: #fff;
    font-weight: 700;
  }

  .dp-nav {
    background: var(--card);
    border: none;
    border-radius: 8px;
    width: 34px;
    height: 34px;
    font-size: 1.2rem;
    line-height: 1;
    color: var(--text-dark);
    cursor: pointer;
  }
  .dp-nav:hover { background: var(--border-light); }

  .dp-weekdays, .dp-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .dp-weekdays {
    margin-bottom: 0.25rem;
  }

  .dp-weekdays div {
    text-align: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-soft);
    text-transform: uppercase;
    padding: 0.25rem 0;
  }

  .dp-day {
    position: relative;
    text-align: center;
    padding: 0.55rem 0;
    font-size: 0.9rem;
    min-width: 0;
    border-radius: 8px;
    cursor: pointer;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .dp-day:not(.dp-day-empty):hover { background: var(--border-light); }
  .dp-day-empty { cursor: default; }
  .dp-day-today { font-weight: 700; }
  .dp-day-today::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--accent);
  }
  .dp-day-selected {
    background: var(--bg-night);
    color: #fff;
    font-weight: 700;
  }

  .dp-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 0.6rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border-light);
  }

  .dp-footer-btn {
    background: transparent;
    border: none;
    color: var(--text-dark);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.3rem 0.5rem;
  }
  .dp-footer-btn:hover { color: var(--accent); }
  .dp-clear { color: var(--incident-color); }

  /* ===== BUTTONS ===== */
  .btn {
    border: none;
    border-radius: 999px;
    padding: 0.6rem 1.15rem;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    box-shadow: 0 1px 2px rgba(15,31,61,0.08);
  }
  .btn:active { transform: translateY(0) scale(0.97); }
  .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(15,31,61,0.14);
    filter: brightness(1.04);
  }

  .icon-svg {
    flex-shrink: 0;
    display: inline-block;
    vertical-align: middle;
  }

  .btn-spinner {
    display: none;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: btn-spin 0.7s linear infinite;
  }
  .btn.is-loading .btn-spinner { display: inline-block; }
  .btn.is-loading { opacity: 0.7; pointer-events: none; }
  .btn-accent .btn-spinner,
  .btn-outline .btn-spinner {
    border-color: rgba(15,31,61,0.3);
    border-top-color: var(--bg-night);
  }
  @keyframes btn-spin { to { transform: rotate(360deg); } }

  .btn-entry { background: var(--entry-color); color: #fff; }
  .btn-exit { background: var(--exit-color); color: #fff; }
  .btn-accent { background: var(--accent); color: var(--bg-night); }
  .btn-primary { background: var(--bg-night); color: #fff; }
  .btn-incident { background: var(--incident-color); color: #fff; }
  .btn-outline {
    background: transparent;
    border: 1.25px solid var(--text-dark);
    color: var(--text-dark);
    box-shadow: none;
  }
  .btn-outline:hover { border-color: var(--accent); color: var(--accent); }

  .btn-text-danger {
    background: transparent;
    border: none;
    color: var(--text-soft);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    transition: color 0.2s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-direction: row-reverse;
  }
  .btn-text-danger:hover { color: var(--incident-color); }

  .btn-full { width: 100%; justify-content: center; }

  .btn-group {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
  }

  /* ===== LOG TABLE ===== */
  .log-table-wrap {
    overflow-x: auto;
    border-radius: 10px;
    border: 1px solid var(--border-light);
  }

  table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    background: var(--card-white);
  }

  th, td {
    padding: 0.65rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
  }

  th {
    color: var(--text-soft);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
  }

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

  @media (max-width: 700px) {
    .log-table-wrap table, .log-table-wrap thead, .log-table-wrap tbody,
    .log-table-wrap th, .log-table-wrap td, .log-table-wrap tr {
      display: block;
    }
    .log-table-wrap thead { display: none; }
    .log-table-wrap tr {
      border: 1px solid var(--border-light);
      border-radius: 10px;
      margin: 0.6rem;
      padding: 0.4rem 0.75rem;
    }
    .log-table-wrap tr:first-child { margin-top: 0.6rem; }
    .log-table-wrap td {
      border: none;
      padding: 0.4rem 0;
      white-space: normal;
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 0.75rem;
    }
    .log-table-wrap td[data-label]::before {
      content: attr(data-label);
      font-weight: 700;
      color: var(--text-soft);
      font-size: 0.72rem;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      flex-shrink: 0;
    }
    .log-table-wrap td:last-child { justify-content: flex-end; }
  }

  .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    font-size: 0.78rem;
    font-weight: 700;
  }

  .badge-entry { background: rgba(46,107,79,0.15); color: var(--entry-color); }
  .badge-exit { background: rgba(122,143,166,0.2); color: var(--exit-color); }
  body.night-mode .badge-entry { background: rgba(46,107,79,0.35); color: #7FD9A8; }
  body.night-mode .badge-exit { background: rgba(122,143,166,0.28); color: #C3CEDB; }

  .delete-btn {
    background: transparent;
    border: none;
    color: var(--text-soft);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.35rem;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, color 0.15s ease;
  }
  .delete-btn:hover { color: var(--incident-color); background: rgba(179,64,45,0.08); }

  .empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-soft);
  }
  .empty-state .icon { font-size: 2.5rem; margin-bottom: 0.5rem; display: block; }

  /* ===== STAT CARDS (occupancy counters) ===== */
  .stat-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
    margin-bottom: 1rem;
  }
  @media (max-width: 540px) {
    .stat-row { grid-template-columns: 1fr; }
  }
  .stat-card {
    background: var(--card-white);
    border: 1px solid var(--border-light);
    border-radius: 14px;
    padding: 1rem 1.25rem;
    text-align: center;
    box-shadow: 0 2px 10px rgba(15,31,61,0.05);
  }
  .stat-value {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-dark);
    line-height: 1.1;
  }
  .stat-label {
    margin-top: 0.3rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-soft);
  }

  /* ===== OCCUPANTS PANEL ===== */
  .occupant-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }
  .occupant-card {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.75rem;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    transition: background-color 0.15s ease, border-color 0.15s ease;
  }
  .occupant-card:hover {
    background: var(--card);
    border-color: var(--border);
  }
  .occupant-select {
    display: flex;
    align-items: center;
  }
  .occupant-select input { width: auto; }
  .occupant-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
  }
  .occupant-avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--border-light);
    font-size: 1.3rem;
  }
  .occupant-info {
    flex: 1;
    min-width: 0;
  }
  .occupant-name {
    font-weight: 700;
    color: var(--text-dark);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .occupant-meta {
    font-size: 0.8rem;
    color: var(--text-soft);
    margin: 0.15rem 0 0.35rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .occupant-actions {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
  }
  .occupant-photo-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
  }
  .occupant-photo-preview {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
  }
  .occupant-photo-placeholder {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
  }
  .occupant-photo-actions {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
  }

  /* ===== SIGNATURE PAD ===== */
  .sig-wrap {
    background: var(--card-white);
    border: 1.5px solid var(--border-light);
    border-radius: 10px;
    overflow: hidden;
  }

  canvas#sigCanvas, canvas#sigCanvasIncident, canvas#sigCanvasSignInOut {
    display: block;
    width: 100%;
    height: 150px;
    touch-action: none;
    cursor: crosshair;
    background: #fff;
  }

  .sig-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.85rem;
    border-top: 1px solid var(--border-light);
    background: var(--card);
  }

  .sig-controls span {
    font-size: 0.8rem;
    color: var(--text-soft);
    font-style: italic;
  }

  .sig-controls button {
    background: transparent;
    border: none;
    color: var(--text-soft);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    transition: color 0.15s ease;
  }
  .sig-controls button:hover { color: var(--accent); }

  /* ===== TOAST ===== */
  .toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--entry-color);
    color: #fff;
    padding: 0.85rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 6px 20px rgba(15,31,61,0.3);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 1000;
    text-align: center;
    max-width: 90%;
  }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
  .toast.error { background: var(--incident-color); }

  /* ===== CUSTOM CONFIRM MODAL ===== */
  .modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15,31,61,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    padding: 1.25rem;
  }
  .modal-overlay.show {
    opacity: 1;
    pointer-events: all;
  }

  .modal-box {
    background: var(--card-white);
    border-radius: 14px;
    padding: 1.5rem;
    max-width: 380px;
    width: 100%;
    max-height: calc(100vh - 2.5rem);
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(15,31,61,0.25);
    transform: scale(0.95) translateY(10px);
    transition: transform 0.2s ease;
    container-type: inline-size;
    container-name: modal;
  }
  .modal-overlay.show .modal-box {
    transform: scale(1) translateY(0);
  }

  /* A modal is always narrow (max-width: 380px above), regardless of
     screen size — so any two-column row inside one must collapse based
     on the modal's own width, not the viewport's. A plain @media query
     would never fire here on a large screen even though the box itself
     is cramped, so this uses a container query instead. */
  @container modal (max-width: 480px) {
    .form-row.two-col {
      grid-template-columns: 1fr;
    }
    .form-row.two-col label {
      min-height: 0;
    }
  }

  .modal-icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
  }

  .modal-message {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-dark);
    margin-bottom: 1.5rem;
  }

  .modal-buttons {
    display: flex;
    gap: 0.6rem;
    justify-content: flex-end;
  }

  .modal-buttons .btn {
    padding: 0.65rem 1.25rem;
    font-size: 0.9rem;
  }

  /* ===== PRINTABLE FORM PREVIEW (hidden, used for blank forms) ===== */
  .hidden { display: none !important; }

  .helper-text {
    font-size: 0.8rem;
    color: var(--text-soft);
    margin-top: 0.4rem;
    line-height: 1.5;
  }

  .section-divider {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 1.25rem 0;
  }

  .client-group {
    border: 1px solid var(--border-light);
    border-radius: 10px;
    margin-bottom: 0.75rem;
    overflow: hidden;
  }

  .client-group-header {
    background: rgba(15,31,61,0.06);
    padding: 0.7rem 0.85rem;
    font-weight: 700;
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
  }

  .client-group-header .title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  .client-group-header .actions {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
  }

  .client-group-header .count {
    font-size: 0.75rem;
    color: var(--text-soft);
    font-weight: 500;
  }

  .client-group-body {
    display: flex;
    flex-direction: row;
  }

  .client-group-table {
    flex: 1.4;
    min-width: 0;
    overflow-x: auto;
  }

  .client-group-note {
    flex: 1;
    min-width: 0;
    border-left: 1px solid var(--border-light);
    padding: 0.6rem;
  }

  .client-note-input {
    width: 100%;
    height: 100%;
    min-height: 70px;
    border: none;
    background: transparent;
    color: var(--text-dark);
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
    padding: 0.3rem;
  }

  .client-note-input:focus {
    outline: 1px solid var(--accent);
    border-radius: 4px;
  }

  .client-note-input::placeholder {
    color: var(--text-soft);
    font-style: italic;
  }

  @media (max-width: 540px) {
    .client-group-body { flex-direction: column; }
    .client-group-note {
      border-left: none;
      border-top: 1px solid var(--border-light);
    }
  }

  /* ===== GLOBAL RESPONSIVE SAFEGUARDS ===== */
  html, body {
    overflow-x: hidden;
    width: 100%;
  }

  img, canvas, svg, video {
    max-width: 100%;
  }

  /* Comfortable touch targets on touch-sized screens (phones & tablets) */
  @media (max-width: 1023px) {
    .btn {
      min-height: 44px;
    }
    .delete-btn {
      min-width: 40px;
      min-height: 40px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 1.1rem;
    }
    .lang-btn {
      padding: 0.6rem 0.9rem;
    }
    .logout-btn, .hamburger-btn, .theme-toggle-btn {
      width: 44px;
      height: 44px;
    }
    .occupant-select input,
    .occupant-select {
      width: 24px;
      height: 24px;
      transform: scale(1.3);
    }
    input, select, textarea, .datepicker-trigger {
      font-size: 1rem; /* prevents iOS Safari from auto-zooming on focus */
    }
  }

  /* Slightly larger base text on very small phones for readability without zoom */
  @media (max-width: 390px) {
    .panel-header h2 { font-size: 1.4rem; }
    .stat-value { font-size: 1.7rem; }
    .card { padding: 1rem; }
    main { padding: 1.25rem 0.85rem 3rem; }
  }

  /* The header packs a lot in (clock, language, night mode, logout) —
     on narrow phones this wraps to a second line, and French text
     (slightly longer than English) tips it over first. Dropping the
     date and tightening the gaps keeps everything on one line in
     either language. */
  @media (max-width: 600px) {
    .header-right { gap: 0.5rem; }
    .clock-date { display: none; }
    .live-clock { text-align: center; }
    .header-top { gap: 0.5rem; }
  }

  /* Landscape phones/tablets: keep the login box and modals from feeling
     cramped against the reduced vertical space. */
  @media (max-height: 480px) and (orientation: landscape) {
    .login-overlay { padding: 1.25rem 1.5rem; align-items: flex-start; }
    .modal-box { max-height: calc(100vh - 1.5rem); }
  }
