:root {
  color-scheme: light;
  --bg: oklch(0.985 0.008 78);
  --surface: oklch(0.998 0.004 80);
  --surface-muted: oklch(0.955 0.012 78);
  --ink: oklch(0.21 0.035 245);
  --muted: oklch(0.46 0.028 250);
  --line: oklch(0.86 0.018 78);
  --primary: oklch(0.42 0.13 213);
  --primary-strong: oklch(0.32 0.12 221);
  --accent: oklch(0.68 0.15 72);
  --accent-soft: oklch(0.93 0.055 83);
  --success: oklch(0.48 0.1 154);
  --shadow: 0 10px 24px oklch(0.24 0.04 240 / 0.07);
  --radius: 8px;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", ui-sans-serif, system-ui, sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, oklch(0.974 0.01 78), var(--bg) 240px),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(18px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: oklch(0.998 0.004 80 / 0.94);
  backdrop-filter: blur(18px);
}

.topbar h1,
.record-header h2,
.panel-heading h2 {
  margin: 0;
}

.topbar h1 {
  font-size: 1.52rem;
  line-height: 1.18;
  font-weight: 820;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.text-link {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--primary-strong);
  font-weight: 700;
  text-decoration: none;
  background: transparent;
}

.text-link:hover {
  border-color: var(--line);
  background: var(--surface);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(270px, 320px) minmax(0, 1fr);
  gap: 24px;
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: 20px clamp(14px, 3vw, 32px) 46px;
}

.sidebar {
  position: sticky;
  top: 92px;
  align-self: start;
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 118px);
}

.control-panel,
.record-list,
.selected-record,
.tasks-panel,
.library-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: none;
}

.control-panel {
  padding: 14px;
}

.sidebar-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.sidebar-heading h2 {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.2;
}

.sidebar-heading span {
  display: inline-flex;
  min-width: 32px;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  border: 1px solid oklch(0.72 0.055 213);
  border-radius: 999px;
  color: var(--primary-strong);
  font-size: 0.82rem;
  font-weight: 800;
  background: oklch(0.96 0.025 213);
}

.search-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.search-input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px oklch(0.42 0.13 213 / 0.15);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  background: var(--surface-muted);
}

.segment {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 760;
}

.segment.is-active {
  color: var(--surface);
  background: var(--primary);
}

.record-list {
  overflow: auto;
  padding: 8px;
  box-shadow: var(--shadow);
}

.record-month-group + .record-month-group {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.record-month-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 4px 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.record-month-heading small {
  font-size: 0.76rem;
  font-weight: 760;
}

.record-item {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 78px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 12px;
  color: var(--ink);
  text-align: left;
  background: transparent;
}

.record-item:hover,
.record-item.is-active {
  border-color: oklch(0.72 0.055 213);
  background: oklch(0.96 0.025 213);
}

.record-item strong {
  font-size: 0.98rem;
  line-height: 1.35;
}

.record-date,
.record-meta {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 680;
}

.content-area {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.content-area > *,
.sidebar > *,
.record-detail,
.record-header > div,
  .rich-text,
  .split-panels > div,
  .record-layout,
  .record-main,
  .record-aside,
  .brief-panel,
  .split-panels,
  .record-todos,
  .full-record,
  .table-wrap {
  min-width: 0;
  max-width: 100%;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
}

.metric {
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: oklch(0.998 0.004 80 / 0.86);
}

.metric-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 740;
}

.metric strong {
  font-size: 1.08rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.record-detail,
.tasks-panel,
.library-panel {
  padding: 22px;
}

.record-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.record-header h2 {
  font-size: 1.62rem;
  line-height: 1.22;
  overflow-wrap: anywhere;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.tags span {
  border: 1px solid oklch(0.78 0.07 72);
  border-radius: 999px;
  padding: 6px 9px;
  color: oklch(0.36 0.08 72);
  font-size: 0.78rem;
  font-weight: 760;
  background: var(--accent-soft);
}

.record-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
  gap: 24px;
  align-items: start;
  padding-top: 18px;
}

.record-main {
  display: grid;
  gap: 14px;
}

.record-aside {
  border-left: 1px solid var(--line);
  padding-left: 18px;
}

.metadata-list {
  display: grid;
  gap: 14px;
  margin: 0;
}

.metadata-list div {
  display: grid;
  gap: 4px;
}

.metadata-list dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.metadata-list dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
  line-height: 1.5;
  font-weight: 720;
}

.brief-panel,
.split-panels > div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: oklch(0.985 0.006 78);
}

.brief-panel {
  border-color: oklch(0.78 0.07 72);
  background: var(--accent-soft);
}

.brief-panel h3,
.split-panels h3,
.record-todos h3,
.full-record h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  line-height: 1.3;
}

.brief-panel p {
  margin: 0;
  line-height: 1.75;
}

.split-panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.record-todos,
.tasks-panel {
  margin-top: 0;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-title-row h3 {
  margin: 0;
}

.section-title-row span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 780;
}

.full-record {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.full-record summary {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  border: 1px solid oklch(0.72 0.055 213);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--primary-strong);
  background: oklch(0.96 0.025 213);
  font-weight: 820;
  cursor: pointer;
}

.full-record[open] summary {
  margin-bottom: 14px;
}

.panel-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-note {
  max-width: 38ch;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 680;
  line-height: 1.5;
  text-align: right;
}

.card-grid,
.person-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.library-card {
  display: grid;
  gap: 12px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: oklch(0.985 0.006 78);
}

.library-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.library-card h3 {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.library-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.library-meta span,
.source-note {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 720;
}

.library-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 8px;
  background: var(--surface);
}

.library-summary {
  margin: 0;
  color: var(--ink);
  line-height: 1.75;
}

.library-card details {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.library-card summary {
  min-height: 36px;
  color: var(--primary-strong);
  font-weight: 800;
  cursor: pointer;
}

.library-card details[open] summary {
  margin-bottom: 10px;
}

.source-note {
  padding-top: 2px;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  width: 100%;
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
  line-height: 1.55;
}

th {
  color: var(--primary-strong);
  font-size: 0.82rem;
  font-weight: 800;
  background: oklch(0.95 0.018 213);
}

tr:last-child td {
  border-bottom: 0;
}

.rich-text {
  color: var(--ink);
  font-size: 0.98rem;
  line-height: 1.78;
  overflow-wrap: anywhere;
}

.rich-text h2 {
  margin: 28px 0 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 1.26rem;
}

.rich-text h3 {
  margin: 20px 0 10px;
  font-size: 1.06rem;
}

.rich-text p,
.rich-text ul,
.rich-text ol {
  margin: 0 0 12px;
}

.rich-text ul,
.rich-text ol {
  padding-left: 1.25rem;
}

.rich-text code {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  background: var(--surface-muted);
}

.inline-button {
  min-height: 34px;
  border: 1px solid oklch(0.72 0.055 213);
  border-radius: 6px;
  padding: 0 9px;
  color: var(--primary-strong);
  background: oklch(0.96 0.025 213);
  font-weight: 760;
}

.loading,
.empty-state {
  padding: 18px;
  color: var(--muted);
  font-weight: 700;
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
  }

  .record-list {
    max-height: 340px;
  }

  .record-layout,
  .split-panels,
  .status-strip {
    grid-template-columns: 1fr;
  }

  .record-aside {
    border-top: 1px solid var(--line);
    border-left: 0;
    padding-top: 14px;
    padding-left: 0;
  }

  .status-strip,
  .selected-record,
  .tasks-panel,
  .library-panel {
    width: 100%;
    min-width: 0;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-note {
    max-width: none;
    text-align: left;
  }
}

@media (max-width: 640px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .text-link {
    flex: 1 1 30%;
  }

  .record-header {
    flex-direction: column;
  }

  .tags {
    justify-content: flex-start;
  }

  .record-detail,
  .tasks-panel,
  .library-panel {
    padding: 14px;
  }

  .topbar h1 {
    font-size: 1.3rem;
  }

  .record-header h2 {
    font-size: 1.36rem;
  }

  table {
    min-width: 560px;
  }
}
