:root {
  color-scheme: light;
  --ink: #18201d;
  --muted: #66706b;
  --line: #dce2df;
  --line-strong: #c4ceca;
  --surface: #ffffff;
  --surface-soft: #f5f7f6;
  --canvas: #eef2f0;
  --brand: #146b4a;
  --brand-hover: #0f573c;
  --danger: #ad352e;
  --danger-soft: #fff1ef;
  --warning: #966100;
  --warning-soft: #fff7df;
  --info: #285d92;
  --info-soft: #edf5fc;
  --sidebar: #202925;
  --sidebar-muted: #a9b5af;
  --radius: 6px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { min-width: 320px; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: .58; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(20, 107, 74, .24);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 28px 18px; background: var(--surface-soft); }
.login-panel { width: min(100%, 390px); padding: 32px; border: 1px solid var(--line); border-top: 3px solid var(--brand); border-radius: var(--radius); background: var(--surface); box-shadow: 0 12px 35px rgba(23, 35, 29, .08); }
.brand-mark { display: inline-grid; place-items: center; width: 44px; height: 44px; margin-bottom: 24px; border-radius: 4px; background: var(--brand); color: white; font-weight: 700; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 12px; font-weight: 600; }
.login-panel h1 { margin: 0 0 8px; font-size: 24px; line-height: 1.3; }
.muted { color: var(--muted); }
.login-panel > .muted { margin: 0 0 26px; }

.form-stack { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: #39433f; font-size: 13px; font-weight: 600; }
input, select, textarea { width: 100%; min-height: 38px; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--surface); color: var(--ink); padding: 8px 10px; }
textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
input::placeholder, textarea::placeholder { color: #909994; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-note { margin: -2px 0 0; color: var(--muted); font-size: 12px; font-weight: 400; }
.form-error { margin: 0; padding: 10px 12px; border-left: 3px solid var(--danger); background: var(--danger-soft); color: #7d2924; line-height: 1.45; overflow-wrap: anywhere; }

.button { min-height: 36px; border: 1px solid var(--line-strong); border-radius: 4px; padding: 7px 13px; background: var(--surface); color: var(--ink); font-weight: 600; }
.button:hover:not(:disabled) { background: var(--surface-soft); border-color: #9eaaa4; }
.button.primary { border-color: var(--brand); background: var(--brand); color: white; }
.button.primary:hover:not(:disabled) { border-color: var(--brand-hover); background: var(--brand-hover); }
.button.danger { border-color: #e6b8b3; color: var(--danger); }
.button.quiet { border-color: transparent; background: transparent; }
.button.wide { width: 100%; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.text-button { border: 0; padding: 0; background: none; color: var(--brand); font-weight: 600; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; z-index: 20; display: flex; flex-direction: column; padding: 20px 14px 14px; background: var(--sidebar); color: white; }
.sidebar-brand { display: grid; gap: 3px; padding: 0 10px 20px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-brand strong { font-size: 16px; }
.sidebar-brand span { color: var(--sidebar-muted); font-size: 12px; }
.main-nav { display: grid; gap: 4px; margin-top: 18px; }
.nav-button { width: 100%; min-height: 40px; border: 0; border-radius: 4px; padding: 9px 12px; background: transparent; color: #d6ded9; text-align: left; font-weight: 600; }
.nav-button:hover { background: rgba(255,255,255,.07); }
.nav-button.active { background: #e7f2ed; color: #125a40; }
.sidebar-foot { margin-top: auto; padding: 14px 10px 2px; color: var(--sidebar-muted); font-size: 11px; }
.shell-main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 10; min-height: 68px; display: flex; align-items: center; gap: 12px; padding: 10px 24px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.97); }
.topbar h1 { margin: 0; font-size: 19px; line-height: 1.25; }
.account-wrap { position: relative; margin-left: auto; }
.account-button { min-height: 38px; max-width: 240px; border: 1px solid var(--line); border-radius: 4px; padding: 7px 11px; background: var(--surface); color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-menu { position: absolute; right: 0; top: calc(100% + 7px); z-index: 30; width: 230px; padding: 7px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 10px 28px rgba(24,32,29,.14); }
.account-menu button { width: 100%; border: 0; border-radius: 3px; padding: 9px 10px; background: transparent; text-align: left; }
.account-menu button:hover { background: var(--surface-soft); }
.account-identity { padding: 8px 10px 11px; margin-bottom: 4px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.account-identity strong, .account-identity span { display: block; }
.account-identity span { margin-top: 3px; color: var(--muted); font-size: 12px; }

.workspace { width: min(100%, 1460px); margin: 0 auto; padding: 22px 24px 40px; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.view-head h2 { margin: 0 0 3px; font-size: 17px; }
.view-head p { margin: 0; color: var(--muted); font-size: 13px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.load-more-row { margin-top: 12px; }
.surface { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 10px 12px; background: var(--surface-soft); color: #505b56; text-align: left; font-size: 12px; font-weight: 700; white-space: nowrap; }
td { padding: 11px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: #fafcfb; }
.unread-row { background: var(--info-soft); }
.clickable-row { cursor: pointer; }
.clickable-row:focus-visible { outline: 3px solid rgba(20,107,74,.22); outline-offset: -3px; }
.cell-main { min-width: 190px; }
.cell-main strong, .cell-main span { display: block; }
.cell-main span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.nowrap { white-space: nowrap; }
.hash-text { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--muted); }
.json-preview { max-height: 52vh; margin: 0; overflow: auto; padding: 12px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface-soft); font: 12px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.tag { display: inline-flex; align-items: center; min-height: 24px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; background: var(--surface-soft); color: #46514c; font-size: 12px; white-space: nowrap; }
.tag.high, .tag.urgent, .tag.cancelled { border-color: #edc7c3; background: var(--danger-soft); color: #8a302a; }
.tag.active, .tag.done { border-color: #bfdbce; background: #edf7f2; color: #176046; }
.tag.review { border-color: #c7d9e9; background: var(--info-soft); color: var(--info); }
.state-panel { min-height: 280px; display: grid; place-items: center; padding: 40px 20px; text-align: center; }
.state-panel > div { max-width: 420px; }
.state-panel h3 { margin: 0 0 7px; font-size: 16px; }
.state-panel p { margin: 0 0 16px; color: var(--muted); line-height: 1.6; }
.loading-line { width: 180px; height: 4px; margin: 18px auto 0; border-radius: 2px; background: var(--line); overflow: hidden; }
.loading-line::after { content: ""; display: block; width: 45%; height: 100%; background: var(--brand); animation: loading 1s ease-in-out infinite alternate; }
@keyframes loading { from { transform: translateX(-80%); } to { transform: translateX(200%); } }

.scrim { position: fixed; inset: 0; z-index: 39; background: rgba(12, 18, 15, .38); }
.drawer { position: fixed; inset: 0 0 0 auto; z-index: 40; width: min(560px, 100%); overflow-y: auto; border-left: 1px solid var(--line); background: var(--surface); box-shadow: -12px 0 35px rgba(20,30,25,.14); transform: translateX(102%); transition: transform .2s ease; }
.drawer.open { transform: translateX(0); }
.drawer-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.drawer-head > div { min-width: 0; flex: 1; }
.drawer-head h2 { margin: 2px 0 3px; font-size: 18px; overflow-wrap: anywhere; }
.drawer-head p { margin: 0; color: var(--muted); font-size: 12px; }
.drawer-body { padding: 20px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.detail-item span, .detail-item strong { display: block; }
.detail-item span { margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.detail-item strong { overflow-wrap: anywhere; }
.detail-description { grid-column: 1 / -1; line-height: 1.55; white-space: pre-wrap; }
.drawer-section { padding: 20px 0; border-bottom: 1px solid var(--line); }
.drawer-section:last-child { border-bottom: 0; }
.drawer-section h3 { margin: 0 0 12px; font-size: 14px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 19px; border-left: 1px solid var(--line-strong); }
.timeline li:last-child { padding-bottom: 0; border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -4px; top: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); }
.timeline strong { display: block; margin-bottom: 3px; }
.timeline p { margin: 4px 0; color: #48534e; line-height: 1.5; }
.timeline time { color: var(--muted); font-size: 12px; }
.notice { padding: 10px 12px; border-left: 3px solid var(--info); background: var(--info-soft); color: #234f79; line-height: 1.5; }
.notice.warning { border-left-color: var(--warning); background: var(--warning-soft); color: #755000; }
.notice.error { border-left-color: var(--danger); background: var(--danger-soft); color: #7d2924; }

.modal { width: min(560px, calc(100% - 28px)); max-height: calc(100vh - 40px); margin: auto; padding: 0; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); box-shadow: 0 18px 55px rgba(12,20,16,.22); color: var(--ink); }
.modal::backdrop { background: rgba(12,18,15,.42); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 17px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { flex: 1; margin: 0; font-size: 17px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-soft); }
.assignment-list { display: grid; gap: 8px; }
.permission-editor { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 4px; }
.permission-editor h3 { grid-column: 1 / -1; margin: 0; font-size: 14px; }
.data-section { margin-top: 24px; }
.data-section > h3 { margin: 0 0 10px; font-size: 15px; }
.assignment-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.assignment-row .button { margin-bottom: 1px; }
.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 70; display: grid; gap: 8px; width: min(360px, calc(100% - 36px)); }
.toast { padding: 11px 13px; border: 1px solid #bcd8ca; border-radius: var(--radius); background: #eef8f3; color: #174f3a; box-shadow: 0 8px 24px rgba(20,30,25,.13); }
.toast.error { border-color: #e7bbb6; background: var(--danger-soft); color: #7d2924; }
.mobile-only { display: none; }

@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { position: fixed; left: 0; transform: translateX(-102%); width: min(270px, 84vw); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
  .topbar { padding: 9px 12px; }
  .workspace { padding: 16px 12px 30px; }
  .view-head { align-items: flex-start; flex-direction: column; }
  .view-head .toolbar { width: 100%; }
  .view-head .toolbar .button { flex: 1; }
  .account-button { max-width: 120px; }
  .field-row, .detail-grid { grid-template-columns: 1fr; }
  .detail-description { grid-column: auto; }
  .assignment-row { grid-template-columns: 1fr 1fr; }
  .permission-editor { grid-template-columns: 1fr; }
  .permission-editor h3 { grid-column: auto; }
  .assignment-row .button { grid-column: 1 / -1; }
  .login-panel { padding: 26px 22px; }
  .snapshot-table { border: 0; background: transparent; overflow: visible; }
  .snapshot-table table, .snapshot-table tbody { display: block; }
  .snapshot-table thead { display: none; }
  .snapshot-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; margin-bottom: 10px; padding: 15px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
  .snapshot-table td { display: block; min-width: 0; padding: 0; border: 0; white-space: normal; overflow-wrap: anywhere; }
  .snapshot-table td::before { content: attr(data-label); display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; font-weight: 700; }
  .snapshot-table .cell-main, .snapshot-table .snapshot-actions { grid-column: 1 / -1; }
  .snapshot-table .button-row .button { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
