:root {
  --blue: #1d4f91; --blue-dark: #143a6b; --blue-soft: #e8f0fb;
  --ink: #17202c; --muted: #5d6878; --line: #dde3ec; --bg: #f5f7fb; --card: #fff;
  --ok: #1d7a46; --ok-soft: #e3f4ea; --warn: #9a5b00; --warn-soft: #fff3dc; --bad: #b42318; --bad-soft: #fde8e6;
  --radius: 10px; --side: 240px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
a { color: var(--blue); }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: .75rem 0 .35rem; }
.loading { padding: 2rem; color: var(--muted); }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.side { width: var(--side); background: var(--card); border-right: 1px solid var(--line); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; flex-shrink: 0; }
.side .logo { display: block; padding: .25rem .5rem 1rem; }
.side .logo img { max-width: 100%; max-height: 72px; }
.nav a { display: block; padding: .55rem .75rem; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--blue-soft); }
.nav a.active { background: var(--blue); color: #fff; }
.nav .section { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1rem .75rem .25rem; }
.side .who { margin-top: 1.5rem; padding: .75rem; border-top: 1px solid var(--line); font-size: .85rem; color: var(--muted); }
.main { flex: 1; min-width: 0; padding: 1.25rem 1.5rem 4rem; max-width: 1200px; }
.topbar { display: none; }

@media (max-width: 820px) {
  .shell { display: block; }
  .side { position: fixed; z-index: 30; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  .side.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 20; }
  .topbar { display: flex; align-items: center; gap: .75rem; position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line); padding: .5rem 1rem; padding-top: max(.5rem, env(safe-area-inset-top)); }
  .topbar img { height: 34px; }
  .topbar .title { font-weight: 600; flex: 1; }
  .main { padding: 1rem 1rem 5rem; }
}

/* Controls */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; padding: .5rem .85rem; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .35rem; min-height: 40px; }
button:hover, .btn:hover { border-color: var(--blue); }
.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.primary:hover { background: var(--blue-dark); }
.danger { color: var(--bad); border-color: #f2c3be; }
.small { padding: .25rem .55rem; min-height: 32px; font-size: .85rem; }
.linkish { border: 0; background: none; color: var(--blue); padding: 0; min-height: 0; text-decoration: underline; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; }
.muted { color: var(--muted); }
.tbc { color: var(--warn); font-style: italic; }

label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .2rem; }
input, select, textarea { font: inherit; width: 100%; padding: .55rem .65rem; border: 1px solid #c8d0dc; border-radius: 8px; background: #fff; color: var(--ink); }
input[type=checkbox] { width: auto; }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: .8rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 1rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem .25rem; margin: 0 0 1rem; background: var(--card); }
legend { font-weight: 700; padding: 0 .35rem; }
.hint { font-size: .82rem; color: var(--muted); margin-top: .2rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.pill { display: inline-block; font-size: .78rem; font-weight: 600; border-radius: 999px; padding: .1rem .55rem; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.pill.Accepted, .pill.Paid, .pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.Pending, .pill.Unconfirmed, .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.Declined, .pill.Outstanding, .pill.bad { background: var(--bad-soft); color: var(--bad); }
.warnbox { background: var(--warn-soft); color: #6b4000; border-radius: 8px; padding: .5rem .75rem; margin: .5rem 0; font-size: .9rem; }
.errbox { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: .5rem .75rem; margin: .5rem 0; }
.okbox { background: var(--ok-soft); color: var(--ok); border-radius: 8px; padding: .5rem .75rem; margin: .5rem 0; }

/* Calendar */
.cal-head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .75rem; }
.cal-head h1 { margin-right: auto; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); gap: 1px; }
.cal .dow { background: #f0f3f8; text-align: center; font-size: .78rem; font-weight: 700; padding: .35rem 0; color: var(--muted); }
.cal .day { background: var(--card); min-height: 108px; padding: .3rem; }
.cal .day.other { background: #fafbfd; color: #a8b0bc; }
.cal .day.today .num { background: var(--blue); color: #fff; border-radius: 999px; }
.cal .num { display: inline-block; min-width: 1.6rem; text-align: center; font-size: .82rem; font-weight: 600; padding: .05rem .3rem; }
.cal .add { float: right; border: 0; background: none; color: var(--muted); min-height: 0; padding: 0 .3rem; font-size: 1rem; }
.entry { display: block; width: 100%; text-align: left; border: 0; border-left: 3px solid var(--blue); background: var(--blue-soft); border-radius: 4px; padding: .2rem .35rem; margin-top: .2rem; font-size: .8rem; min-height: 0; line-height: 1.25; color: var(--ink); }
.entry b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry span { color: var(--muted); }
.entry.tbc-time span { color: var(--warn); }
.agenda { display: none; }
@media (max-width: 640px) {
  .cal { display: none; }
  .agenda { display: block; }
}
.list-item { display: flex; gap: .75rem; align-items: flex-start; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.datebox { flex: 0 0 52px; text-align: center; background: var(--blue-soft); color: var(--blue-dark); border-radius: 8px; padding: .25rem 0; line-height: 1.1; }
.datebox .d { font-size: 1.3rem; font-weight: 700; }
.datebox .m, .datebox .w { font-size: .72rem; text-transform: uppercase; }
.grow { flex: 1; min-width: 0; }
.clickable { cursor: pointer; }
.clickable:hover .title { text-decoration: underline; }
.title { font-weight: 600; }

/* Details */
dl.details { display: grid; grid-template-columns: 180px 1fr; gap: .4rem 1rem; margin: 0; }
dl.details dt { color: var(--muted); font-weight: 600; font-size: .88rem; }
dl.details dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 560px) { dl.details { grid-template-columns: 1fr; } dl.details dd { margin-bottom: .5rem; } }
.coverage { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.cov { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .65rem; background: #fbfcfe; }
.cov .n { font-size: 1.15rem; font-weight: 700; }
.cov.short { border-color: #f2c3be; background: var(--bad-soft); }
.cov.full { border-color: #b8e0c7; background: var(--ok-soft); }
.cov.unknown { border-color: #f3d9a4; background: var(--warn-soft); }
@media (max-width: 480px) { .coverage { grid-template-columns: 1fr; } }

table.simple { width: 100%; border-collapse: collapse; background: var(--card); }
table.simple th, table.simple td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.simple th { font-size: .8rem; color: var(--muted); text-transform: uppercase; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.assign { display: flex; flex-wrap: wrap; gap: .4rem .75rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.assign:last-child { border-bottom: 0; }
.assign .who { font-weight: 600; min-width: 140px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 25, 40, .45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; overflow-y: auto; }
.modal { background: var(--card); border-radius: 12px; width: 100%; max-width: 620px; padding: 1.1rem 1.2rem; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.copyfield { display: flex; gap: .5rem; align-items: flex-start; }
.copyfield input, .copyfield textarea { flex: 1; }
.copyfield textarea { min-height: 220px; }

#toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); background: #17202c; color: #fff; padding: .6rem 1rem; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: 90vw; }
#toast.show { opacity: 1; }

/* Auth pages */
.auth { max-width: 420px; margin: 8vh auto; padding: 0 1rem; }
.auth .logo { text-align: center; margin-bottom: 1.25rem; }
.auth .logo img { max-width: 260px; max-height: 110px; }

.perm-table td:not(:first-child), .perm-table th:not(:first-child) { text-align: center; }
.perm-table input { width: 22px; height: 22px; }

@media print {
  .side, .topbar, .noprint, button { display: none !important; }
  .main { padding: 0; }
  body { background: #fff; }
  .card { border: 0; padding: 0; }
}
