:root {
  --honey: #b06d00;
  --honey-strong: #8f5800;
  --honey-soft: #f0b13a;
  --honey-wash: #fdf5e6;
  --ink: #2b2416;
  --ink-2: #4a3f2c;
  --muted: #7d6f57;
  --line: #ece3d3;
  --bg: #faf7f1;
  --panel: #ffffff;
  --side: #2a2013;
  --side-2: #3a2d1b;
  --side-text: #e9dcc4;
  --side-muted: #a8977a;
  --ok: #2f7d4f;
  --bad: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(43, 36, 22, .06), 0 4px 16px rgba(43, 36, 22, .06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-size: 15px; line-height: 1.45; }
a { color: var(--honey-strong); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- boot / auth */
.boot { display: grid; place-items: center; height: 100vh; }
.boot img { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; transform: scale(.94); } }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, #fbe9c4 0, transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border-radius: 16px; padding: 32px;
  box-shadow: var(--shadow); border: 1px solid var(--line); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.auth-brand img { width: 44px; height: 44px; }
.auth-brand b { display: block; font-size: 18px; }
.auth-brand span { color: var(--muted); font-size: 13px; }
.auth h1 { font-size: 20px; margin: 0 0 6px; }
.auth p.lead { color: var(--muted); margin: 0 0 20px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field small { display: block; color: var(--muted); margin-top: 4px; font-size: 12px; }
.field .error { color: var(--bad); font-size: 13px; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; border: 1px solid #dccfb8; border-radius: 8px; padding: 10px 12px; background: #fff;
  outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--honey); box-shadow: 0 0 0 3px rgba(176, 109, 0, .15); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid #dccfb8;
  background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 14px;
  text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { background: var(--honey-wash); }
.btn.primary { background: var(--honey); border-color: var(--honey); color: #fff; }
.btn.primary:hover { background: var(--honey-strong); }
.btn.danger { color: var(--bad); border-color: #e7c3bf; }
.btn.danger:hover { background: #fdf0ee; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; padding: 11px; }
.btn:disabled { opacity: .55; cursor: default; }
.link-btn { background: none; border: 0; color: var(--honey-strong); cursor: pointer; padding: 0; font-weight: 600; }
.form-error { background: #fdf0ee; color: var(--bad); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px;
  font-size: 14px; }
.form-ok { background: #eef7f1; color: var(--ok); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.muted { color: var(--muted); }

/* ------------------------------------------------------------------ shell */
.shell { display: grid; grid-template-columns: 264px 1fr; height: 100vh; height: 100dvh; }
.shell.with-thread { grid-template-columns: 264px 1fr 400px; }
.side { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; min-height: 0; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px; }
.side-brand img { width: 34px; height: 34px; }
.side-brand b { display: block; color: #fff; font-size: 15px; }
.side-brand span { font-size: 12px; color: var(--side-muted); }
.side-scroll { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.side h3 { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--side-muted);
  margin: 16px 10px 6px; font-weight: 700; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px 10px;
  border-radius: 8px; color: var(--side-text); text-decoration: none; border: 0; background: none; cursor: pointer; }
.nav-item:hover { background: var(--side-2); }
.nav-item.active { background: var(--honey); color: #fff; }
.nav-item .hash { min-width: 24px; height: 22px; padding: 0 4px; border-radius: 6px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .08); font-size: 11px; font-weight: 700; flex: none; }
.nav-item.active .hash { background: rgba(255, 255, 255, .2); }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item.unread .label { font-weight: 700; color: #fff; }
.badge { background: var(--honey-soft); color: #2a2013; border-radius: 999px; font-size: 11px; font-weight: 800;
  padding: 1px 7px; min-width: 20px; text-align: center; }
.nav-item.active .badge { background: #fff; }
.side-foot { border-top: 1px solid var(--side-2); padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.side-foot .who { flex: 1; min-width: 0; }
.side-foot .who b { display: block; color: #fff; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .who span { font-size: 12px; color: var(--side-muted); }
.icon-btn { background: none; border: 0; color: inherit; cursor: pointer; padding: 6px; border-radius: 6px; line-height: 0; }
.icon-btn:hover { background: rgba(0, 0, 0, .06); }
.side .icon-btn:hover { background: var(--side-2); }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line);
  min-height: 60px; }
.topbar h2 { font-size: 17px; margin: 0; }
.topbar .sub { color: var(--muted); font-size: 13px; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }

/* --------------------------------------------------------------- messages */
.stream { flex: 1; overflow-y: auto; padding: 12px 0 8px; min-height: 0; }
.stream-empty { text-align: center; color: var(--muted); padding: 48px 24px; }
.stream-empty img { width: 56px; opacity: .9; }
.day { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; font-weight: 700;
  margin: 14px 20px 6px; }
.day::before, .day::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.msg { display: grid; grid-template-columns: 40px 1fr; gap: 10px; padding: 6px 20px; position: relative; }
.msg:hover { background: #fcfaf5; }
.msg.flash { animation: flash 2s ease-out; }
@keyframes flash { 0% { background: #fdeccb; } 100% { background: transparent; } }
.avatar { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; font-weight: 700;
  font-size: 14px; color: #fff; flex: none; }
.avatar.bot { background: var(--side); }
.avatar.bot img { width: 26px; height: 26px; }
.msg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.msg-head b { font-size: 15px; }
.role { font-size: 11px; font-weight: 700; border-radius: 4px; padding: 0 5px; background: var(--honey-wash);
  color: var(--honey-strong); }
.role.bot { background: #efe7d8; color: var(--ink-2); }
.time { color: var(--muted); font-size: 12px; }
.text { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.text code { background: #f4efe5; border-radius: 4px; padding: 0 4px; font-size: 13px; }
.text pre { background: #f4efe5; border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 13px; margin: 6px 0; }
.text .mention { background: var(--honey-wash); color: var(--honey-strong); border-radius: 4px; padding: 0 3px; font-weight: 600; }
.deleted { color: var(--muted); font-style: italic; }
.edited { color: var(--muted); font-size: 12px; }

.blocks { margin-top: 4px; border: 1px solid var(--line); border-left: 4px solid var(--honey-soft);
  border-radius: 10px; padding: 12px 14px; background: #fffdf8; max-width: 720px; }
.blocks .b-section { margin: 4px 0 8px; }
.blocks .b-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 18px; margin: 6px 0 10px; }
.blocks .b-context { color: var(--muted); font-size: 13px; margin: 6px 0; }
.blocks .b-header { font-weight: 800; font-size: 16px; margin: 4px 0 8px; }
.blocks .b-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.blocks .b-divider { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.blocks .btn.danger { background: #fff; }

.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.file-chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; background: #fff; text-decoration: none; color: var(--ink); max-width: 320px; }
.file-chip:hover { border-color: var(--honey-soft); }
.file-chip .ext { background: var(--honey); color: #fff; font-size: 10px; font-weight: 800; border-radius: 4px; padding: 2px 5px; }
.file-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.file-chip .size { color: var(--muted); font-size: 12px; }
.file-img { display: block; max-width: 280px; max-height: 220px; border-radius: 8px; border: 1px solid var(--line); }

.reactions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.reaction { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: #fff;
  border-radius: 999px; padding: 1px 8px; cursor: pointer; font-size: 14px; }
.reaction.mine { border-color: var(--honey-soft); background: var(--honey-wash); }
.reaction.system { cursor: default; }
.reaction small { font-weight: 700; color: var(--ink-2); font-size: 12px; }
.replies-link { display: inline-flex; align-items: center; gap: 8px; margin-top: 6px; border: 0; background: none;
  color: var(--honey-strong); font-weight: 700; cursor: pointer; padding: 2px 0; font-size: 13px; }
.replies-link span { color: var(--muted); font-weight: 400; }

.tools { position: absolute; right: 16px; top: -12px; display: none; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); padding: 2px; }
.msg:hover .tools, .msg:focus-within .tools { display: flex; }
.tools button { background: none; border: 0; padding: 5px 7px; border-radius: 6px; cursor: pointer; font-size: 15px; line-height: 1; }
.tools button:hover { background: var(--honey-wash); }
.picker { position: absolute; z-index: 30; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px; display: flex; gap: 2px; }
.picker button { background: none; border: 0; font-size: 20px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.picker button:hover { background: var(--honey-wash); }

/* ---------------------------------------------------------------- composer */
.composer { border-top: 1px solid var(--line); padding: 12px 20px 16px; }
.composer-box { border: 1px solid #dccfb8; border-radius: 12px; background: #fff; transition: border-color .15s, box-shadow .15s; }
.composer-box:focus-within { border-color: var(--honey); box-shadow: 0 0 0 3px rgba(176, 109, 0, .12); }
.composer-box.drag { border-color: var(--honey); background: var(--honey-wash); }
.composer textarea { border: 0; box-shadow: none !important; resize: none; min-height: 44px; max-height: 220px;
  padding: 12px 14px 4px; background: transparent; }
.composer-bar { display: flex; align-items: center; gap: 6px; padding: 4px 8px 8px; }
.composer-bar .hint { color: var(--muted); font-size: 12px; flex: 1; }
.pending-files { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px; }
.pending-files .file-chip { padding: 4px 8px; }
.pending-files button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; }

/* ------------------------------------------------------------------ thread */
.thread { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.thread .topbar h2 { font-size: 16px; }
.thread .msg { padding: 6px 16px; }
.thread-root { border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 4px; }
.thread .composer { padding: 10px 16px 14px; }

/* ------------------------------------------------------------------ pages */
.page { flex: 1; overflow-y: auto; padding: 24px; }
.page-inner { max-width: 980px; margin: 0 auto; }
.cards { display: grid; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.waiting-item { display: flex; align-items: center; gap: 12px; }
.waiting-item .what { flex: 1; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat b { display: block; font-size: 26px; }
.stat span { color: var(--muted); font-size: 13px; }
.section-head { display: flex; align-items: center; gap: 12px; margin: 8px 0 12px; }
.section-head h2 { margin: 0; font-size: 18px; flex: 1; }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #fcfaf5; }
table.list tr:last-child td { border-bottom: 0; }
table.list .actions { text-align: right; white-space: nowrap; }
.pill { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 700; background: #efe7d8; color: var(--ink-2); }
.pill.ok { background: #e3f2e8; color: var(--ok); }
.pill.off { background: #f3e2df; color: var(--bad); }
.pill.honey { background: var(--honey-wash); color: var(--honey-strong); }
.store-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.store-list label { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 6px; cursor: pointer; }
.store-list label:hover { background: var(--honey-wash); }
.store-list small { color: var(--muted); }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-size: 13px; }

/* ------------------------------------------------------------------ modal */
.overlay { position: fixed; inset: 0; background: rgba(30, 22, 10, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 520px; max-height: 90vh; display: flex;
  flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal header { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal header h2 { flex: 1; margin: 0; font-size: 17px; }
.modal .modal-body { padding: 18px 20px; overflow-y: auto; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); }
.modal .notice { background: var(--honey-wash); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; font-size: 14px; }

#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; }
.toast { background: var(--side); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  max-width: 90vw; animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

/* ------------------------------------------------------------------ mobile */
@media (max-width: 900px) {
  .shell, .shell.with-thread { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .shell.side-open .side { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
  .menu-btn { display: inline-flex; }
  .thread { position: fixed; inset: 0; z-index: 35; border-left: 0; }
  .msg { padding: 6px 12px; }
  .topbar { padding: 10px 12px; }
  .composer { padding: 10px 12px 14px; }
  .tools { right: 8px; }
  .page { padding: 16px 12px; }
  table.list .hide-sm { display: none; }
  .composer-bar .hint { visibility: hidden; }
}
