:root {
  color-scheme: light;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(12, 28, 56, 0.08);
  --line-strong: rgba(12, 28, 56, 0.14);
  --bg: #f5f5f7;
  --accent: #0b2f6b;
  --accent-hover: #16408a;
  --selected: #e7eef8;
  --danger: #a4262c;
  --shadow: 0 1px 2px rgba(11, 47, 107, 0.04), 0 12px 32px rgba(11, 47, 107, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.45 var(--font);
  letter-spacing: -0.011em;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: var(--ink); }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
}
.login-card {
  width: min(400px, 100%);
  background: #fff;
  border: 0;
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-card h1 { margin: 0 0 22px; font-size: 28px; font-weight: 650; letter-spacing: -0.03em; }
.login-card label { display: block; font-weight: 600; margin-bottom: 14px; }
.login-card input, .ghost, .primary, .danger {
  border-radius: 980px;
}
.login-card input, #delete-word, #clear-word {
  display: block;
  width: 100%;
  height: 44px;
  margin-top: 6px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fff;
  font-weight: 400;
}
.login-card input:focus, #delete-word:focus, #clear-word:focus { border-color: var(--accent); outline: none; }
.primary, .danger {
  height: 40px;
  border: 0;
  color: #fff;
  font-weight: 600;
  padding: 0 18px;
}
.primary { background: var(--accent); }
.primary:hover { background: var(--accent-hover); }
.danger { background: var(--danger); }
.danger:hover { background: #8e1c22; }
.danger:disabled { opacity: 0.45; cursor: default; }
.login-card .primary { width: 100%; margin-top: 8px; }
.form-error { color: var(--danger); margin: 0 0 12px; }

.shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
  grid-template-rows: 64px minmax(0, 1fr);
}
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: rgba(251, 251, 253, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.brand { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.03em; }
.account { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  flex: 0 0 auto;
}

.nav {
  background: #fbfbfd;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 8px 0;
}
.nav button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 40px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  padding: 0 12px 0 13px;
  text-align: left;
}
.nav button:hover { background: var(--selected); }
.nav button.is-active { background: var(--selected); border-left-color: var(--accent); font-weight: 600; color: var(--accent); }
.nav svg { flex: 0 0 auto; }

.workspace { display: flex; min-width: 0; min-height: 0; }
.content { flex: 1; min-width: 0; overflow: auto; padding: 24px 28px 48px; }
.panel {
  width: min(720px, 56vw);
  background: #fbfbfd;
  border-left: 1px solid var(--line);
  overflow: auto;
  box-shadow: -8px 0 24px rgba(0, 0, 0, .04);
}

.page-head { margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.command { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.ghost {
  height: 40px;
  border: 1px solid var(--line-strong);
  background: #fff;
  padding: 0 16px;
}
.ghost:hover { background: #f5f5f5; }
.chips { display: flex; gap: 4px; }
.chip {
  height: 32px;
  border: 0;
  background: transparent;
  border-radius: 16px;
  padding: 0 12px;
  color: var(--ink);
}
.chip:hover { background: #f5f5f5; }
.chip.is-active { background: var(--accent); color: #fff; font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 8px 0 28px; }
.stat {
  text-align: left;
  background: #fff;
  border: 0;
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.stat:hover { border-color: var(--accent); }
.stat b { display: block; font-size: 32px; font-weight: 600; line-height: 1.15; }
.stat span { color: var(--muted); }

.section-title { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.table-wrap { background: #fff; border: 0; border-radius: 18px; box-shadow: var(--shadow); overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
td, th { padding: 14px 18px; text-align: left; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
td:first-child, th:first-child { padding-left: 20px; }
td:last-child, th:last-child { padding-right: 20px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f5f5f5; }
tbody tr.is-selected { background: var(--selected); }
.who, .name { display: flex; flex-direction: column; min-width: 0; }
.who { flex-direction: row; align-items: center; gap: 12px; }
.name { gap: 4px; }
.who span, .name { min-width: 0; }
.who-text { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 14px; row-gap: 6px; }
.who strong, .name strong { font-weight: 600; }
.who small, .name small, .muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
a { color: var(--accent); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; }
.order-cell { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: #f0f0f0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.order { background: var(--selected); color: var(--accent); }
.badge.paid { background: #f1faf1; color: #0e700e; }
.badge.open, .badge.draft { background: #fff4ce; color: #8a6116; box-shadow: inset 0 0 0 1px #e6d48a; }
.draft-note { margin: 0 0 16px; padding: 12px 14px; border-radius: 14px; background: #fff4ce; color: #6d5310; font-weight: 600; }

.banner { margin: 0 0 12px; padding: 10px 12px; background: #fff4ce; border: 1px solid #f7e29c; border-radius: 4px; }
.banner.error { background: #fdf3f4; border-color: #f1bbbc; color: var(--danger); }
.empty { color: var(--muted); padding: 28px 4px; }

.panel-head { display: flex; justify-content: space-between; gap: 12px; padding: 20px 16px 8px 20px; }
.panel-head h2 { margin: 0; font-size: 20px; font-weight: 600; word-break: break-word; }
.panel-head p { margin: 4px 0 0; color: var(--muted); }
.icon-button { width: 32px; height: 32px; flex: 0 0 auto; border: 0; background: transparent; font-size: 20px; line-height: 1; }
.icon-button:hover { background: #f5f5f5; }
.pivots { display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.pivots button { height: 40px; border: 0; border-bottom: 2px solid transparent; background: transparent; padding: 0 8px; }
.pivots button.is-active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
.facts { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 8px 12px; margin: 0; padding: 16px 20px 8px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }
.list { list-style: none; margin: 0; padding: 4px 8px 24px; }
.list button {
  display: flex;
  flex-direction: column;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid #f3f2f1;
  background: transparent;
  padding: 10px 8px;
}
.list button:hover { background: #f5f5f5; }
.card { margin: 12px 16px; border: 0; border-radius: 18px; box-shadow: var(--shadow); padding: 14px 14px 6px; background: #fff; }
.card h3 { margin: 4px 0 8px; font-size: 13px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.card header { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.card .facts { padding: 12px 0 8px; }
.people { margin: 0 0 12px; padding-left: 18px; }
.people li { margin: 8px 0; }
.file-links { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.file-links .ghost { height: 28px; padding: 0 10px; font-size: 12px; }
.file-links .ghost.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }
.file-download { color: var(--accent); font-size: 12px; font-weight: 650; }
.card .preview-frame { width: 100%; height: 70vh; margin: 8px 0 4px; }
.card .danger-row { margin: 8px 0 12px; }
.page-mark {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 980px;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0;
  vertical-align: 1px;
}
.page-mark.is-open {
  background: #fff4ce;
  color: #8a6116;
  box-shadow: inset 0 0 0 1px #e6d48a;
}
.marks { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; align-items: center; }
.cadence-mark {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--selected);
  color: var(--accent);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  vertical-align: 1px;
}
.people .cadence-mark { margin-left: 8px; }
.cadence-mark.weekly { background: var(--accent); color: white; }
.cadence-mark.monthly { background: #e7f6ee; color: #0e700e; box-shadow: inset 0 0 0 1px #b7e0c2; }
.cadence-mark.mixed { background: #fff4ce; color: #8a6116; box-shadow: inset 0 0 0 1px #e6d48a; }
.note { margin: 0 0 12px; padding: 8px 10px; background: var(--bg); white-space: pre-wrap; }
dialog {
  width: min(420px, 100%);
  background: #fff;
  border: 0;
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  color: var(--ink);
}
dialog::backdrop { background: rgba(11, 47, 107, 0.28); }
dialog h2 { margin: 0 0 8px; font-size: 22px; letter-spacing: -0.03em; }
dialog p { margin: 0 0 14px; }
dialog label { display: block; font-weight: 600; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.wipe { margin-top: 28px; padding: 16px 18px; background: #fff; border-radius: 18px; box-shadow: var(--shadow); }
.wipe p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.danger-row { margin: 8px 16px 24px; padding-top: 12px; border-top: 1px solid var(--line); }
.danger-row p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.preview-frame {
  display: block;
  width: calc(100% - 32px);
  height: 72vh;
  margin: 12px 16px 20px;
  border: 1px solid var(--line);
  background: #525659;
}

@media (max-width: 1100px) {
  .workspace { position: relative; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel:not([hidden]) {
    position: absolute;
    inset: 0;
    z-index: 4;
    width: 100%;
    border-left: 0;
    box-shadow: none;
  }
  td, th { padding: 12px 14px; }
  .content { padding: 20px 16px 36px; }
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  }
  .login-card input, #delete-word, #clear-word { font-size: 16px; }
  .account { margin-left: auto; }
  .ghost, .primary, .danger, .chip { min-height: 44px; }
  .nav {
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0;
  }
  .nav button {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    min-height: 56px;
    height: auto;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    border-left: 0;
    border-bottom: 3px solid transparent;
    padding: 6px 6px;
    font-size: 12px;
    line-height: 1.15;
    text-align: center;
    white-space: normal;
  }
  .nav button.is-active { border-bottom-color: var(--accent); border-left-color: transparent; }
  .workspace { position: relative; flex-direction: column; }
  .content { padding: 16px 12px 28px; }
  .panel {
    width: 100%;
    border-left: 0;
    border-top: 1px solid var(--line);
    box-shadow: none;
  }
  .panel:not([hidden]) {
    position: absolute;
    inset: 0;
    z-index: 4;
    border-top: 0;
  }
  .page-head h1 { font-size: 24px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 14px; }
  .stat b { font-size: 26px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  td, th { white-space: nowrap; }
  .name, .who { white-space: normal; }
  .facts { grid-template-columns: 1fr; gap: 2px 0; padding: 12px 16px 8px; }
  .facts dt { margin-top: 10px; }
  .pivots { overflow: auto; }
  .pivots button { flex: none; min-height: 44px; }
  .preview-frame { width: calc(100% - 24px); height: 62dvh; margin: 12px; }
  .login-card { padding: 28px 20px; }
  dialog {
    width: min(420px, calc(100% - 24px));
    max-height: calc(100dvh - 24px);
    margin: auto;
  }
  .dialog-actions { flex-direction: column; }
  .dialog-actions .ghost, .dialog-actions .danger { width: 100%; min-height: 44px; white-space: nowrap; }
  .icon-button { width: 44px; height: 44px; }
}
