
  /* IoTCASA theme: charcoal (#1E1E1E, from iotcasa.ai) + brushed gold accent.
     Change these variables to re-colour the whole app. */
  :root {
    --ink: #1E1E1E;
    --ink-2: #2a2a2a;
    --ink-3: #3a3a3a;
    --gold: #C9A646;
    --gold-2: #E3C878;
    --gold-soft: #f6efdc;
    --bg: #f5f4f0;
    --card: #ffffff;
    --line: #e7e3da;
    --text: #1f1f1f;
    --muted: #6d6a64;
    --ok: #2e7d4f;
    --ok-bg: #e5f3ea;
    --warn: #a86a12;
    --warn-bg: #fbf0dc;
    --bad: #b3261e;
    --bad-bg: #fbe5e3;
    --info: #2b5f8a;
    --info-bg: #e3eef7;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; }
  body { font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
  a { color: #8a6c1f; }
  .hidden { display: none !important; }
  .muted { color: var(--muted); }
  .small { font-size: 12px; }
  .logo { font-weight: 700; letter-spacing: 4px; color: var(--gold); }
  .logo.big { font-size: 28px; text-align: center; }

  /* Splash, busy, toast */
  .splash { position: fixed; inset: 0; background: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; z-index: 50; }
  .splash .logo { font-size: 30px; }
  .splash-msg { color: #ddd; max-width: 520px; padding: 0 16px; font-size: 14px; line-height: 1.5; }
  .splash-msg ul { padding-left: 18px; }
  .splash-msg code { color: var(--gold-2); }
  .splash-msg .btn { margin-top: 12px; }
  .splash-detail { margin-top: 10px; padding: 8px 10px; background: #2a2a2a; border-radius: 8px; color: #f3b3ad; font-family: monospace; font-size: 12px; word-break: break-word; }
  .links-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
  .link-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fff; display: flex; flex-direction: column; gap: 4px; }
  .link-card a.t { font-weight: 600; text-decoration: none; color: var(--ink); word-break: break-word; }
  .link-card a.t:hover { color: #8a6c1f; }
  .link-card .u { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .spinner { width: 28px; height: 28px; border: 3px solid rgba(201,166,70,.25); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }
  .busy { position: fixed; right: 16px; bottom: 16px; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; display: flex; gap: 10px; align-items: center; z-index: 40; box-shadow: var(--shadow); }
  .busy .spinner { width: 18px; height: 18px; border-width: 2px; }
  .toast { visibility: hidden; position: fixed; left: 50%; top: 16px; transform: translateX(-50%) translateY(-120%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; transition: transform .25s; max-width: 92vw; box-shadow: var(--shadow); }
  .toast.show { visibility: visible; transform: translateX(-50%) translateY(0); }
  .toast.bad { background: var(--bad); }
  .toast.ok { background: var(--ok); }

  /* Login */
  .login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 30% 20%, #333 0, var(--ink) 60%); padding: 16px; }
  .login-card { background: var(--card); width: 100%; max-width: 360px; padding: 28px 24px; border-radius: 16px; box-shadow: 0 10px 40px rgba(0,0,0,.35); display: flex; flex-direction: column; gap: 12px; }
  .login-card p { text-align: center; margin: 0; }

  /* Shell */
  #app { display: flex; min-height: 100vh; }
  #nav { width: 236px; background: var(--ink); color: #ddd; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; z-index: 30; }
  .brand { padding: 20px 18px 14px; display: flex; flex-direction: column; gap: 2px; border-bottom: 1px solid var(--ink-3); }
  .brand .logo { font-size: 18px; }
  .brand .tag { font-size: 11px; color: #999; letter-spacing: 1px; text-transform: uppercase; }
  #navLinks { flex: 1; overflow-y: auto; padding: 8px; }
  #navLinks a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; color: #cfcfcf; text-decoration: none; border-radius: 8px; margin-bottom: 2px; font-weight: 500; }
  #navLinks a .ic { width: 18px; text-align: center; color: var(--gold); }
  #navLinks a:hover { background: var(--ink-2); color: #fff; }
  #navLinks a.active { background: var(--gold); color: var(--ink); }
  #navLinks a.active .ic { color: var(--ink); }
  #navLinks .sep { font-size: 10px; text-transform: uppercase; letter-spacing: 1.5px; color: #777; padding: 12px 12px 4px; }
  .me { padding: 14px 18px; border-top: 1px solid var(--ink-3); display: flex; flex-direction: column; gap: 6px; }
  .me #meName { color: #fff; font-weight: 600; }
  main { flex: 1; min-width: 0; }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
  .topbar h1 { font-size: 18px; margin: 0; flex: 1; }
  .icon-btn { display: none; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--ink); }
  #scrim { display: none; }
  .view { padding: 20px 24px 60px; max-width: 1280px; }

  @media (max-width: 860px) {
    #nav { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; }
    #nav.open { transform: translateX(0); }
    #scrim.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 25; }
    .icon-btn { display: block; }
    #clock { display: none; }
    .topbar { padding: 12px 16px; }
    .view { padding: 16px 16px 60px; }
  }

  /* Cards & layout */
  .grid { display: grid; gap: 16px; }
  .g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
  @media (max-width: 860px) { .g2, .g3 { grid-template-columns: minmax(0, 1fr); } }
  .card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
  .card h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
  .card h2 .right { margin-left: auto; }
  .kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
  .kpi .v { font-size: 22px; font-weight: 700; }
  .kpi .l { font-size: 12px; color: var(--muted); margin-top: 2px; }
  .kpi.dark { background: var(--ink); color: #fff; border-color: var(--ink); }
  .kpi.dark .v { color: var(--gold); }
  .kpi.dark .l { color: #aaa; }
  .mb { margin-bottom: 16px; }

  /* Forms */
  form.f { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; align-items: end; }
  form.f .full { grid-column: 1 / -1; }
  .fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
  .fld > span { font-size: 12px; color: var(--muted); font-weight: 500; }
  input, select, textarea { font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); width: 100%; min-width: 0; }
  input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-2); border-color: var(--gold); }
  select[multiple] { min-height: 110px; }
  textarea { resize: vertical; }
  .btn { font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--ink); background: var(--ink); color: #fff; cursor: pointer; white-space: nowrap; }
  .btn:hover { background: var(--ink-3); }
  .btn.gold { background: var(--gold); border-color: var(--gold); color: var(--ink); }
  .btn.gold:hover { background: var(--gold-2); }
  .btn.ghost { background: transparent; color: inherit; border-color: var(--line); }
  #nav .btn.ghost { border-color: var(--ink-3); color: #ccc; }
  .btn.small { padding: 4px 10px; font-size: 12px; }
  .btn.ok { background: var(--ok); border-color: var(--ok); }
  .btn.bad { background: var(--bad); border-color: var(--bad); }
  .btn.wide { width: 100%; padding: 12px; }
  .btn:disabled { opacity: .5; cursor: default; }
  .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
  .filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
  .filters .fld { width: 160px; }
  .chips { display: flex; gap: 6px; flex-wrap: wrap; }
  .chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 12px; font-weight: 500; }
  .chip.on { background: var(--ink); color: var(--gold); border-color: var(--ink); }

  /* Tables */
  .tbl { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
  table { border-collapse: collapse; width: 100%; background: #fff; }
  th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
  th { background: #faf8f3; font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
  tr:last-child td { border-bottom: 0; }
  td.num, th.num { text-align: right; white-space: nowrap; }
  td.nowrap { white-space: nowrap; }
  .empty { color: var(--muted); padding: 14px; text-align: center; background: #fff; border: 1px dashed var(--line); border-radius: 10px; margin: 0; }

  /* Badges */
  .badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #eee; color: #444; white-space: nowrap; }
  .b-done, .b-on-time, .b-approved, .b-closed, .b-sent, .b-p { background: var(--ok-bg); color: var(--ok); }
  .b-late, .b-pending, .b-in-progress, .b-open, .b-l { background: var(--warn-bg); color: var(--warn); }
  .b-blocked, .b-rejected, .b-not-checked-in, .b-a, .b-cancelled { background: var(--bad-bg); color: var(--bad); }
  .b-on-leave, .b-planned, .b-active, .b-lv { background: var(--info-bg); color: var(--info); }

  /* Check-in */
  .checkin { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; background: var(--ink); color: #fff; border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
  .checkin .t { font-size: 30px; font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }
  .checkin .s { color: #bbb; font-size: 13px; }
  .checkin .grow { flex: 1; min-width: 180px; }
  .checkin .btn { font-size: 15px; padding: 12px 22px; }

  /* Attendance register */
  .reg td, .reg th { padding: 4px 3px; text-align: center; font-size: 11px; min-width: 26px; }
  .reg td:first-child, .reg th:first-child { text-align: left; position: sticky; left: 0; background: #fff; min-width: 90px; padding-left: 8px; z-index: 1; }
  .reg th:first-child { background: #faf8f3; }
  .cell { display: inline-block; width: 22px; height: 22px; line-height: 22px; border-radius: 5px; font-weight: 700; font-size: 10px; }
  .c-P { background: var(--ok-bg); color: var(--ok); }
  .c-L { background: var(--warn-bg); color: var(--warn); }
  .c-LV { background: var(--info-bg); color: var(--info); }
  .c-A { background: var(--bad-bg); color: var(--bad); }
  .c-off { background: #f0eee9; color: #aaa; }
  .legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 8px 0; align-items: center; }

  /* Bars */
  .bars { display: flex; flex-direction: column; gap: 6px; }
  .bar { display: grid; grid-template-columns: minmax(110px, 38%) 1fr 48px; gap: 8px; align-items: center; font-size: 12px; }
  .bar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bar .trk { background: #f0ece2; border-radius: 4px; height: 10px; overflow: hidden; }
  .bar .fill { background: var(--gold); height: 100%; border-radius: 4px; }
  .bar .n { text-align: right; font-variant-numeric: tabular-nums; }

  /* Scores */
  .score-card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 14px; }
  .score-card .head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
  .score-card .name { font-weight: 700; font-size: 15px; }
  .score-card .pct { margin-left: auto; font-size: 20px; font-weight: 700; color: var(--gold); }
  .stats { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
  .stats span { background: var(--gold-soft); border-radius: 6px; padding: 3px 8px; font-size: 11px; }
  .crit { display: grid; grid-template-columns: 1fr 120px 28px; gap: 8px; align-items: center; font-size: 12px; margin-bottom: 4px; }
  .crit input[type=range] { padding: 0; accent-color: var(--gold); }
  .spark { display: flex; gap: 3px; align-items: flex-end; height: 28px; }
  .spark i { display: block; width: 10px; background: var(--gold-2); border-radius: 2px 2px 0 0; }
  .spark i.na { background: #eee; height: 3px !important; }
  .private { background: var(--ink); color: var(--gold); padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 13px; }

  .list { display: flex; flex-direction: column; gap: 8px; }
  .item { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; display: flex; gap: 10px; align-items: flex-start; }
  .item .grow { flex: 1; min-width: 0; }
  .item .title { font-weight: 600; }
  details.card > summary { cursor: pointer; font-weight: 600; }
  details.card[open] > summary { margin-bottom: 12px; }

  /* ---- website / installed app ---- */
  body { padding-bottom: env(safe-area-inset-bottom); }
  .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
  .g-btn { display: flex; justify-content: center; min-height: 44px; margin: 18px 0 8px; }
  .install-hint { margin-top: 16px; font-size: 12px; color: #8a8a8a; line-height: 1.5; }
  .pwa-btns { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 6px; }
  .pwa-btns .btn { width: 100%; }
  .net-off { background: #b3261e; color: #fff; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; margin-left: auto; margin-right: 8px; }
