:root {
  /* MeteoLux palette: blues from meteolux.lu, sun yellow from the logo */
  --ml-blue: #216d94; --ml-blue-dark: #134968; --ml-blue-btn: #157aad; --ml-teal: #277687; --ml-sun: #f5b82e; --ml-red: #ca4027;
  --paper: #f4f5f5; --surface: #ffffff; --ink: #2b2b2e; --muted: #58585b; --line: #dde1e4; --line-strong: #b4bbc2;
  --accent: var(--ml-blue-btn); --accent-ink: #ffffff; --hard: #c0392b; --soft: #b7791f; --ok: #2f7a4d;
  --we: #e9eef2; --hol: #f9e4e0; --band: var(--ml-blue);
  --s-m: #ffe3a1; --s-a: #c9e1f7; --s-n: #216d94; --s-n-ink: #ffffff; --s-d: #a9e2cb; --s-j: #e1e4e7; --s-b: #ddd3ee; --s-pl: #7ad88a; --s-c: #fff38a;
  --font: 'Open Sans', Arial, system-ui, sans-serif;
  --font-grid: 'Open Sans', Arial, system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12191f; --surface: #1a232b; --ink: #e8ecef; --muted: #a0abb5; --line: #2c3842; --line-strong: #4e5c69;
    --accent: #5fa8d6; --accent-ink: #0c1a24; --hard: #ff8f84; --soft: #f0b85a; --ok: #7fd092;
    --we: #202b35; --hol: #3b2727; --band: #1a4f6e;
    --s-m: #6e5414; --s-a: #1e4f7b; --s-n: #3b78a0; --s-d: #1c6b51; --s-j: #3a414a; --s-b: #4d3a6b; --s-pl: #23803a; --s-c: #6f6800;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 15px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 6px; padding: 6px 12px; }
button:hover:not(:disabled) { border-color: var(--ink); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--ml-blue-dark); border-color: var(--ml-blue-dark); }
button.wide { width: 100%; padding: 10px; font-size: 15px; }
button.quiet { border-color: transparent; background: transparent; }
button.quiet:hover:not(:disabled) { border-color: var(--line-strong); }
button.danger { color: var(--hard); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h2 { font-size: 19px; margin: 28px 0 8px; font-weight: 600; color: var(--ml-blue); padding-bottom: 4px; border-bottom: 2px solid var(--ml-blue); display: inline-block; }
h3 { font-size: 16px; margin: 20px 0 6px; font-weight: 600; }
.lead { color: var(--muted); max-width: 72ch; margin: 0 0 14px; }
.hint { color: var(--muted); font-size: 13.5px; max-width: 72ch; }

/* header */
.bar { position: sticky; top: 0; z-index: 30; display: flex; gap: 20px; align-items: center; flex-wrap: wrap;
  padding: 8px 18px; background: var(--surface); border-bottom: 3px solid var(--band); box-shadow: 0 1px 0 var(--line); }
.brand { display: flex; gap: 12px; align-items: center; min-width: 220px; }
.brand img { flex: none; }
.brand .logo { height: 37px; width: auto; }
.logo-login { display: block; height: 66px; width: auto; margin: 2px 0 10px; }
.app { font-size: 12px; color: var(--ml-blue); line-height: 1.1; font-weight: 600; }
.brand > div { border-left: 1px solid var(--line); padding-left: 12px; }
h1 { font-size: 21px; margin: 0; font-weight: 700; letter-spacing: -.01em; line-height: 1.15; color: var(--muted); }
.tabs { display: flex; gap: 2px; align-self: stretch; }
.tabs button { border: 0; border-radius: 0; background: none; padding: 8px 12px; color: var(--ml-blue); font-weight: 600; font-size: 13.5px; border-bottom: 3px solid transparent; margin-bottom: -11px; }
.tabs button[aria-selected="true"] { color: var(--ml-blue-dark); border-bottom-color: var(--ml-sun); }
.tabs button:hover { background: var(--paper); }
.user { color: var(--muted); font-size: 13px; text-decoration: none; padding: 6px 4px; }
.user:hover { color: var(--ml-blue); text-decoration: underline; }
.actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.menu { position: relative; }
.menu-list { position: absolute; top: calc(100% + 4px); left: 0; z-index: 40; min-width: 270px; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 4px; box-shadow: 0 8px 24px rgba(20, 30, 45, .18); }
.menu-list.right { left: auto; right: 0; }
.menu-list button { display: block; width: 100%; text-align: left; border: 0; border-radius: 4px; padding: 8px 10px; }
.menu-list button:hover { background: var(--paper); }
#userBox { color: var(--muted); font-size: 13.5px; }

main { padding: 0 18px 40px; }
.tab { padding-top: 14px; }
.pane { max-width: 1200px; }
#tab-rules .pane, #tab-month .pane { max-width: none; }

/* empty state */
.empty { max-width: 920px; padding: 20px 0; }
.empty h2 { font-size: 26px; margin: 18px 0 6px; font-weight: 600; color: var(--muted); border: 0; display: block; }
.steps { list-style: none; padding: 0; margin: 22px 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; counter-reset: st; }
.steps li { counter-increment: st; }
.drop { width: 100%; height: 100%; text-align: left; display: flex; flex-direction: column; gap: 6px; padding: 18px 18px 16px 58px; position: relative;
  border: 1.5px dashed var(--line-strong); border-radius: 10px; background: var(--surface); }
.drop::before, .step3 .n { content: counter(st); position: absolute; left: 16px; top: 15px; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; background: var(--ml-blue); color: #fff; }
.step3 { position: relative; display: flex; gap: 10px; padding: 14px 18px 14px 58px; border-radius: 10px; background: var(--surface); border: 1.5px solid var(--line); max-width: 920px; }
.step3 .n { position: absolute; }
.step3 strong { display: block; font-size: 17px; }
.step3 span:not(.n) { color: var(--muted); font-size: 14px; }
.drop.done::before { background: var(--ok); }
.drop em::before { content: '📂 '; }
.drop.done em::before { content: '✓ '; }
.drop strong { font-size: 17px; }
.drop span { color: var(--muted); font-size: 14px; }
.drop em { font-style: normal; font-size: 13.5px; font-weight: 600; color: var(--ml-blue-btn); }
.drop.done { border-style: solid; border-color: var(--ok); }
.drop.done em { color: var(--ok); }
.drop.dragover { border-color: var(--accent); background: var(--paper); }

/* plan view */
.infobar { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; margin-bottom: 10px; flex-wrap: wrap; }
#carryInfo { color: var(--muted); font-size: 13.5px; max-width: 110ch; }
#carryInfo b { color: var(--ink); font-weight: 600; }
.tools { display: flex; gap: 6px; align-items: center; }
.quiet-check { font-size: 13.5px; color: var(--muted); display: flex; gap: 5px; align-items: center; padding: 0 6px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 14px; align-items: start; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }
.gridwrap { overflow: auto; max-height: calc(100vh - 170px); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }

/* the grid */
#grid { border-collapse: separate; border-spacing: 0; font-family: var(--font-grid); font-size: 13px; font-weight: 600; }
#grid th, #grid td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; text-align: center; white-space: nowrap; }
#grid td { min-width: 44px; height: 27px; position: relative; cursor: pointer; }
.compact #grid td { min-width: 36px; height: 22px; font-size: 13px; }
#grid thead th { position: sticky; top: 0; z-index: 3; background: var(--ml-blue); color: #fff; padding: 6px 4px 5px; font-size: 13px; line-height: 1.1; vertical-align: bottom; border-right-color: rgba(255,255,255,.25); }
#grid thead th small { display: block; font-weight: 400; color: rgba(255,255,255,.8); font-size: 11px; }
#grid th.day { position: sticky; left: 0; z-index: 2; background: var(--surface); text-align: left; padding: 0 8px; min-width: 76px; font-weight: 600; }
#grid thead th.day { z-index: 4; background: var(--ml-blue); color: #fff; }
#grid tr.we th.day, #grid tr.we td.e { background: var(--we); }
#grid tr.hol th.day { background: var(--hol); }
#grid tr.hol td.e { background: var(--hol); }
#grid tr.mon > * { border-top: 2px solid var(--line-strong); }
#grid th.day .wd { color: var(--muted); font-weight: 500; margin-left: 4px; }
#grid th.day .h { color: var(--hard); font-weight: 600; margin-left: 4px; font-size: 12px; }
#grid td.m { background: var(--s-m); } #grid td.a { background: var(--s-a); } #grid td.d { background: var(--s-d); }
#grid td.n { background: var(--s-n); color: var(--s-n-ink); border-bottom-color: transparent; }
#grid td.n.nend { border-bottom-color: var(--line); }
#grid td.j { background: var(--s-j); } #grid td.b { background: var(--s-b); } #grid td.pl { background: var(--s-pl); }
#grid td.c { background: var(--s-c); } #grid td.c0 { background: var(--s-c); color: var(--muted); }
#grid td.e { color: var(--line-strong); font-weight: 500; }
#grid td.fx { font-weight: 500; }
#grid td.fx::before { content: ''; position: absolute; left: 0; top: 0; border-style: solid; border-width: 7px 7px 0 0; border-color: var(--line-strong) transparent transparent transparent; }
#grid td.edited::after { content: ''; position: absolute; right: 3px; top: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
#grid td.lock::after { content: ''; position: absolute; right: 2px; top: 2px; width: 7px; height: 7px; border-radius: 1px; background: var(--ink); box-shadow: 0 0 0 1.5px var(--surface); }
#grid td.vh { box-shadow: inset 0 0 0 2px var(--hard); }
#grid td.vs { box-shadow: inset 0 0 0 2px var(--soft); }
#grid td.focus { animation: pulse 1.4s ease-out 2; }
@keyframes pulse { 0% { box-shadow: inset 0 0 0 3px var(--accent); } 100% { box-shadow: inset 0 0 0 3px transparent; } }
@media (prefers-reduced-motion: reduce) { #grid td.focus { animation: none; box-shadow: inset 0 0 0 3px var(--accent); } }
#grid td:hover { filter: brightness(.94); }
#grid col.sep, #grid .sep { border-left: 2px solid var(--line-strong); }
#grid tfoot { position: sticky; bottom: 0; z-index: 3; }
#grid tfoot th, #grid tfoot td { background: var(--surface); font-weight: 600; font-size: 13px; padding: 3px 4px; cursor: default; height: 24px; }
#grid tfoot tr:first-child > * { border-top: 2px solid var(--line-strong); }
#grid tfoot td.neg { color: var(--hard); }
#grid tfoot td.pos { color: var(--ok); }
#grid tfoot td.hi { color: var(--soft); }
#grid tfoot th.day { font-weight: 600; font-size: 13px; position: sticky; left: 0; z-index: 4; }
#grid tfoot td:hover { filter: none; }

/* checks */
.checks { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; max-height: calc(100vh - 170px); overflow: auto; position: sticky; top: 76px; }
.checks-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.checks h2 { margin: 0 0 8px; font-size: 17px; border: 0; display: block; color: var(--ink); }
#checkCounts { font-size: 13.5px; font-weight: 600; }
.cnt-h { color: var(--hard); } .cnt-s { color: var(--soft); } .cnt-ok { color: var(--ok); }
.v { display: block; width: 100%; text-align: left; border: 0; border-left: 3px solid var(--soft); border-radius: 0; padding: 5px 8px; margin: 4px 0; font-size: 13.5px; background: var(--paper); }
.v.hard { border-left-color: var(--hard); }
.v.info { border-left-color: var(--line-strong); }
.vgroup { font-size: 12.5px; color: var(--muted); margin: 12px 0 2px; font-weight: 600; }
.stats-mini { font-size: 13px; color: var(--muted); margin-top: 14px; border-top: 1px solid var(--line); padding-top: 8px; }

.legend { margin-top: 14px; max-width: 110ch; font-size: 14px; }
.legend summary { cursor: pointer; color: var(--muted); }
.legend .sw { display: inline-block; padding: 1px 7px; margin: 3px 4px 3px 0; border-radius: 3px; font-family: var(--font-grid); font-weight: 600; }

/* progress */
.progress { position: fixed; right: 18px; bottom: 18px; z-index: 50; width: min(420px, calc(100vw - 36px)); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 10px; padding: 14px 16px; box-shadow: 0 12px 32px rgba(20, 30, 45, .22); }
.p-head { display: flex; justify-content: space-between; gap: 10px; }
.p-bar { height: 6px; background: var(--paper); border-radius: 3px; margin: 10px 0 8px; overflow: hidden; }
.p-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .5s linear; }
.p-info { font-size: 13.5px; color: var(--muted); min-height: 2.9em; }
.p-actions { margin-top: 8px; display: flex; justify-content: flex-end; }

/* popover */
.pop { position: fixed; z-index: 60; width: 300px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px;
  padding: 10px 12px 12px; box-shadow: 0 12px 32px rgba(20, 30, 45, .25); }
.pop-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.pop .x { border: 0; font-size: 20px; padding: 0 6px; line-height: 1; background: none; }
.pop .grp { font-size: 12px; color: var(--muted); margin: 8px 0 3px; }
.pop .codes { display: flex; flex-wrap: wrap; gap: 4px; }
.pop .codes button { font-family: var(--font-grid); font-weight: 600; min-width: 46px; padding: 4px 6px; border-radius: 4px; }
.pop .codes button.cur { outline: 2px solid var(--ink); outline-offset: 1px; }
.pop .codes button.bad { opacity: .5; }
.pop-lock { display: flex; gap: 6px; align-items: center; margin-top: 10px; font-size: 13.5px; }
.sw-m { background: var(--s-m); } .sw-a { background: var(--s-a); } .sw-n { background: var(--s-n); color: var(--s-n-ink); } .sw-d { background: var(--s-d); }
.sw-j { background: var(--s-j); } .sw-b { background: var(--s-b); } .sw-pl { background: var(--s-pl); } .sw-c { background: var(--s-c); }

/* forms */
.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
table.form { border-collapse: collapse; font-size: 14px; width: 100%; }
table.form th { text-align: left; font-weight: 600; font-size: 13px; color: var(--muted); padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
table.form td { padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.form td.grow { width: 100%; }
table.form td.grow input { width: 100%; min-width: 120px; }
table.form th { white-space: normal; line-height: 1.2; vertical-align: bottom; }
table.form tr.off td { opacity: .5; }
table.form input[type=number] { width: 56px; }
table.form input[type=text] { width: 120px; }
table.form input.wide { width: 100%; min-width: 140px; }
table.form input.code { width: 58px; font-weight: 600; }
table.form .pair { display: inline-flex; gap: 3px; align-items: center; }
table.form .pair input { width: 44px; }
input[type=text], input[type=number], input:not([type]), input[type=password], select, textarea {
  border: 1px solid var(--line-strong); border-radius: 5px; padding: 4px 6px; background: var(--surface); }
input::placeholder { color: var(--line-strong); }
textarea { width: 100%; font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.row-fields { display: flex; flex-wrap: wrap; gap: 12px 20px; }
.row-fields label { display: flex; flex-direction: column; gap: 3px; font-size: 13.5px; color: var(--muted); }
.row-fields input { width: 160px; color: var(--ink); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.versions { border-collapse: collapse; width: 100%; max-width: 900px; }
.versions td, .versions th { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }

dialog { display: none; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--ink); padding: 18px 20px; width: min(360px, 92vw); }
dialog::backdrop { background: rgba(10, 18, 28, .45); }
dialog h2 { margin-top: 0; }
dialog label { display: flex; flex-direction: column; gap: 3px; margin: 10px 0; font-size: 14px; }
.err { color: var(--hard); font-size: 13.5px; min-height: 1.2em; }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 70; background: var(--ink); color: var(--paper);
  padding: 9px 16px; border-radius: 8px; font-size: 14px; max-width: 90vw; }

@media (max-width: 700px) {
  .bar { padding: 8px 12px; gap: 10px; }
  main { padding: 0 12px 30px; }
  .actions { margin-left: 0; }
  .tabs { overflow-x: auto; max-width: 100%; }
}
@media print {
  @page { size: A3 landscape; margin: 8mm; }
  body { background: #fff; color: #000; font-size: 11px; }
  .bar .tabs, .bar .actions, .checks, .infobar .tools, .legend, .progress, .toast { display: none !important; }
  .bar { position: static; border: 0; padding: 0 0 6px; }
  main { padding: 0; }
  .split { display: block; }
  .gridwrap { overflow: visible; max-height: none; border: 0; }
  #grid { font-size: 11px; }
  #grid td { min-width: 0; height: 17px; }
  #grid thead th, #grid tfoot, #grid tfoot th, #grid th.day { position: static; }
  #grid td.vh, #grid td.vs { box-shadow: none; }
  #grid td.edited::after, #grid td.lock::after { display: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* login */
body.login-page { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(180deg, var(--ml-blue-dark), var(--ml-blue) 60%, #4a94bd); }
.login-card { width: min(380px, 92vw); background: var(--surface); border-radius: 12px; padding: 26px 28px 24px; box-shadow: 0 20px 50px rgba(10, 30, 50, .35); }
.login-card .brand { margin-bottom: 8px; }
.login-card h1 { color: var(--ml-blue-dark); font-size: 22px; margin-bottom: 4px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; margin: 12px 0; font-size: 14px; color: var(--muted); }
.login-card input { padding: 8px 10px; font-size: 15px; color: var(--ink); }
.login-card .lead { font-size: 14px; margin-bottom: 4px; }
.login-card button { margin-top: 6px; }
