:root {
  color-scheme: light dark;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dbe0e7;
  --text: #1a2330;
  --muted: #5b6878;
  --accent: #1d4f91;
  --accent-soft: #e4edf9;
  --on-accent: #ffffff;
  --danger: #b8322a;
  --danger-soft: #fbe9e7;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --ok: #2a7540;
  --shadow: 0 1px 2px rgba(20, 30, 45, .06), 0 2px 8px rgba(20, 30, 45, .05);
  --c0: #2b6fd6; --c1: #0c8577; --c2: #7650c9; --c3: #b0730f;
  --c4: #c03e78; --c5: #3d8a37; --c6: #cc5a1c; --c7: #5a6a80;
  --c8: #0b82b5; --c9: #a8452f; --c10: #7d7f15; --c11: #4a55b8;
  --none: #8792a0;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --surface: #1a2029;
    --surface-2: #222a35;
    --border: #303a47;
    --text: #e6ebf1;
    --muted: #9ba8b7;
    --accent: #77a9f2;
    --accent-soft: #1f3048;
    --on-accent: #0c1420;
    --danger: #f2837a;
    --danger-soft: #3a2020;
    --warn: #e8ae52;
    --warn-soft: #3a2e17;
    --ok: #72c789;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 10px rgba(0, 0, 0, .25);
    --c0: #6ea4f5; --c1: #3cc0b0; --c2: #a78bea; --c3: #e0a542;
    --c4: #ec7fae; --c5: #7cc974; --c6: #f08f56; --c7: #9aabc0;
    --c8: #4fc0ec; --c9: #e58a72; --c10: #c2c552; --c11: #8f99f0;
    --none: #7d8896;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }
.boot { padding: 48px 16px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.grow { flex: 1 1 auto; }
.hidden { display: none !important; }
svg.ic { width: 1em; height: 1em; flex: none; vertical-align: -0.125em; }

/* ---------- controls ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%;
  min-height: 38px;
  padding: 7px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
textarea { resize: vertical; min-height: 72px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, .cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 7px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.sm { min-height: 30px; padding: 3px 10px; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  background: none; border: 0; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 1.1rem;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--muted); }
.field .hint { font-weight: 400; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: 18px; height: 18px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px 20px; flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 1.02rem; white-space: nowrap; }
.brand img { width: 26px; height: 26px; }
.tabs { display: flex; gap: 2px; flex: 1 1 auto; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 7px 12px; border-radius: 8px; white-space: nowrap;
  color: var(--muted); font-weight: 600; text-decoration: none;
}
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a.on { background: var(--accent-soft); color: var(--accent); }
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 8px; font-weight: 600; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary:hover { background: var(--surface-2); }
.usermenu .menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.usermenu .menu button { text-align: left; padding: 8px 10px; background: none; border: 0; border-radius: 6px; cursor: pointer; }
.usermenu .menu button:hover { background: var(--surface-2); }
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: .68rem; font-weight: 700;
}
main { max-width: 1280px; margin: 0 auto; padding: 16px 16px 64px; }
@media (max-width: 720px) {
  .top { padding: 8px 12px 4px; }
  .tabs { order: 3; flex-basis: 100%; margin: 0 -4px; }
  .brand { flex: 1 1 auto; }
  main { padding: 12px 12px 64px; }
}

/* ---------- summary pills ---------- */
.stats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.stat {
  display: flex; align-items: baseline; gap: 7px; padding: 6px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
}
.stat:hover { background: var(--surface-2); }
.stat b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .88rem; }
.stat.alert { border-color: var(--danger); background: var(--danger-soft); }
.stat.alert b, .stat.alert span { color: var(--danger); }
.stat.warn b { color: var(--warn); }

/* ---------- toolbars ---------- */
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.bar select, .bar input[type=search] { width: auto; min-width: 0; flex: 0 1 auto; }
.bar input[type=search] { flex: 1 1 180px; max-width: 320px; }
.quick { display: flex; gap: 8px; margin-bottom: 12px; }
.quick input { flex: 1 1 auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
.page-head h1 { flex: 1 1 auto; }

/* ---------- calendar ---------- */
.cal-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 10px; }
.cal-nav { display: flex; align-items: center; gap: 6px; flex: 1 1 auto; }
.cal-nav h1 { margin-left: 8px; }
.cal-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.cal-filters select { width: auto; }
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-week { padding: 0 1px; }
.cal-week span { padding: 4px 8px; font-size: .75rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.cal-grid { gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.cell {
  position: relative; min-height: 118px; padding: 5px 6px 6px;
  background: var(--surface); cursor: pointer;
  display: flex; flex-direction: column; gap: 3px; min-width: 0;
}
.cell.out { background: var(--surface-2); }
.cell.out .num { opacity: .55; }
.cell.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.cell.drop { background: var(--accent-soft); }
.cell .num {
  align-self: flex-start; min-width: 24px; height: 24px; padding: 0 5px;
  display: grid; place-items: center; border-radius: 999px;
  font-size: .82rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.cell.today .num { background: var(--accent); color: var(--on-accent); }
.chip {
  display: flex; align-items: center; gap: 4px; width: 100%; min-width: 0;
  padding: 2px 6px; border: 0; border-left: 3px solid var(--tc, var(--none)); border-radius: 4px;
  background: color-mix(in srgb, var(--tc, var(--none)) 15%, var(--surface));
  font-size: .78rem; line-height: 1.35; text-align: left; cursor: pointer;
}
.chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip:hover { background: color-mix(in srgb, var(--tc, var(--none)) 28%, var(--surface)); }
.chip.done { opacity: .55; }
.chip.done > span { text-decoration: line-through; }
.chip.late { box-shadow: inset 0 0 0 1px var(--danger); }
.chip.late::after { content: "!"; margin-left: auto; padding-left: 4px; color: var(--danger); font-weight: 800; }
.chip.ship { border-left-color: var(--text); background: var(--surface); box-shadow: inset 0 0 0 1px var(--border); font-weight: 600; }
.more { font-size: .75rem; color: var(--muted); padding-left: 6px; }
.dots { display: none; flex-wrap: wrap; gap: 3px; align-items: center; padding: 0 2px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--tc, var(--none)); }
.dot.done { opacity: .35; }
.dot.late { box-shadow: 0 0 0 1.5px var(--danger); }
.dot.ship { border-radius: 1px; background: var(--text); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 10px 2px 0; font-size: .82rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--tc, var(--none)); }
.day-panel { margin-top: 18px; }
.day-panel .page-head { margin-bottom: 8px; }
@media (max-width: 720px) {
  .cell { min-height: 58px; padding: 4px 3px; align-items: center; }
  .cell .num { align-self: center; }
  .cell .chip, .cell .more { display: none; }
  .dots { display: flex; justify-content: center; }
  .cal-week span { text-align: center; padding: 4px 0; }
  .cal-nav h1 { font-size: 1.15rem; }
  .cal-filters { width: 100%; }
  .cal-filters select { flex: 1 1 130px; min-width: 0; }
  .row select { flex-basis: 110px; }
}

/* ---------- cards and lists ---------- */
.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; align-items: start; }
.col { background: var(--surface-2); border-radius: 12px; padding: 10px; min-width: 0; }
.col-head { display: flex; align-items: baseline; gap: 8px; padding: 2px 4px 8px; }
.col-head .count { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.list { display: flex; flex-direction: column; gap: 8px; }
.empty { padding: 14px 8px; text-align: center; color: var(--muted); font-size: .9rem; }
.card {
  display: flex; gap: 10px; padding: 10px 12px 10px 10px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--tc, var(--none));
  border-radius: 10px; box-shadow: var(--shadow); cursor: pointer; min-width: 0;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); border-left-color: var(--tc, var(--none)); }
.card.is-done { opacity: .7; box-shadow: none; }
.card.is-done .card-title { text-decoration: line-through; color: var(--muted); }
.card-body { min-width: 0; flex: 1 1 auto; }
.card-title { display: block; width: 100%; padding: 0; background: none; border: 0; text-align: left; font-weight: 600; cursor: pointer; overflow-wrap: anywhere; }
.checkbox {
  flex: none; width: 22px; height: 22px; margin-top: 1px; padding: 0;
  display: grid; place-items: center; cursor: pointer;
  background: var(--surface); border: 2px solid var(--muted); border-radius: 50%; color: transparent; font-size: .8rem;
}
.checkbox:hover { border-color: var(--ok); color: var(--ok); }
.checkbox.on { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 6px; margin-top: 6px; font-size: .8rem; color: var(--muted); }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tag.type { background: color-mix(in srgb, var(--tc, var(--none)) 16%, var(--surface)); color: var(--text); }
.tag.urgent { background: var(--danger); color: var(--surface); font-weight: 700; }
.tag.late { background: var(--danger-soft); color: var(--danger); font-weight: 700; }
.tag.soon { background: var(--warn-soft); color: var(--warn); font-weight: 700; }
.tag.state { box-shadow: inset 0 0 0 1px var(--border); background: none; }
.who { display: inline-flex; align-items: center; gap: 5px; }
.who .avatar { width: 20px; height: 20px; font-size: .6rem; }

.ship-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.ship-card {
  display: flex; flex-direction: column; gap: 8px; padding: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  text-decoration: none; color: inherit;
}
.ship-card:hover { border-color: var(--accent); }
.ship-card.closed { opacity: .7; }
.ship-card strong { font-size: 1.02rem; overflow-wrap: anywhere; }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ok); border-radius: 999px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); margin-bottom: 16px; }
.panel > h2 { margin-bottom: 10px; }
.details-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.two-col { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 10px; text-decoration: none; font-weight: 600; }

/* ---------- notes, history, activity ---------- */
.note-form { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; margin-bottom: 10px; }
.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.log li { font-size: .9rem; }
.log .note { padding: 8px 10px; background: var(--surface-2); border-radius: 10px; }
.log .note-head { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); margin-bottom: 2px; }
.log .note-head b { color: var(--text); }
.log .note-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.log .event { color: var(--muted); font-size: .82rem; padding-left: 10px; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; align-items: baseline; padding: 9px 2px; border-bottom: 1px solid var(--border); }
.feed li:last-child { border-bottom: 0; }
.feed .when { flex: none; width: 76px; color: var(--muted); font-size: .8rem; }
.feed .what { min-width: 0; overflow-wrap: anywhere; }
.feed button.what { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
.feed button.what:hover { text-decoration: underline; }

/* ---------- tables (people and settings) ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 8px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { margin-left: 4px; }
.rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row .swatch { flex: none; width: 12px; height: 12px; border-radius: 3px; background: var(--tc, var(--none)); }
.row select { flex: 0 1 250px; min-width: 0; }
.row input[type=number] { flex: 0 0 76px; }
.row-head { display: flex; gap: 8px; font-size: .78rem; font-weight: 600; color: var(--muted); }

/* ---------- dialogs ---------- */
dialog.dlg {
  width: min(600px, calc(100vw - 20px)); max-height: calc(100dvh - 20px);
  padding: 0; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog.dlg.narrow { width: min(420px, calc(100vw - 20px)); }
dialog.dlg::backdrop { background: rgba(10, 15, 25, .5); }
.dlg-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; padding: 12px 10px 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.dlg-head h2 { flex: 1 1 auto; }
.dlg-body { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.dlg-actions { display: flex; gap: 8px; align-items: center; }
.dlg-section { border-top: 1px solid var(--border); padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
@media (max-width: 360px) { .form-grid { grid-template-columns: 1fr; } }
.card, .cell, .chip, .stat, .ship-card { -webkit-tap-highlight-color: transparent; }

/* ---------- files ---------- */
.tag.pub { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.chip > svg.ic { flex: none; opacity: .8; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file { display: flex; align-items: center; gap: 10px; padding: 6px 4px 6px 8px; background: var(--surface-2); border-radius: 10px; min-width: 0; }
.file.failed { background: var(--danger-soft); }
.file.failed .small { color: var(--danger); }
.file-main { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.file-name { overflow-wrap: anywhere; text-align: left; font-weight: 600; }
a.file-name { text-decoration: underline; }
.file-thumb { flex: none; width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--surface); }
.file-thumb.ext { display: grid; place-items: center; font-size: .62rem; font-weight: 800; letter-spacing: .03em; color: var(--muted); box-shadow: inset 0 0 0 1px var(--border); }
.file-thumb.ext.k-pdf { color: var(--danger); }
.file-thumb.ext.k-video, .file-thumb.ext.k-audio { color: var(--c2); }
.file-thumb.ext.k-image { color: var(--ok); }
.dropzone { display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1.5px dashed var(--border); border-radius: 10px; }
.dropzone-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.dropzone.drop, .dropzone-section.drop { background: var(--accent-soft); outline: 2px dashed var(--accent); outline-offset: 2px; border-radius: 10px; }
.uploads { display: flex; flex-direction: column; gap: 6px; }
.uploads:empty { display: none; }
.upload { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; font-size: .9rem; }
.upload-top { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.upload .pct { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; }
.upload .progress { background: var(--surface); }
.upload .progress i { background: var(--accent); width: 0; transition: width .2s; }
.upload.failed { flex-direction: row; align-items: baseline; background: var(--danger-soft); color: var(--danger); overflow-wrap: anywhere; }
dialog.dlg.preview { width: min(980px, calc(100vw - 20px)); }
.preview .dlg-head h2 { font-size: 1rem; overflow-wrap: anywhere; min-width: 0; }
.preview-body { padding: 12px; display: grid; place-items: center; background: var(--surface-2); }
.preview-body img, .preview-body video { max-width: 100%; max-height: calc(100dvh - 130px); border-radius: 6px; }
.preview-body audio { width: 100%; }
.dlg-head a.btn { text-decoration: none; color: inherit; }
a.icon-btn { text-decoration: none; }

/* ---------- sign in ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px 16px; }
.auth-card { width: min(400px, 100%); padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.auth-card .brand { font-size: 1.2rem; }
.auth-card .brand img { width: 34px; height: 34px; }
.error { padding: 8px 10px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-size: .9rem; }

/* ---------- toast ---------- */
#toast { position: fixed; inset: auto auto 20px 50%; margin: 0; padding: 0; border: 0; background: none; overflow: visible; transform: translateX(-50%); z-index: 2147483647; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 24px); }
#toast div { padding: 9px 14px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: .9rem; box-shadow: var(--shadow); }
#toast div.bad { background: var(--danger); color: var(--surface); }
.offline { background: var(--warn-soft); color: var(--warn); text-align: center; font-size: .85rem; padding: 4px 12px; }
