:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #5b6875;
  --line: #d5dbe1;
  --accent: #0b5f8a;
  --accent-ink: #ffffff;
  --good: #1d7a3e;
  --warn: #9a6200;
  --bad: #b3261e;
  --focus: #f0b400;
  font: 15px/1.4 "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 .5rem; }
h2:first-child { margin-top: 0; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; margin: .25rem 0; }
.good { color: var(--good); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.fatal { margin: 3rem auto; max-width: 30rem; font-size: 1.1rem; color: var(--bad); }

input, select, textarea, button, .button {
  font: inherit; color: inherit;
  border: 1px solid var(--line); border-radius: 6px;
  padding: .45rem .6rem; background: #fff;
}
input, select, textarea { width: 100%; }
input[type=radio], input[type=checkbox] { width: auto; }
textarea { resize: vertical; }
button, .button { cursor: pointer; background: #fff; text-decoration: none; display: inline-block; white-space: nowrap; }
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { border-color: var(--line); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
input.invalid { border-color: var(--bad); background: #fdecea; }
kbd { font: inherit; font-size: .75em; opacity: .8; margin-left: .3em; }
button.pulse { box-shadow: 0 0 0 3px rgba(11, 95, 138, .3); }

/* auth screens */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1.75rem; width: min(26rem, 100%); }
.card label { display: block; margin: .75rem 0; font-weight: 600; }
.card label input, .card label select { margin-top: .3rem; font-weight: 400; }
.card button.primary { width: 100%; padding: .7rem; margin-top: .5rem; }
.plant-line { margin: 0 0 .25rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: .8rem; }

/* main layout */
.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .5rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; }
.tabs { display: flex; gap: .25rem; }
.tabs button { border-color: transparent; background: transparent; }
.tabs button.active { background: var(--bg); border-color: var(--line); font-weight: 600; }
.who { margin-left: auto; display: flex; align-items: center; gap: .5rem; }

#tab-rounds { display: grid; grid-template-columns: 13rem 1fr; min-height: calc(100vh - 3.2rem); }
.days { background: var(--panel); border-right: 1px solid var(--line); padding: .75rem .5rem; overflow-y: auto; max-height: calc(100vh - 3.2rem); position: sticky; top: 3.2rem; }
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
#day-list { list-style: none; margin: 0; padding: 0; }
#day-list button { width: 100%; display: grid; grid-template-columns: 1rem 1.6rem 2.2rem 1fr; align-items: center; gap: .25rem; text-align: left; border-color: transparent; padding: .25rem .4rem; background: transparent; }
#day-list button.current { background: var(--bg); border-color: var(--accent); }
#day-list small { color: var(--muted); }
#day-list .by { overflow: hidden; text-overflow: ellipsis; }
.dot { display: inline-block; width: .65rem; height: .65rem; border-radius: 50%; border: 1px solid var(--line); }
.dot.saved { background: #9bbcd0; border-color: #6d97b0; }
.dot.exported { background: var(--good); border-color: var(--good); }
.dot.stale { background: #e8a900; border-color: var(--warn); }
.dot.pending { background: #fff; border: 2px solid var(--accent); }
.dot.conflict { background: var(--bad); border-color: var(--bad); }
.legend { font-size: .75rem; color: var(--muted); margin-top: .75rem; display: grid; grid-template-columns: .9rem 1fr; gap: .2rem .3rem; align-items: center; }

.entry { padding: 1rem 1.25rem 4rem; max-width: 72rem; }
.entry-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem; position: sticky; top: 3.2rem; background: var(--bg); padding: .5rem 0; z-index: 4; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.date-pick { display: flex; align-items: center; gap: .25rem; }
.date-pick input { width: auto; font-weight: 600; }
.status { color: var(--muted); font-size: .9rem; flex: 1; min-width: 14rem; }
.actions { display: flex; gap: .5rem; }
.banner { background: #fff4e0; border: 1px solid #e8c37a; padding: .6rem .8rem; border-radius: 6px; }
.banner button { margin-left: .5rem; }
.derived { color: var(--muted); font-size: .9rem; }

fieldset.section { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .35rem; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .6rem 1rem; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .2rem; }
.field label small, th small { font-weight: 400; color: var(--muted); margin-left: .2rem; }
.field.wide, .field.has-hint { grid-column: 1 / -1; }
.field .hint { margin: .2rem 0 0; font-size: .8rem; color: var(--muted); }
.operator-field { max-width: 22rem; margin-bottom: 1rem; }

table.grid { border-collapse: collapse; width: 100%; }
table.grid th, table.grid td { padding: .2rem; }
table.grid thead th { font-size: .8rem; text-align: left; vertical-align: bottom; }
table.grid thead th small { display: block; margin: 0; }
table.grid tbody th { text-align: left; font-weight: 600; font-size: .9rem; white-space: nowrap; padding-right: .5rem; }
table.grid td.na { background: repeating-linear-gradient(45deg, transparent 0 6px, #eef1f4 6px 12px); border-radius: 4px; }
table.grid input { min-width: 4.5rem; }

.panel { padding: 1rem 1.25rem 3rem; max-width: 64rem; }
table.list { border-collapse: collapse; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table.list th, table.list td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: left; }
table.list tr.inactive td { color: var(--muted); }
.row-actions { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.pin-reset { display: inline-flex; gap: .25rem; }
.pin-reset input { width: 6.5rem; }
form.inline { display: flex; flex-wrap: wrap; align-items: end; gap: .6rem; }
form.inline label { display: flex; flex-direction: column; font-size: .85rem; font-weight: 600; gap: .2rem; }
form.inline label input { width: 13rem; font-weight: 400; }
form.inline label.check { flex-direction: row; align-items: center; gap: .35rem; padding-bottom: .5rem; }
form.inline label.check input { width: auto; }
#settings-form label input { width: 24rem; }

#toast { position: fixed; bottom: 1rem; left: 50%; transform: translate(-50%, 150%); background: var(--ink); color: #fff; padding: .65rem 1rem; border-radius: 6px; max-width: min(40rem, 90vw); transition: transform .2s; z-index: 20; }
#toast { visibility: hidden; }
#toast.show { transform: translate(-50%, 0); visibility: visible; }
#toast.good { background: var(--good); }
#toast.bad { background: var(--bad); }

@media (max-width: 760px) {
  #tab-rounds { grid-template-columns: 1fr; }
  .days { position: static; max-height: 12rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .topbar { flex-wrap: wrap; gap: .5rem; }
}

/* offline and sync */
.conn { font-size: .85rem; font-weight: 600; padding: .2rem .6rem; border-radius: 999px; }
.conn.off { background: #3a3f45; color: #fff; }
.conn.pending { background: #e6f0f6; color: var(--accent); }
.offline-note { background: #eef1f4; border-left: 4px solid #3a3f45; padding: .5rem .7rem; border-radius: 4px; font-size: .9rem; }
#conflict { background: #fdecea; border: 1px solid #e6a59f; border-radius: 8px; padding: .8rem 1rem; margin-bottom: 1rem; }
#conflict h2 { margin-top: 0; }
#conflict table { margin: .5rem 0 .8rem; }
#conflict label { display: flex; gap: .4rem; align-items: center; font-weight: 400; }
.code-box { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; }
.code-box .code { font: 700 1.6rem/1.2 ui-monospace, Consolas, monospace; letter-spacing: .1em; margin-left: .4rem; }
.fatal button { margin-top: .75rem; }
input[readonly], textarea[readonly] { background: #f0f2f4; }
