:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --border: #e3e6ee;
  --text: #1c2030;
  --muted: #6b7185;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --ok: #059669;
  --ok-soft: #d9f7ea;
  --warn: #b45309;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 8px 24px rgba(20, 24, 40, .06);
  --radius: 14px;
  --cell-h: 20px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171a23;
    --surface-2: #1f2330;
    --border: #2a2f3e;
    --text: #e8eaf2;
    --muted: #9aa0b4;
    --accent: #818cf8;
    --accent-soft: #252a4a;
    --accent-text: #0f1117;
    --danger: #f87171;
    --ok: #34d399;
    --ok-soft: #123528;
    --warn: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 28px; letter-spacing: -.02em; }
h2 { font-size: 20px; letter-spacing: -.01em; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

button, .btn {
  font: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .12s, border-color .12s, transform .05s;
}
button:hover, .btn:hover { background: var(--surface-2); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover, .btn.primary:hover { filter: brightness(1.07); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.danger { color: var(--danger); }
button.icon { padding: 7px 10px; }
button.sm, .btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; color: var(--text); }
.brand .logo {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #06b6d4); color: #fff; font-size: 15px;
}
.project-name { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.keychip {
  display: inline-flex; align-items: center; gap: 6px;
  font: 600 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 6px 4px 12px;
}
.keychip button { padding: 3px 9px; font-size: 12px; border-radius: 999px; }
.sync { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }

main { max-width: 1240px; margin: 0 auto; padding: 20px 16px 60px; }

/* ---- home ---- */
.hero { text-align: center; padding: 36px 0 24px; }
.hero p { font-size: 17px; margin: 10px auto 0; max-width: 560px; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; max-width: 760px; margin: 0 auto; }
.home-grid .card h2 { margin-bottom: 4px; }
.recent { max-width: 760px; margin: 24px auto 0; }
.recent-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; }
.recent-item:hover { background: var(--surface-2); }
.recent-item a { font-weight: 600; text-decoration: none; color: var(--text); flex: 1; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.error { color: var(--danger); font-size: 14px; }
.how { max-width: 760px; margin: 28px auto 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.how div { padding: 14px; border-radius: 12px; background: var(--surface-2); font-size: 14px; }
.how b { display: block; margin-bottom: 3px; }

/* ---- project layout ---- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
@media (max-width: 960px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.layout > * { min-width: 0; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .week-label { font-weight: 700; font-size: 17px; margin: 0 6px; }
.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border-radius: 12px; margin-bottom: 12px;
  background: var(--accent-soft); border: 1px solid var(--border); border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

/* ---- calendar ---- */
.cal-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.cal-scroll { overflow: auto; max-height: calc(100vh - 210px); max-height: calc(100dvh - 210px); min-height: 360px; -webkit-overflow-scrolling: touch; }
.cal { display: grid; grid-template-columns: 56px repeat(7, minmax(84px, 1fr)); min-width: 660px; position: relative; }
@media (max-width: 600px) { .cal { grid-template-columns: 48px repeat(7, minmax(64px, 1fr)); min-width: 500px; } .project-name { max-width: 55vw; } }
.cal-head {
  position: sticky; top: 0; z-index: 5; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: 8px 4px; text-align: center; font-size: 13px;
}
.cal-head .dname { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .05em; }
.cal-head .dnum { font-size: 18px; font-weight: 700; }
.cal-head.today .dnum { color: var(--accent); }
.cal-head.corner { position: sticky; left: 0; z-index: 6; }
.times { position: sticky; left: 0; z-index: 3; background: var(--surface); border-right: 1px solid var(--border); }
.times div { height: var(--cell-h); font-size: 11px; color: var(--muted); text-align: right; padding-right: 6px; transform: translateY(-7px); }
.col { position: relative; border-right: 1px solid var(--border); }
.col:last-child { border-right: 0; }
.cell {
  height: var(--cell-h); border-bottom: 1px solid transparent; display: flex; gap: 3px; padding: 0 4px;
  cursor: pointer; position: relative;
}
.cell.hour { border-bottom-color: var(--border); }
.cell.half { border-bottom: 1px dashed var(--border); border-bottom-color: color-mix(in srgb, var(--border) 60%, transparent); }
@media (hover: hover) { .cell:hover { background: var(--surface-2); } }
.cell .bar { flex: 1 1 0; max-width: 14px; opacity: .85; }
.cell.all { background: var(--ok-soft); }
@media (hover: hover) { .cell.all:hover { background: var(--ok-soft); background: color-mix(in srgb, var(--ok) 25%, var(--surface)); } }
.cell.all::after { content: ""; position: absolute; inset: 0; border-left: 3px solid var(--ok); pointer-events: none; }
.cell.past { opacity: .45; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 2; pointer-events: none; }
.now-line::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.mtg {
  position: absolute; left: 4px; right: 4px; z-index: 4; border-radius: 7px; padding: 3px 6px; overflow: hidden;
  background: var(--accent); color: var(--accent-text); font-size: 12px; line-height: 1.25; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .18); border: 1px solid rgba(0, 0, 0, .15);
}
.mtg b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-foot { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; padding: 10px 14px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.swatch-all { display: inline-block; width: 14px; height: 14px; border-radius: 3px; background: var(--ok-soft); border-left: 3px solid var(--ok); vertical-align: -2px; }

/* ---- side panel ---- */
.side .card { padding: 16px; }
.side .card + .card { margin-top: 16px; }
.side h3 { margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; }
.person { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 10px; }
.person:hover { background: var(--surface-2); }
.person .who { flex: 1; min-width: 0; cursor: pointer; }
.person .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .who span { font-size: 12px; color: var(--muted); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none;
  color: #fff; font-weight: 700; font-size: 13px;
}
.toggle { width: 18px; height: 18px; accent-color: var(--accent); flex: none; width: auto; cursor: pointer; }
.you-tag { font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 1px 6px; border-radius: 999px; margin-left: 4px; }
.meeting-item { padding: 9px 10px; border-radius: 10px; cursor: pointer; border-left: 3px solid var(--accent); background: var(--surface-2); }
.meeting-item + .meeting-item { margin-top: 8px; }
.meeting-item b { display: block; }
.meeting-item span { font-size: 12px; color: var(--muted); }

/* ---- modal ---- */
.modal-back {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 12, 20, .45);
  display: flex; align-items: flex-start; justify-content: center; padding: 5vh 12px; overflow: auto;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  width: 100%; max-width: 560px; padding: 22px; position: relative;
}
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.modal-head h2 { flex: 1; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.modal-foot .left { margin-right: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 28px; height: 28px; padding: 0; border-radius: 50%; border: 2px solid transparent; }
.swatches button.sel { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface); }

/* availability editor */
.avail-tools { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.avail-scroll { max-height: 46vh; overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.avail { display: grid; grid-template-columns: 50px repeat(7, 1fr); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
.avail.touch-painting .c { cursor: crosshair; }
.avail.touch-painting { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 12px; }
.avail .h { position: sticky; top: 0; background: var(--surface); z-index: 2; text-align: center; font-size: 12px; font-weight: 700; padding: 6px 0; border-bottom: 1px solid var(--border); }
.avail .t { font-size: 10px; color: var(--muted); text-align: right; padding-right: 5px; height: 16px; line-height: 16px; }
.avail .c { height: 16px; border-left: 1px solid var(--border); cursor: pointer; }
.avail .c.hr { border-top: 1px solid var(--border); }
.avail .c.on { background: var(--sel, var(--accent)); opacity: .85; }

/* profile view */
.avail-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.avail-table th, .avail-table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.avail-table th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.facts div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.facts span { display: block; font-size: 12px; color: var(--muted); }
.facts b { font-size: 15px; }

/* meeting form attendees */
.attendees { border: 1px solid var(--border); border-radius: 12px; max-height: 240px; overflow: auto; }
.att { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--border); cursor: pointer; }
.att:last-child { border-bottom: 0; }
.att .grow { min-width: 0; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.pill.free { background: var(--ok-soft); color: var(--ok); }
.pill.busy { background: rgba(217, 119, 6, .16); color: var(--warn); }
.linkbox { display: flex; gap: 8px; }
.linkbox input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow);
}

/* ---- invite page ---- */
.invite { max-width: 620px; margin: 0 auto; padding: 32px 16px 60px; }
.invite .card { padding: 28px; }
.invite .when { font-size: 20px; font-weight: 700; margin-top: 14px; }
.invite .kv { margin-top: 14px; font-size: 15px; }
.invite .kv span { color: var(--muted); display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.cal-buttons { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; margin-top: 12px; }
.cal-buttons .btn { text-align: left; justify-content: flex-start; padding: 12px 14px; gap: 12px; font-weight: 600; }
.cal-buttons .btn small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.cal-buttons .btn .ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: #fff; font-size: 14px; font-weight: 800; flex: none; }
.cal-buttons .btn.suggested { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.badge { display: inline-block; font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 2px 7px; border-radius: 999px; margin-left: 6px; vertical-align: 1px; }
.notes { white-space: pre-wrap; }
footer.site { text-align: center; color: var(--muted); font-size: 13px; padding: 20px; }


/* searchable time zone picker */
.tzp { position: relative; }
.tzp.compact { width: 320px; max-width: 100%; }
.tzp.compact input { padding: 6px 10px; font-size: 13px; }
.tzp-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 70; margin: 0; padding: 4px; list-style: none;
  max-height: 280px; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.tzp.compact .tzp-list { min-width: 300px; }
.tzp-list li { padding: 7px 10px; border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; font-size: 14px; color: var(--text); }
.tzp-list li small { color: var(--muted); font-size: 12px; }
.tzp-list li.active { background: var(--accent-soft); }
.tzp-list li.sel span { font-weight: 700; }
.tzp-list li.empty { color: var(--muted); cursor: default; }

/* hover tooltip */
.tip {
  position: fixed; left: 0; top: 0; z-index: 90; pointer-events: none; opacity: 0; transition: opacity .08s;
  background: var(--text); color: var(--bg); border-radius: 9px; padding: 7px 10px; font-size: 13px; line-height: 1.35;
  max-width: 280px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.tip.show { opacity: 1; }
.tip-head { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.tip-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px var(--bg); }
.tip-body { white-space: pre-line; opacity: .85; }
@media (hover: none) { .tip { display: none; } }

.att-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.att-tools .att-search { flex: 1 1 180px; width: auto; padding: 6px 10px; font-size: 14px; }

/* Phones: 16px inputs stop iOS from zooming on focus; roomier tap targets. */
@media (pointer: coarse), (max-width: 600px) {
  input, select, textarea { font-size: 16px; }
  .tzp.compact input, .att-tools .att-search { font-size: 16px; }
  .avail .c, .avail .t { height: 22px; line-height: 22px; }
  button.sm, .btn.sm { padding: 7px 11px; }
}
@media (max-width: 600px) {
  main { padding: 12px 10px 40px; }
  .modal-back { padding: 10px 8px; }
  .modal { padding: 16px; border-radius: 16px; }
  .toolbar .week-label { font-size: 15px; }
  .topbar { gap: 8px; padding: 8px 10px; }
  .tzp.compact .tzp-list { min-width: 0; }
  .hero { padding: 20px 0 16px; }
  h1 { font-size: 24px; }
}

button, .btn, a, .cell, .avail .c, .person .who, .meeting-item { -webkit-tap-highlight-color: transparent; }
@media (max-width: 600px) {
  .topbar .brand-name, .topbar .sep { display: none; }
  .topbar .project-name { flex: 1 1 45%; min-width: 0; max-width: none; }
  .topbar > button { order: 1; padding: 6px 8px; }
  .topbar .me-name { display: none; }
  .topbar .keychip, .topbar .sync { order: 2; }
  .topbar .grow { display: none; }
  .toolbar .tz-note { order: 10; flex-basis: 100%; }
  .toolbar .primary { margin-left: auto; }
}
