:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-soft: #eeece5;
  --line: #d9d5ca;
  --line-strong: #bdb7aa;
  --text: #1e201c;
  --muted: #6f7169;
  --accent: #0f766e;
  --accent-soft: #d9efeb;
  --amber: #a16207;
  --amber-soft: #fef3c7;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --red: #b42318;
  --red-soft: #fee4e2;
  --green: #15803d;
  --green-soft: #dcfce7;
  --radius: 8px;
  --shadow: 0 18px 45px rgba(35, 36, 31, 0.07);
  --font: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
}

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

.primary,
.secondary {
  min-height: 40px;
  border-radius: var(--radius);
  padding: 9px 14px;
  white-space: nowrap;
}

.primary {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary:hover {
  background: #115e59;
  border-color: #115e59;
}

.secondary {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}

.secondary:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.file-action {
  display: inline-flex;
  align-items: center;
}

#importInput {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.quick-add {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(160px, 0.6fr) auto;
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.settings-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.settings-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.settings-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

.settings-status {
  margin: 5px 0 0;
  color: var(--muted);
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.field-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.chat-id-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 32px;
  align-items: center;
}

.chat-id-empty {
  color: var(--muted);
}

.chat-id-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 4px 5px 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbfbfa;
  color: var(--text);
}

.chat-id-chip button {
  min-height: 24px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 3px 8px;
}

.chat-id-chip button:hover {
  color: var(--red);
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
}

.control {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  outline: none;
  padding: 9px 11px;
}

textarea.control {
  min-height: 68px;
  resize: vertical;
}

.control:focus,
.inline-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
  padding: 12px 14px;
}

.summary-item:hover {
  border-color: var(--line-strong);
}

.summary-item.muted {
  background: #f0f0ed;
}

.summary-item strong {
  display: block;
  font-size: 24px;
  line-height: 1;
  letter-spacing: 0;
  margin-bottom: 6px;
}

.summary-item span {
  color: var(--muted);
}

.board {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.board-head {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr);
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfbfa;
}

.archive-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff8f7;
  color: var(--muted);
}

.archive-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.tab {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 7px 12px;
  white-space: nowrap;
}

.tab.active {
  background: var(--text);
  color: #fff;
}

.topic-list {
  display: grid;
}

.topic {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px 220px;
  gap: 14px;
  padding: 16px 14px;
  border-bottom: 1px solid var(--line);
  align-items: start;
}

.topic:last-child {
  border-bottom: 0;
}

.topic-main {
  display: grid;
  gap: 9px;
}

.title-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}

.archive-checkbox {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  margin: 3px 2px 0 0;
  accent-color: var(--red);
}

.identity {
  display: grid;
  gap: 5px;
  min-width: 0;
  flex: 1;
}

.inline-input {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  outline: none;
  padding: 2px 4px;
}

.topic-title-input {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
}

.topic-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  min-width: 0;
}

.source-input {
  width: auto;
  min-width: 90px;
  max-width: 220px;
  flex: 0 1 170px;
  color: var(--muted);
  font-size: 12px;
}

.topic-date {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.topic-date::before {
  content: "·";
  margin-right: 10px;
  color: var(--line-strong);
}

.why,
.result,
.decision,
.actions {
  display: grid;
  gap: 8px;
}

.why label,
.result label,
.decision label,
.actions label {
  color: var(--muted);
  font-size: 12px;
}

.why {
  gap: 0;
}

.result {
  margin-top: 6px;
  display: none;
}

.topic.done .result {
  display: grid;
}

.pills,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 5px 10px;
  white-space: nowrap;
}

.pill.active {
  color: var(--text);
  border-color: transparent;
  font-weight: 700;
}

.pill.must.active {
  background: var(--amber-soft);
  color: var(--amber);
}

.pill.maybe.active {
  background: var(--blue-soft);
  color: var(--blue);
}

.pill.watch.active {
  background: var(--surface-soft);
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-candidate {
  background: var(--surface-soft);
  color: var(--muted);
}

.badge-week {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-done {
  background: var(--green-soft);
  color: var(--green);
}

.badge-archive {
  background: var(--red-soft);
  color: var(--red);
}

.small {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 5px 9px;
  white-space: nowrap;
}

.small:hover {
  border-color: var(--line-strong);
  background: #fbfbfa;
}

.small.accent {
  border-color: var(--accent);
  color: var(--accent);
  background: #f6fbf9;
}

.small.red {
  border-color: #f4b3ad;
  color: var(--red);
  background: #fff8f7;
}

.empty {
  padding: 46px 16px;
  text-align: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 320px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--text);
  color: #fff;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 420px);
  display: grid;
  gap: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  color: var(--muted);
  font-size: 12px;
}

.login-message {
  min-height: 21px;
  margin: 0;
  color: var(--red);
}

@media (max-width: 900px) {
  .quick-add,
  .settings-grid,
  .input-row,
  .board-head,
  .topic {
    grid-template-columns: 1fr;
  }

  .summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .app {
    padding: 18px 14px 36px;
  }

  .topbar {
    display: grid;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .summary {
    grid-template-columns: 1fr;
  }

  .tabs {
    width: 100%;
    overflow-x: auto;
  }

  .tab {
    flex: 1 0 auto;
  }
}
