:root {
  /* Surface */
  --bg: #f6f4ee;
  --panel: #fffefb;
  --panel-line: #e6e1d3;

  /* Ink */
  --text: #23241f;
  --text-soft: #4a4a42;
  --muted: #7a7a6e;

  /* Brand: deep ink-navy + brass accent (compass needle) */
  --ink: #182233;
  --ink-soft: #2a3650;
  --brass: #ab7d2f;
  --brass-soft: #f3e6cf;

  /* Functional accents — distinct from each other and from danger/warning */
  --local: #2f5d56;   /* personal/local data: deep teal */
  --local-soft: #e3ede9;
  --shared: #9c5a1e;  /* leaves the browser: warm amber-brown */
  --shared-soft: #faecd9;
  --danger: #9c3b2e;  /* destructive action: muted brick */
  --danger-soft: #f6e4df;
  --good: #3c6e4f;
  --good-soft: #e6efe7;

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --shadow-panel: 0 1px 2px rgba(24, 27, 20, 0.04), 0 10px 28px rgba(24, 27, 20, 0.05);

  --font-display: "Source Serif 4", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --font-body: "Inter", "Hiragino Sans", "Yu Gothic", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  letter-spacing: 0.01em;
}

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 272px 1fr;
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--ink);
  background-image:
    radial-gradient(circle at 85% -10%, rgba(171, 125, 47, 0.16), transparent 55%);
  color: #f4f1e8;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  gap: 13px;
  align-items: center;
}

.logo {
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  color: var(--brass);
}

.logo svg {
  width: 100%;
  height: 100%;
}

.brand h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: #fbf8f0;
}

.brand p {
  margin: 3px 0 0;
  color: #aab3c4;
  font-size: 11.5px;
  letter-spacing: 0.02em;
}

.local-note {
  font-size: 12.5px;
  color: #d9e6e1;
  background: rgba(63, 110, 79, 0.16);
  border: 1px solid rgba(63, 110, 79, 0.32);
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  line-height: 1.65;
}

.local-note strong {
  color: #f4f1e8;
}

nav {
  display: grid;
  gap: 4px;
}

.nav-heading {
  margin: 14px 0 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #7d869c;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-heading:first-of-type {
  margin-top: 2px;
}

.nav-heading-shared {
  color: #cd9a52;
}

.nav-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--brass);
  display: inline-block;
}

nav button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #d6dae3;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  font-family: var(--font-body);
  transition: background 0.15s ease, color 0.15s ease;
}

nav button:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
}

nav button.active {
  background: rgba(171, 125, 47, 0.2);
  border-color: rgba(171, 125, 47, 0.35);
  color: #fbf8f0;
}

.profile-box {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: grid;
  gap: 10px;
}

.profile-box label {
  color: #aab3c4;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 0;
}

.profile-box input {
  margin-top: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.16);
  color: #f4f1e8;
}

.profile-box input::placeholder {
  color: #6b7588;
}

/* ---------- Main content ---------- */

.main {
  padding: 32px 36px;
  max-width: 1180px;
  width: 100%;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-panel);
  margin-bottom: 18px;
}

.panel h2 {
  font-size: 19px;
  font-weight: 600;
  margin: 0 0 4px;
}

.panel h3 {
  margin-top: 0;
  font-size: 15px;
  font-weight: 600;
}

.grid {
  display: grid;
  gap: 18px;
}

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

.hero {
  background: linear-gradient(155deg, #182233 0%, #2a3650 100%);
  border-color: #182233;
  color: #f1efe6;
  position: relative;
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  right: -60px;
  top: -60px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  border: 1px solid rgba(171, 125, 47, 0.22);
}

.hero h2 {
  color: #fbf8f0;
  font-size: 22px;
}

.hero p.muted {
  color: #c3c9d6;
}

.hero strong {
  color: var(--brass);
}

/* Local vs shared distinction: shared/external panels get a warm amber tint,
   destructive/irreversible panels keep the brick "warning" tone. */
.shared {
  background: var(--shared-soft);
  border-color: #e7cda0;
}

.shared h2::after {
  content: "外部に送信";
  margin-left: 10px;
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--shared);
  background: #fff;
  border: 1px solid #e7cda0;
  border-radius: 999px;
  padding: 3px 9px;
  vertical-align: middle;
}

.warning {
  background: var(--danger-soft);
  border-color: #e0bdb3;
}

label {
  display: block;
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 12px;
  color: var(--text-soft);
}

form label,
form > label {
  margin-top: 18px;
}

form label:first-child,
form > label:first-child {
  margin-top: 0;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--panel-line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(171, 125, 47, 0.15);
}

input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
}

input[type="date"] {
  font-family: var(--font-body);
}

input[type="file"] {
  padding: 9px 12px;
  font-size: 13px;
  color: var(--muted);
}

input[type="file"]::file-selector-button {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  margin-right: 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: #ece8db;
  color: var(--text);
  transition: background 0.15s ease;
}

input[type="file"]::file-selector-button:hover {
  background: #e2ddcc;
}

textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.6;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

button {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  background: var(--ink);
  color: #fff;
  transition: background 0.15s ease, transform 0.05s ease;
}

button:hover {
  background: var(--ink-soft);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background: #ece8db;
  color: var(--text);
}

button.secondary:hover {
  background: #e2ddcc;
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #832f24;
}

button.good {
  background: var(--good);
}

button.good:hover {
  background: #305c41;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.muted {
  color: var(--muted);
  font-size: 13.5px;
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  background: #ece8db;
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.badge-worry { background: var(--danger-soft); color: var(--danger); }

/* note types */
.badge-reading { background: #e3ede9; color: #2f5d56; }
.badge-experiment { background: #e8eaf6; color: #3c4d8f; }
.badge-analysis { background: #f3e6cf; color: var(--brass); }
.badge-idea { background: #fdf0d9; color: #9c6b1e; }
.badge-quote { background: #f0e6f4; color: #6b3f87; }
.badge-failure { background: var(--danger-soft); color: var(--danger); }
.badge-other { background: #ece8db; color: var(--text-soft); }

/* map node kinds */
.badge-claim { background: #e3ede9; color: var(--local); }
.badge-evidence { background: #e8eaf6; color: #3c4d8f; }
.badge-literature { background: #f0e6f4; color: #6b3f87; }
.badge-counter { background: var(--danger-soft); color: var(--danger); }
.badge-data { background: #e6f0f3; color: #2a6275; }
.badge-question { background: #fdf0d9; color: #9c6b1e; }

.card-list {
  display: grid;
  gap: 12px;
}

.item-card {
  border: 1px solid var(--panel-line);
  border-radius: var(--radius-md);
  padding: 15px 16px;
  background: #fff;
}

.item-card h3 {
  margin: 8px 0 8px;
  font-size: 15.5px;
}

.item-card p {
  white-space: pre-wrap;
  line-height: 1.6;
}

/* ---------- Map ---------- */

.map-node {
  margin-top: 10px;
}

.map-leaf {
  border-left: 3px solid var(--panel-line);
  padding: 12px 14px;
  background: #fbfaf6;
  border-radius: var(--radius-sm);
}

.map-branch {
  border-left: 3px solid var(--brass-soft);
  border-radius: var(--radius-sm);
  background: #fbfaf6;
  padding: 0;
}

.map-branch > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  user-select: none;
}

.map-branch > summary::-webkit-details-marker {
  display: none;
}

.map-toggle {
  width: 9px;
  height: 9px;
  border-right: 1.6px solid var(--muted);
  border-bottom: 1.6px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex: none;
}

.map-branch[open] > summary .map-toggle {
  transform: rotate(45deg);
}

.map-summary-title {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-child-count {
  font-size: 12px;
  flex: none;
}

.map-node-detail {
  padding: 0 14px 14px 14px;
}

.map-node-detail h3 {
  display: none;
}

.map-children {
  padding: 0 0 12px 22px;
  border-left: 1px dashed var(--panel-line);
  margin-left: 14px;
  display: grid;
  gap: 0;
}

.map-children .map-node:last-child {
  margin-bottom: 0;
}

/* ---------- Chat ---------- */

.chat-log {
  display: grid;
  gap: 12px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.chat-message {
  border-radius: var(--radius-md);
  padding: 12px 15px;
  white-space: pre-wrap;
  border: 1px solid var(--panel-line);
  line-height: 1.6;
}

.chat-message strong {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
}

.chat-message.user {
  background: var(--local-soft);
  border-color: #cfdfd7;
}

.chat-message.model {
  background: #fff;
}

.chat-message.is-pending {
  background: #fbfaf6;
}

.pending-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--panel-line);
  border-top-color: var(--brass);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 1.6s;
  }
}

.report-text {
  min-height: 520px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  background: var(--ink);
  color: #f4f1e8;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 12px 30px rgba(24, 27, 20, 0.22);
  transition: 0.2s;
  max-width: 420px;
}

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

.toast.error {
  background: var(--danger);
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

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

  .main {
    padding: 18px;
  }
}

@media (max-width: 600px) {
  .panel {
    padding: 18px;
  }

  .main {
    padding: 14px;
  }
}
