:root {
  font-family: system-ui, "Malgun Gothic", sans-serif;
  color: #242a23;
  background: #f2f4ee;
  --line: #dbe1d6;
  --accent: #245740;
  --muted: #526257;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, textarea, input { font: inherit; }
button {
  min-height: 44px;
  padding: .55rem .9rem;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: .6rem;
  background: #fff;
  cursor: pointer;
}
button:disabled { opacity: .6; cursor: wait; }
a { color: var(--accent); }
.log-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: .35rem .65rem;
  border: 1px solid var(--line);
  border-radius: .6rem;
  background: #fff;
  text-decoration: none;
}
.log-button span { font-size: 1.2rem; line-height: 1; }
.log-page { width: min(100% - 1.5rem, 840px); margin: 0 auto 2rem; }
.log-panel { background: #fff; border: 1px solid var(--line); border-radius: .8rem; overflow: auto; }
.log-panel table { width: 100%; border-collapse: collapse; text-align: left; }
.log-panel th, .log-panel td { padding: .65rem .7rem; border-bottom: 1px solid var(--line); }
.log-panel tbody tr:last-child td { border-bottom: 0; }
.log-panel time { font-variant-numeric: tabular-nums; }
.log-level { white-space: nowrap; }
.log-warning { font-weight: 700; color: #884417; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); color: white; border-color: var(--accent); }
.workspace { max-width: 1760px; margin: auto; padding: 0 1.5rem 1.5rem; }
.topbar, .chat-header, .composer-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.topbar { min-height: 76px; }
.brand { font-size: 1.2rem; font-weight: 800; text-decoration: none; }
.chat {
  height: max(440px, calc(100dvh - 100px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 1rem;
}
.chat-header, #composer { padding: 1rem 1.25rem; }
.chat-header { border-bottom: 1px solid var(--line); }
h1, h2 { margin: 0; font-size: 1.25rem; }
#connection, .meta, #empty, #feedback, #edit-feedback { color: var(--muted); }
#connection { font-size: .85rem; }
.history { overflow: auto; padding: .85rem 1.25rem; }
#empty { text-align: center; margin: 2rem 0; }
#messages { list-style: none; display: grid; gap: .8rem; padding: 0; margin: 0; }
.message { background: #f5f7f2; padding: .8rem 1rem; border-radius: .8rem; }
.meta { margin: 0; font-size: .85rem; overflow-wrap: anywhere; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: .5rem 0; }
.sources {
  list-style: none;
  padding: 0;
  margin: .6rem 0;
  display: grid;
  gap: .35rem;
}
.sources li {
  border-left: 2px solid var(--line);
  padding: .3rem .6rem;
  overflow-wrap: anywhere;
}
.sources span {
  display: block;
  margin-top: .15rem;
  font-size: .82rem;
  color: var(--muted);
}
.pdf-attachment {
  margin: .6rem 0;
  padding: .4rem .65rem;
  border-left: 2px solid var(--line);
  overflow-wrap: anywhere;
}
.pdf-attachment span {
  display: block;
  margin-top: .15rem;
  font-size: .82rem;
  color: var(--muted);
}
.attachment-control { display: grid; gap: .25rem; }
.attachment-control small { font-weight: 400; color: var(--muted); }
.message-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
.message-actions button { font-size: .83rem; }
#composer { border-top: 1px solid var(--line); }
form { display: grid; gap: .5rem; }
label { font-weight: 650; }
textarea, input { width: 100%; padding: .65rem; border: 1px solid #9da99e; border-radius: .5rem; }
textarea { resize: vertical; }
#body { max-height: 25dvh; }
#feedback, #edit-feedback { margin: 0; overflow-wrap: anywhere; }
dialog { width: min(30rem, calc(100% - 2rem)); border: 1px solid var(--line); border-radius: 1rem; padding: 1.25rem; }
dialog::backdrop { background: #19241b80; }
.dialog-actions { display: flex; gap: .5rem; justify-content: flex-end; }
.checkbox { display: flex; gap: .5rem; align-items: center; min-height: 44px; }
.checkbox input { width: auto; }
#ai-settings p { margin: .35rem 0; }

@media (max-width: 600px) {
  .workspace { padding: 0; }
  .topbar { min-height: 58px; padding: 0 .85rem; }
  .chat { height: max(380px, calc(100dvh - 58px)); border-radius: 0; border-inline: 0; }
  .chat-header, .history, #composer { padding-inline: .85rem; }
  #composer { padding-bottom: max(1rem, env(safe-area-inset-bottom)); }
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(155px, .65fr) minmax(0, 2.4fr) minmax(320px, 1.4fr);
  gap: 1rem;
}
.sidebar, .board {
  min-width: 0;
  height: max(440px, calc(100dvh - 100px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: #fff;
  padding: 1rem;
}
.sidebar h2 { margin: .2rem 0 1rem; }
#board-nav { display: grid; gap: .35rem; }
#board-nav button {
  display: flex;
  justify-content: space-between;
  gap: .45rem;
  text-align: left;
  overflow-wrap: anywhere;
}
#board-nav button[aria-pressed="true"], .mobile-nav button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}
.board-count { font-variant-numeric: tabular-nums; }
.board-header { display: flex; align-items: center; justify-content: space-between; gap: .65rem; }
.board-header h1 { overflow-wrap: anywhere; }
.board-header button { flex-shrink: 0; }
.board-tabs { display: flex; gap: .4rem; margin-bottom: .85rem; border-bottom: 1px solid var(--line); }
.board-tabs button { border: 0; border-radius: 0; background: transparent; }
.board-tabs button[aria-selected="true"] { border-bottom: 3px solid var(--accent); font-weight: 700; }
#log-entries { margin-top: .85rem; }
#logs-status { color: var(--muted); }
#board-filters { margin-top: .85rem; }
.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .3rem .45rem;
}
.search-row label { grid-column: 1 / -1; }
.date-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
  align-items: end;
  gap: .45rem;
}
.date-filters label { display: grid; gap: .25rem; min-width: 0; font-size: .86rem; }
.date-filters input { min-width: 0; min-height: 44px; }
.edit-hint, #search-status { color: var(--muted); font-size: .86rem; }
.edit-hint { margin: .15rem 0; }
.board-picker, .mobile-nav { display: none; }
#board-empty { color: var(--muted); margin: 2rem 0; }
#board-posts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: .85rem;
  margin-top: 1rem;
}
.note {
  --paper: #fff1c7;
  display: grid;
  align-content: start;
  gap: .55rem;
  min-width: 0;
  padding: .9rem;
  background: var(--paper);
  border-radius: .45rem;
  border: 1px solid #28302522;
  box-shadow: 0 3px 8px #28302514;
  overflow-wrap: anywhere;
}
.note[data-color="0"] { --paper: #f4e7fb; }
.note[data-color="1"] { --paper: #fff1c7; }
.note[data-color="2"] { --paper: #e2f1d9; }
.note[data-color="3"] { --paper: #e0effb; }
.note[data-color="4"] { --paper: #fde8e3; }
.note[data-color="neutral"] { --paper: #f0f0ea; }
.note img { width: 100%; height: 118px; object-fit: cover; border-radius: .3rem; }
.note p { margin: 0; }
.note-meta, .note-tags { font-size: .83rem; color: #435047; }
.note-heading { display: flex; align-items: start; justify-content: space-between; gap: .4rem; }
.favorite-button { min-width: 44px; padding-inline: .45rem; font-size: 1.15rem; }
.favorite-button[aria-pressed="true"] { color: #795100; background: #fff4cf; }
.note-summary { white-space: pre-wrap; }
.note-tags { display: flex; flex-wrap: wrap; gap: .3rem; list-style: none; padding: 0; margin: 0; }
.note-tags li { padding: .15rem .48rem; border-radius: .45rem; background: #ffffffa0; }
.note-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; margin-top: .25rem; }
.note-actions a { padding: .65rem .25rem; }
.note-actions button { font-size: .85rem; }
#board-dialog { max-height: 90dvh; overflow: auto; }
#board-dialog form { margin-top: .8rem; }
select { font: inherit; max-width: 100%; min-height: 44px; padding: .35rem; border-radius: .5rem; }

@media (max-width: 1020px) {
  .dashboard { display: block; }
  .sidebar, .dashboard[data-pane="chat"] .board, .dashboard[data-pane="board"] .chat { display: none; }
  .board-picker { display: grid; gap: .35rem; margin-top: .85rem; }
  .mobile-nav { display: flex; justify-content: center; gap: .55rem; padding: .5rem; }
  .mobile-nav button { flex: 1; }
  .dashboard .chat, .board { height: max(395px, calc(100dvh - 150px)); }
}
@media (max-width: 600px) {
  .topbar .dialog-actions { gap: .3rem; }
  .topbar button { padding-inline: .48rem; }
  .topbar { gap: .4rem; flex-wrap: wrap; padding-block: .4rem; }
  .dashboard .chat, .board { height: max(380px, calc(100dvh - 115px)); }
  .board { border-radius: 0; border-inline: 0; }
  .mobile-nav { padding-bottom: max(.5rem, env(safe-area-inset-bottom)); }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  color: #e7ebe3;
  background: #151c19;
  --line: #3d4c43;
  --accent: #a5d4b8;
  --muted: #b5c4ba;
}
[data-theme="dark"] :is(.sidebar, .board, .chat, .log-panel, .log-button, dialog, button, input, textarea, select) {
  background: #202a25;
  color: #e7ebe3;
}
[data-theme="dark"] .log-warning { color: #ffd19c; }
[data-theme="dark"] :is(.primary, #board-nav button[aria-pressed="true"], .mobile-nav button[aria-pressed="true"]) {
  background: var(--accent);
  color: #17221b;
}
[data-theme="dark"] .message { background: #28352e; }
[data-theme="dark"] .note { background: var(--dark-paper, #30332a); border-color: var(--line); }
[data-theme="dark"] .note[data-color="0"] { --dark-paper: #382c42; }
[data-theme="dark"] .note[data-color="1"] { --dark-paper: #39321f; }
[data-theme="dark"] .note[data-color="2"] { --dark-paper: #283b2a; }
[data-theme="dark"] .note[data-color="3"] { --dark-paper: #263943; }
[data-theme="dark"] .note[data-color="4"] { --dark-paper: #442f2c; }
[data-theme="dark"] :is(.note-meta, .note-tags) { color: #d0ded3; }
[data-theme="dark"] .note-tags li { background: #111a17a0; }
[data-theme="dark"] .favorite-button[aria-pressed="true"] { color: #fbdb82; background: #3b3320; }
