:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --ink: #1f2328;
  --ink-2: #4b5563;
  --ink-3: #8a919c;
  --line: #e3e6eb;
  --line-2: #d0d5dc;
  --accent: #b0243a;
  --accent-ink: #ffffff;
  --blue: #2563eb;
  --green: #16a34a;
  --amber: #d97706;
  --red: #b91c1c;
  --axis: #3b3f45;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
  --serif: Georgia, 'Iowan Old Style', 'Source Serif Pro', 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 var(--sans); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--blue); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: var(--surface);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; color: var(--ink);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #000; }
.btn.danger { color: var(--red); border-color: #f1c2c2; }
.btn.danger:hover { background: #fdf0f0; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=url], input[type=email], input[type=search], select, textarea {
  border: 1px solid var(--line-2); border-radius: 6px; padding: 6px 9px; background: var(--surface); min-width: 0;
}
textarea { min-height: 80px; resize: vertical; width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid #93b4f5; outline-offset: 1px; }
input[type=color] { width: 44px; height: 32px; padding: 2px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--surface); }
label.field { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
label.field > input, label.field > select, label.field > textarea { font-weight: 400; font-size: 14px; color: var(--ink); width: 100%; }
label.check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.multi { border: 1px solid var(--line-2); border-radius: 6px; padding: 6px 8px; max-height: 160px; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 2px 8px; font-weight: 400; font-size: 13px; color: var(--ink); background: var(--surface); }
.multi label { display: flex; gap: 6px; align-items: center; cursor: pointer; }

/* ---------- Chips / badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.red { background: #fde8e8; color: var(--red); }
.badge.amber { background: #fdf1dc; color: #9a5b06; }
.badge.blue { background: #e3ecfd; color: #1d4ed8; }
.badge.green { background: #e0f4e6; color: #15803d; }
.badge.gray { background: #eceef1; color: #4b5563; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--green); }

/* ---------- App shell ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 20px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; position: sticky; top: 0; z-index: 20; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 20px; }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 8px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; cursor: pointer; font-weight: 500; color: var(--ink-2); }
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 20px 0; }
.page { padding: 16px 20px 40px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.empty { padding: 40px; text-align: center; color: var(--ink-3); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; padding: 28px; }
.login h1 { font-family: var(--serif); font-size: 26px; margin-bottom: 4px; }
.login form { display: grid; gap: 12px; margin-top: 18px; }
.error { color: var(--red); font-size: 13px; min-height: 18px; }

/* ---------- Modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(17, 24, 39, .45); display: grid; place-items: center; padding: 16px; z-index: 100; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 820px; }
.modal-head { padding: 16px 20px 10px; display: flex; gap: 12px; align-items: flex-start; }
.modal-head h2 { font-size: 18px; flex: 1; }
.modal-body { padding: 4px 20px 16px; overflow: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; }
.toast.error { background: var(--red); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 700; margin: 18px 0 8px; }

/* ---------- Timeline ---------- */
.tl { --lw: 210px; --gap: 14px; --row: 34px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 22px 16px; overflow-x: auto; }
.tl-inner { min-width: 980px; position: relative; }
.tl-title { font-family: var(--serif); font-size: 34px; font-weight: 700; letter-spacing: -.01em; }
.tl-sub { color: var(--ink-2); font-size: 15px; margin: 4px 0 14px; }
.tl-head { display: grid; grid-template-columns: var(--lw) 1fr; column-gap: var(--gap); position: relative; }
.tl-axis { background: var(--axis); color: #fff; height: 38px; position: relative; border-radius: 2px; font-size: 13px; }
.tl-axis span { position: absolute; top: 50%; transform: translate(-50%, -50%); white-space: nowrap; }
.tl-today-label { position: absolute; top: -20px; color: var(--accent); font-weight: 700; font-size: 12px; transform: translateX(-50%); }
.tl-groups { position: relative; margin-top: 12px; }
.tl-group { display: grid; grid-template-columns: var(--lw) 1fr; column-gap: var(--gap); margin-bottom: 10px; }
.tl-glabel { border-radius: 6px; color: #fff; font-weight: 700; font-size: 15px; padding: 10px 12px; display: flex; align-items: center; min-height: var(--row); line-height: 1.2; }
.tl-rows { position: relative; border-radius: 2px; padding: 6px 0; }
.tl-row { position: relative; height: var(--row); }
.tl-mark { position: absolute; top: 50%; cursor: pointer; z-index: 2; }
.tl-mark.ms { width: 18px; height: 18px; transform: translate(-50%, -50%) rotate(45deg); border: 2.5px solid currentColor; background: currentColor; }
.tl-mark.ms.hollow { background: var(--surface); }
.tl-mark.bar { height: 22px; transform: translateY(-50%); border-radius: 4px; border: 2px solid currentColor; background: currentColor; min-width: 6px; overflow: hidden; }
.tl-mark.bar.hollow { background: var(--surface); }
.tl-mark.bar .pg { position: absolute; left: 0; bottom: 0; height: 4px; background: rgba(0,0,0,.28); }
.tl-mark.bar.hollow .pg { background: currentColor; opacity: .5; }
.tl-mark.ev { width: 12px; height: 12px; border-radius: 50%; transform: translate(-50%, -50%); background: currentColor; }
.tl-mark.evbar { height: 8px; transform: translateY(-50%); border-radius: 4px; background: currentColor; opacity: .55; }
.tl-mark:hover { filter: brightness(1.1); box-shadow: 0 0 0 3px rgba(0,0,0,.08); }
.tl-label { position: absolute; top: 50%; transform: translateY(-50%); white-space: nowrap; font-size: 14px; cursor: pointer; z-index: 3; display: flex; gap: 6px; align-items: baseline; }
.tl-label b { font-weight: 650; }
.tl-label:not(.inside) { background: rgba(255, 255, 255, .82); padding: 0 5px; border-radius: 4px; margin-left: -5px; }
.tl-label.left:not(.inside) { margin-left: 0; margin-right: -5px; }
.tl-label.inside, .tl-label.inside .own, .tl-label.inside .open { color: #fff; }
.tl-label.inside b { color: #fff; }
.tl-row:has(.hollow) .tl-label.inside, .tl-row:has(.hollow) .tl-label.inside b { color: var(--ink); }
.tl-row:has(.hollow) .tl-label.inside .open { color: var(--red); }
.tl-rows { z-index: 1; }
.tl-label .own { color: var(--ink-2); font-size: 13px; }
.tl-label .open { color: var(--red); font-size: 13px; font-weight: 500; }
.tl-label.left { flex-direction: row-reverse; }
.tl-label.done b { text-decoration: line-through; text-decoration-color: rgba(0,0,0,.35); color: var(--ink-2); }
.tl-label.overdue b { color: var(--red); }
.tl-label .badge { align-self: center; }
.tl-overlay { position: absolute; top: 0; bottom: 0; left: calc(var(--lw) + var(--gap)); right: 0; pointer-events: none; }
.tl-overlay.back { z-index: 0; }
.tl-overlay.front { z-index: 4; }
.tl-grid-line { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(0,0,0,.06); }
.tl-today { position: absolute; top: -12px; bottom: 0; border-left: 2px dashed var(--accent); }
.tl-deps { position: absolute; inset: 0; overflow: visible; }
.tl-foot { margin-top: 10px; color: var(--ink-3); font-size: 12px; display: flex; gap: 12px; flex-wrap: wrap; }
.tl-legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.tl-legend i { display: inline-block; width: 10px; height: 10px; transform: rotate(45deg); margin-right: 6px; border: 2px solid var(--ink-2); }

/* ---------- Calendar ---------- */
.cal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.cal-head h2 { font-family: var(--serif); font-size: 22px; min-width: 200px; }
.cal-dows { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--line); background: var(--surface-2); }
.cal-dows div { padding: 6px 8px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.cal-week { position: relative; display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--line); min-height: 124px; }
.cal-day { border-right: 1px solid var(--line); padding: 4px 6px; cursor: default; }
.cal-day:last-child { border-right: 0; }
.cal-day.click { cursor: pointer; }
.cal-day.click:hover { background: #fafbfc; }
.cal-day.other { background: #fbfbfc; }
.cal-day.other .num { color: var(--ink-3); }
.cal-day .num { font-size: 12px; font-weight: 600; display: inline-grid; place-items: center; min-width: 22px; height: 22px; border-radius: 999px; }
.cal-day.today .num { background: var(--accent); color: #fff; }
.cal-bars { position: absolute; left: 0; right: 0; top: 28px; display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: 21px; row-gap: 2px; pointer-events: none; padding: 0 2px; }
.cal-bar { pointer-events: auto; margin: 0 2px; border-radius: 4px; font-size: 12px; padding: 0 6px; line-height: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; color: #fff; border: 1px solid transparent; }
.cal-bar.hollow { background: var(--surface) !important; color: var(--ink); }
.cal-bar.ms::before { content: '◆ '; }
.cal-bar.ev { color: var(--ink); background: var(--surface-2); }
.cal-bar.done { opacity: .55; text-decoration: line-through; }
.cal-bar.overdue { box-shadow: inset 3px 0 0 var(--red); }
.cal-more { pointer-events: auto; font-size: 11px; color: var(--ink-2); padding: 0 8px; cursor: pointer; font-weight: 600; }
.cal-more:hover { text-decoration: underline; }
.agenda { padding: 4px 0; }
.agenda-day { display: grid; grid-template-columns: 130px 1fr; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.agenda-day .d { font-weight: 600; }
.agenda-day .d.today { color: var(--accent); }
.agenda-item { display: flex; gap: 8px; align-items: center; padding: 3px 0; cursor: pointer; }
.agenda-item:hover b { text-decoration: underline; }

/* ---------- Kanban ---------- */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 14px; overflow-x: auto; align-items: start; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 200px; }
.col.drop { outline: 2px dashed var(--blue); outline-offset: -2px; }
.col-head { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 10px; padding: 0 2px; }
.col-head .n { color: var(--ink-3); font-weight: 500; }
.tcard { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--c, #999); border-radius: 6px; padding: 9px 10px; margin-bottom: 8px; cursor: pointer; box-shadow: 0 1px 1px rgba(0,0,0,.03); }
.tcard:hover { border-color: var(--line-2); box-shadow: var(--shadow); }
.tcard[draggable=true] { cursor: grab; }
.tcard .t { font-weight: 600; margin-bottom: 4px; }
.tcard .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--ink-2); }
.tcard .progress { margin-top: 6px; }

/* ---------- People / Upcoming ---------- */
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.person { padding: 14px; }
.person-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; flex: none; }
.person-head .name { font-weight: 700; }
.mini { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.mini:hover .ti { text-decoration: underline; }
.mini .ti { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini .when { color: var(--ink-2); font-size: 12px; white-space: nowrap; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { padding: 14px 16px; }
.stat .v { font-size: 28px; font-weight: 700; font-family: var(--serif); }
.stat .l { color: var(--ink-2); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat.red .v { color: var(--red); }
.stat.amber .v { color: var(--amber); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; align-items: start; }
.ws-progress { display: grid; grid-template-columns: 160px 1fr 54px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }

/* ---------- Tables ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-size: 12px; color: var(--ink-2); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); position: sticky; top: 0; cursor: default; white-space: nowrap; }
table.data th.sort { cursor: pointer; }
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: #fafbfc; }

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar { padding: 10px 12px; }
  .page, .toolbar { padding-left: 12px; padding-right: 12px; }
  .board { grid-template-columns: repeat(4, 260px); }
  .cal-week { min-height: 96px; }
}

/* ---------- Print ---------- */
@media print {
  @page { size: landscape; margin: 8mm; }
  body { background: #fff; }
  .no-print, .topbar, .toolbar, .sidebar, .toasts { display: none !important; }
  .page { padding: 0 !important; }
  .main { margin: 0 !important; }
  .tl { border: 0; padding: 0; overflow: visible; }
  .tl-inner { min-width: 0; }
  .cal, .card { box-shadow: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
