/* ==========================================================================
   Tokens & base
   ========================================================================== */
:root {
  color-scheme: dark;
  --bg: #0b131d; --panel: #14212c; --line: #304451; --text: #f3f8f4; --muted: #a3b6c0;
  --mint: #baf0d2; --sun: #f5c88c; --night: #a3b6d5; --lilac: #d9ccff; --danger: #ffaaa6;
  --daylight: #ffd84d; --daylight-slot: #a8902c;
  --radius: 16px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
body.modal-open { overflow: hidden; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 30; background: var(--mint); color: #153326; padding: 8px 12px; border-radius: 8px; font-weight: 800; text-decoration: none; }
.skip:focus { top: 12px; }
.wrap { max-width: 1400px; margin: auto; padding: 20px clamp(15px, 3vw, 45px) 48px; }
.planner:focus { outline: none; }

/* ==========================================================================
   Header & buttons
   ========================================================================== */
.top, .topactions, .cardhead, .cardfoot, .dialoghead, .dialogactions { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.top { border-bottom: 1px solid var(--line); padding-bottom: 18px; }
.brand { display: flex; align-items: center; font-size: 22px; font-weight: 800; letter-spacing: -1px; white-space: nowrap; }
.brandicon { display: grid; place-items: center; background: var(--mint); color: #153024; width: 34px; height: 34px; border-radius: 11px; margin-right: 10px; font-size: 25px; }
.accent { color: var(--mint); }
.topactions { justify-content: flex-end; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: #1b2d39; color: var(--text); border-radius: 10px; padding: 9px 12px; font-size: 12px; font-weight: 750; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover:not(:disabled) { background: #29404a; }
.btn.primary { background: var(--mint); border-color: var(--mint); color: #153326; }
.btn.primary:hover:not(:disabled) { background: #d2f9e3; }
.btn.attention { border-color: var(--sun); color: var(--sun); }
.btngroup { display: flex; }
.btngroup .btn { border-radius: 0; margin-left: -1px; }
.btngroup .btn:first-child { border-radius: 10px 0 0 10px; margin-left: 0; }
.btngroup .btn:last-child { border-radius: 0 10px 10px 0; }
.btngroup .btn:focus-visible { position: relative; z-index: 1; }

/* ==========================================================================
   Cards
   ========================================================================== */
.places { margin-top: 25px; }
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.card { display: flex; flex-direction: column; background: linear-gradient(145deg, #1c2d39, #14212c); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; transition: border-color .15s; }
.card:hover { border-color: #46606e; }
.card.home { background: linear-gradient(145deg, #28473e, #192d34); border-color: #679e85; }
.card.person { border-color: #5c6587; background: linear-gradient(145deg, #2b3148, #192733); }
.cardhead { align-items: flex-start; }
.cardtitle { min-width: 0; }
.cardname { font-size: 15px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cardsub { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { color: var(--mint); border: 1px solid #7cac9760; border-radius: 20px; padding: 3px 7px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.person .tag { color: var(--lilac); border-color: #9783c260; }
.x { flex-shrink: 0; border: 0; background: #ffffff15; color: var(--text); width: 27px; height: 27px; border-radius: 7px; font-size: 18px; line-height: 1; }
.x:hover { background: #ffffff30; }
.clock { font-size: clamp(24px, 2.4vw, 32px); font-weight: 750; letter-spacing: -1.7px; font-variant-numeric: tabular-nums; white-space: nowrap; margin-top: 8px; line-height: 1.2; }
.carddate { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 11px; color: var(--muted); }
.dayshift { color: var(--sun); font-weight: 750; }
.rel { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 750; color: var(--text); background: #ffffff12; border-radius: 6px; padding: 1px 6px; }
.rel.relhome { color: var(--mint); }
.cardfoot { border-top: 1px solid #ffffff20; margin-top: auto; padding-top: 7px; font-size: 10.5px; flex-wrap: wrap; row-gap: 2px; }
.carddate { margin-bottom: 6px; }
.sun { color: var(--daylight); }
.moon { color: var(--night); }
.inwork { color: var(--mint); }
.offwork { color: var(--muted); }
.sethome { align-self: flex-start; background: none; border: 0; padding: 4px 0 0; color: var(--mint); font-size: 11px; font-weight: 700; }
.sethome:hover { text-decoration: underline; }
.cardbuttons { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.editperson { border: 1px solid #9e8ec580; border-radius: 7px; background: #ffffff12; color: #e3d9ff; padding: 5px 9px; font-size: 11px; font-weight: 750; white-space: nowrap; }
.editperson:hover { background: #7d6c9b55; }
.addcard { align-items: center; justify-content: center; gap: 4px; text-align: center; color: var(--muted); background: transparent; border: 1px dashed #5c6587; }
.addcard:hover { background: #2b314855; color: var(--text); border-color: #8a83b0; }
.addcard strong { color: var(--lilac); font-size: 14px; }
.addcard small { max-width: 220px; font-size: 11px; }
.addplus { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: #9783c230; color: var(--lilac); font-size: 22px; font-weight: 700; margin-bottom: 4px; }

/* ==========================================================================
   Planner & timeline
   ========================================================================== */
.planner { margin-top: 24px; }
.panel, .insight { background: var(--panel); border: 1px solid var(--line); border-radius: 17px; padding: 20px; }
.controls { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; margin: 20px 0; }
.controls label, .dialog form label, .timeset legend { display: flex; flex-direction: column; gap: 5px; font-size: 11px; color: var(--muted); font-weight: 750; }
.controls input, .controls select, .dialog input, .dialog select { height: 39px; border: 1px solid #4a5e68; border-radius: 9px; background: #101c28; color: var(--text); padding: 0 10px; color-scheme: dark; }
.controls .btn { height: 39px; }
.selected { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; margin: 17px 0; }
.selected strong { font-size: 29px; letter-spacing: -1px; font-variant-numeric: tabular-nums; }
.selected span { color: var(--muted); font-size: 12px; }
.timeline-scroll { overflow-x: auto; scrollbar-color: #567368 #162631; }
.timeline { min-width: 760px; }
.timeline-row { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px; align-items: center; margin: 7px 0; }
.axisrow { font-size: 10px; color: var(--muted); font-weight: 750; }
.axis { height: 25px; position: relative; }
.axislabel { position: absolute; white-space: nowrap; transform: translateX(-50%); font-size: 10px; font-variant-numeric: tabular-nums; }
.axislabel:first-child { transform: none; }
.axislabel:last-child { transform: translateX(-100%); }
.rowlabel { font-size: 11px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rowlabel small { display: block; font-size: 10px; color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.track { height: 34px; display: flex; position: relative; border-radius: 7px; overflow: hidden; cursor: pointer; }
.track:hover .slot { filter: brightness(1.08); }
.slot { flex: 1; min-width: 0; background: #263647; border-right: 1px solid #0a121b22; }
.slot.day { background: var(--daylight-slot); }
.slot.work { background: #537c61; }
.slot.work.dark { background: #526778; }
.slot.selectedslot { box-shadow: inset 0 0 0 2px #f8fff3; }
.needle { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #f7fff3; box-shadow: 0 0 10px var(--mint); pointer-events: none; }
#slider { width: 100%; accent-color: var(--mint); cursor: pointer; margin: 8px 0 0; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; color: var(--muted); font-size: 10px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.key { width: 9px; height: 9px; border-radius: 2px; }
.key.work { background: #537c61; }
.key.day { background: var(--daylight-slot); }
.key.night { background: #263647; }
.key.selectedkey { background: #f8fff3; }
.hint { color: var(--muted); font-size: 11px; margin: 14px 0 0; }

/* ==========================================================================
   Insights
   ========================================================================== */
.insights { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; gap: 12px; margin-top: 12px; }
.insight:first-child { background: linear-gradient(145deg, #243f38, #192c32); border-color: #527963; }
.insight-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.insight-head .label { margin: 0; }
.label { color: var(--muted); font-size: 10px; letter-spacing: 1.2px; font-weight: 800; }
.insight strong { display: block; font-size: 25px; margin: 9px 0 2px; }
.insight p { font-size: 11px; color: var(--muted); margin: 0; }
.progress { height: 7px; border-radius: 20px; background: #0e1c25; overflow: hidden; margin: 15px 0 10px; }
.progress div { height: 100%; width: 0; background: var(--mint); transition: width .25s ease; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { border-radius: 20px; padding: 4px 8px; background: #ffffff19; font-size: 10px; }
.suggestions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 13px; }
.suggestion { background: #26413e; color: var(--mint); border: 1px solid #547767; border-radius: 9px; padding: 8px 10px; font-size: 11px; font-weight: 700; }
.suggestion:hover { background: #335549; }
.actions-card { min-width: 0; padding: 20px; background: linear-gradient(145deg, #172b3a, #112231); border: 1px solid var(--line); border-radius: 17px; }
.actions-card h2, .fairness h3 { margin: 0 0 12px; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: 1.4px; }
.actions-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.actions-head h2 { margin: 0; }
#actionsContent:not([hidden]) { margin-top: 12px; }
.action-list { display: grid; gap: 7px; }
.action-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 11px; background: #203748; border: 1px solid #365166; border-radius: 11px; color: var(--text); text-align: left; font-size: 12px; font-weight: 700; }
.action-btn:hover { background: #2b475b; }
.action-btn span { width: 22px; color: #b7d0df; font-size: 21px; line-height: 1; text-align: center; }
.action-help { margin: 10px 0 0; color: var(--muted); font-size: 11px; }
.fairness { margin-top: 14px; padding-top: 12px; border-top: 1px solid #456071; }
.fairness h3 span { cursor: help; font-size: 15px; }
.fairness-switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; font-weight: 700; }
.fairness-switch input { appearance: none; flex: 0 0 38px; width: 38px; height: 22px; margin: 1px 0 0; border: 2px solid #668195; border-radius: 20px; background: #2b4151; position: relative; cursor: pointer; }
.fairness-switch input::before { content: ''; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.fairness-switch input:checked { background: #56856c; border-color: var(--mint); }
.fairness-switch input:checked::before { transform: translateX(16px); }
.fairness-switch input:focus-visible { outline: 2px solid var(--mint); outline-offset: 3px; }
.fairness-switch small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 400; }

/* ==========================================================================
   Dialogs
   ========================================================================== */
.backdrop { position: fixed; inset: 0; z-index: 10; display: none; align-items: center; justify-content: center; padding: 15px; background: #030a12d9; }
.backdrop.open { display: flex; animation: fade .15s ease-out; }
.dialog { width: min(480px, 100%); max-height: 90vh; overflow: auto; background: #1b2b37; border: 1px solid #567368; border-radius: 18px; padding: 22px; box-shadow: 0 30px 80px #0009; }
.backdrop.open .dialog { animation: pop .18s ease-out; }
.dialoghead { align-items: flex-start; margin-bottom: 17px; }
.dialog h2 { margin: 0; font-size: 21px; }
.dialog p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.dialog form { display: grid; gap: 13px; }
.dialog form label { font-size: 12px; }
.dialog input, .dialog select { width: 100%; }
.timeset { border: 0; margin: 0; padding: 0; min-width: 0; }
.timeset legend { padding: 0; font-size: 12px; margin-bottom: 5px; }
.timefields { display: flex; align-items: center; gap: 7px; }
.dialog .timefields select, .dialog .timefields input { width: 85px; }
.schedule, .workdays { min-width: 0; border: 0; padding: 0; margin: 0; }
.schedule { display: grid; gap: 8px; }
.schedule legend, .workdays legend { padding: 0; font-size: 12px; font-weight: 750; margin-bottom: 5px; }
.schedulehours { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.daychecks { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.dialog .daychecks label { display: inline-flex; flex-direction: row; align-items: center; gap: 4px; }
.dialog .daychecks input { width: auto; }
.help { font-size: 11px; color: var(--muted); }
.help.empty { padding: 14px 10px; }
.error { font-size: 12px; color: var(--danger); }
.error:empty { display: none; }
.dialogactions { justify-content: flex-end; }
.choices { max-height: 360px; overflow: auto; margin-top: 12px; }
.choice { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; padding: 10px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; color: var(--text); }
.choice:hover, .choice:focus-visible { background: #29463d; outline-offset: -2px; }
.choice small { display: block; color: var(--muted); }
.choicetime { color: var(--mint); font-size: 12px; font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ==========================================================================
   Toast
   ========================================================================== */
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 20; display: flex; align-items: center; gap: 12px; background: var(--mint); color: #153326; border-radius: 9px; padding: 10px 14px; font-weight: 800; box-shadow: 0 10px 30px #0007; opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .18s, transform .18s; }
.toast.show { opacity: 1; transform: none; pointer-events: auto; }
.toastundo { border: 0; background: #153326; color: var(--mint); border-radius: 6px; padding: 4px 10px; font-weight: 800; font-size: 12px; }
.toastundo:hover { background: #22493a; }
.toastundo:focus-visible { outline-color: #153326; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 650px) {
  .wrap { padding: 15px; }
  .topactions { gap: 5px; }
  .topactions .btn { font-size: 11px; padding: 8px; }
  .brand { font-size: 17px; }
  .brandicon { width: 28px; height: 28px; font-size: 20px; margin-right: 5px; }
  .clock { font-size: 26px; }
  .insights, .action-list { grid-template-columns: 1fr; }
  .actions-card { grid-column: auto; }
  .panel { padding: 14px; }
  .timeline-row { grid-template-columns: 90px minmax(0, 1fr); }
  .toast { left: 15px; right: 15px; justify-content: space-between; }
}
@media (max-width: 450px) {
  .top { align-items: flex-start; flex-wrap: wrap; }
  .topactions { width: 100%; justify-content: flex-start; }
  .cards { grid-template-columns: 1fr; }
  .clock { font-size: 30px; }
  .controls label { flex: 1 1 140px; }
}
