:root {
  --cream: #FAFAF7;
  --surface: #FFFFFF;
  --pine: #4E5B4D;
  --deep: #263627;
  --sage: #8DAE88;
  --sage-tint: #EFF2EC;
  --peach: #FDB68A;
  --peach-tint: #FFF1E6;
  --ink: #2A2620;
  --muted: #63645F;
  --line: #DCE1D8;
  --danger: #9A3B26;
  --focus: #2F6FDB;
  --radius: 14px;
  --radius-lg: 20px;
  --font: system-ui, "Segoe UI", "Noto Sans Georgian", "BPG Arial", Sylfaen, -apple-system, Roboto, sans-serif;
  --font-serif: "Noto Serif Georgian", Georgia, "Times New Roman", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --cream: #191E19;
    --surface: #222922;
    --pine: #B9CDB4;
    --deep: #E7EEE4;
    --sage: #7FA27A;
    --sage-tint: #2B352B;
    --peach: #F2A877;
    --peach-tint: #3A2C22;
    --ink: #EDEAE3;
    --muted: #A9ABA4;
    --line: #3A443A;
    --danger: #F2A08C;
    --focus: #8DB4FF;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  background: var(--cream);
  color: var(--ink);
  font: 400 1rem/1.55 var(--font);
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

h1, h2 { font-family: var(--font-serif); font-weight: 400; color: var(--deep); margin: 0; }
h1 { font-size: 1.75rem; line-height: 1.25; }
h2 { font-size: 1.3rem; line-height: 1.3; }
p { margin: 0; }

.env-banner {
  background: var(--peach);
  color: #2A2620;
  font-weight: 600;
  text-align: center;
  padding: 6px 16px;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--deep); }

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--pine);
  color: var(--cream);
  font-family: var(--font-serif);
  font-size: 0.95rem;
}

.who { display: flex; align-items: center; gap: 12px; }
.who-name { color: var(--muted); }

.btn {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
}

.btn:disabled { cursor: not-allowed; opacity: 0.55; }
.btn-primary { background: var(--pine); color: var(--cream); }
.btn-primary:not(:disabled):hover { background: var(--deep); color: var(--cream); }
.btn-quiet { background: transparent; color: var(--pine); border-color: var(--line); }
.btn-quiet:not(:disabled):hover { background: var(--sage-tint); }
.btn-accent { background: var(--peach-tint); color: var(--ink); border-color: var(--peach); }

.notice { display: flex; align-items: center; gap: 12px; padding: 10px 20px; flex-wrap: wrap; }
.notice-warn { background: var(--peach-tint); color: var(--ink); }
.notice-error { background: var(--peach-tint); color: var(--danger); font-weight: 600; }

.inline-notice { color: var(--muted); min-height: 0; }
.inline-notice.is-error { color: var(--danger); }
#signin-notice { color: var(--danger); }

main { flex: 1; display: flex; min-height: 0; }

.center-card {
  margin: auto;
  max-width: 440px;
  width: calc(100% - 32px);
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  display: grid;
  gap: 16px;
}

.inbox {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
}

.threads {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
}

.filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 16px; }

.chip {
  font: inherit;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.chip[aria-pressed="true"] { background: var(--pine); border-color: var(--pine); color: var(--cream); }

.list-status { display: flex; align-items: center; gap: 12px; padding: 0 16px; color: var(--muted); }
.list-status:has(p:empty):has(button[hidden]) { display: none; }

.thread-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }

.thread-row {
  display: grid;
  gap: 6px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
}

.thread-row:hover { background: var(--sage-tint); }
.thread-row[aria-current="true"] { background: var(--sage-tint); border-color: var(--sage); }

.row-top { display: flex; justify-content: space-between; gap: 8px; }
.row-title { font-weight: 600; }
.row-time, .row-assignee { color: var(--muted); font-size: 0.9rem; }
.row-badges { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  font-size: 0.8rem;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--sage-tint);
  color: var(--deep);
  border: 1px solid var(--line);
}

.badge-attention { background: var(--peach-tint); border-color: var(--peach); color: var(--ink); }
.badge-muted { color: var(--muted); }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.thread-empty { margin: auto; color: var(--muted); padding: 32px; }

.thread-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.thread-head {
  display: grid;
  gap: 6px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.thread-head .back { display: none; justify-self: start; }
.thread-meta { color: var(--muted); }
.thread-uid { color: var(--muted); font-size: 0.85rem; font-family: ui-monospace, Consolas, monospace; user-select: all; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.actions:empty { display: none; }

.messages-scroll { flex: 1; overflow-y: auto; padding: 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.older { align-self: center; }

.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }

.msg {
  max-width: min(640px, 85%);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
}

.msg-staff { align-self: flex-end; background: var(--sage-tint); border-color: var(--sage); }
.msg-meta { font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; font-size: 1.05rem; line-height: 1.6; }

.composer {
  display: grid;
  gap: 8px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.composer-label { font-weight: 600; }
.composer-note { color: var(--muted); }
.composer-note:empty { display: none; }

textarea {
  font: inherit;
  font-size: 1.05rem;
  width: 100%;
  min-height: 96px;
  max-height: 40vh;
  resize: vertical;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--cream);
  color: var(--ink);
}

textarea[readonly] { opacity: 0.75; }

.composer-foot { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.composer-foot .btn { margin-left: auto; }
.hint { color: var(--muted); font-size: 0.9rem; }
.hint.over { color: var(--danger); font-weight: 600; }

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  padding: 24px;
  max-width: min(460px, calc(100% - 32px));
}

dialog::backdrop { background: rgb(20 24 20 / 0.45); }
dialog form { display: grid; gap: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

@media (max-width: 760px) {
  .inbox { grid-template-columns: 1fr; }
  .threads { border-right: 0; }
  .inbox.has-selection .threads { display: none; }
  .inbox:not(.has-selection) .thread { display: none; }
  .thread-head { padding: 12px 16px; }
  .thread-head .back { display: inline-block; }
  .messages-scroll, .composer { padding-left: 16px; padding-right: 16px; }
  .msg { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
