:root {
  --ink: #122017;
  --ink-2: #1c2e24;
  --panel: #163022;
  --line: #2a4636;
  --paper: #f4efe4;
  --card: #fffdf8;
  --text: #1a241d;
  --muted: #66756c;
  --green: #128c4b;
  --green-2: #0d6e3a;
  --mint: #d8f3e3;
  --chat-in: #ffffff;
  --chat-out: #d9f6d0;
  --warn: #9a6b12;
  --err: #b42318;
  --ok: #0d6e3a;
  --shadow: 0 10px 30px rgba(18, 32, 23, .08);
  --radius: 14px;
  --sidebar: 260px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --display: "Sora", "IBM Plex Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--paper);
}
h1, h2, h3 { font-family: var(--display); margin: 0 0 .35rem; letter-spacing: -.02em; }
h1 { font-size: 1.6rem; }
a { color: var(--green-2); text-decoration: none; }
p { margin: 0 0 .6rem; }
.muted { color: var(--muted); }
code { font-size: .85em; background: #eef3ee; padding: .1rem .35rem; border-radius: 6px; }
code.block { display: block; padding: .8rem 1rem; margin: .6rem 0; overflow: auto; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
  background: linear-gradient(180deg, var(--ink) 0%, var(--ink-2) 100%);
  color: #e8f3ec; display: flex; flex-direction: column; z-index: 20;
}
.brand { display: flex; gap: .8rem; align-items: center; padding: 1.2rem 1.1rem 1rem; }
.brand strong, .who strong { display: block; font-family: var(--display); font-size: .95rem; }
.brand small, .who small { color: #9bb5a6; }
.logo {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--green); color: #fff; font-family: var(--display); font-weight: 700;
}
.logo.lg { width: 52px; height: 52px; font-size: 1.1rem; }
.sidebar nav { padding: .4rem .7rem; display: grid; gap: .2rem; flex: 1; overflow: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: .7rem; color: #d5e6db; padding: .55rem .7rem;
  border-radius: 10px; font-weight: 500;
}
.sidebar nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar nav a:hover, .sidebar nav a.active { background: #214633; color: #fff; }
.sidebar-foot { padding: 1rem; border-top: 1px solid var(--line); }
.who { display: flex; gap: .7rem; align-items: center; margin-bottom: .7rem; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: #2d5a40; color: #fff; font-size: .75rem; font-weight: 600; flex-shrink: 0;
}

.shell { margin-left: var(--sidebar); min-height: 100%; padding: 1.4rem 1.6rem 2rem; }
.page-inbox .shell { padding: 0; height: 100vh; overflow: hidden; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.1rem; }
.page-head .muted { margin: 0; }

.btn, button.btn {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: .55rem .9rem; border-radius: 10px; font: 600 .9rem var(--font); cursor: pointer;
}
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-2); }
.btn.ghost { background: transparent; color: #d5e6db; border-color: #3a5a48; }
.btn.block { width: 100%; }
.btn.sm { padding: .3rem .55rem; font-size: .78rem; }
.btn.danger { color: var(--err); border-color: #f0c2be; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid #d7ddd8; background: #fff;
  font-size: 1.2rem; cursor: pointer;
}

.card {
  background: var(--card); border: 1px solid #e6dfd0; border-radius: var(--radius);
  padding: 1.1rem 1.15rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.card.tight { padding: .9rem; }
.card.narrow { max-width: 640px; }
.card h3 { margin-bottom: .8rem; }

.stack { display: grid; gap: .75rem; }
.stack label, form label { display: grid; gap: .3rem; font-size: .85rem; font-weight: 600; color: #314139; }
input, select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid #d5ddd7; border-radius: 10px;
  font: 400 .95rem var(--font); background: #fff; color: var(--text);
}
textarea { resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; flex: 1; }
.row-actions { display: flex; gap: .4rem; align-items: center; }
.inline-form { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.inline-form input, .inline-form select { width: auto; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid #e6dfd0; border-radius: var(--radius); padding: .9rem 1rem; }
.stat span { color: var(--muted); font-size: .8rem; }
.stat b { display: block; font-family: var(--display); font-size: 1.6rem; margin-top: .2rem; }

.split { display: grid; grid-template-columns: 1.5fr .9fr; gap: 1rem; align-items: start; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .65rem .4rem; border-bottom: 1px solid #eee6d8; vertical-align: top; }
th { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }

.toast, .banner {
  padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-weight: 500;
}
.toast.ok, .banner.ok { background: var(--mint); color: var(--ok); }
.toast.err, .banner.err { background: #fde8e6; color: var(--err); }
.banner.warn { background: #fff3d6; color: var(--warn); }

.bars { display: flex; align-items: flex-end; gap: .7rem; height: 110px; padding-top: .5rem; }
.bar-col { display: flex; gap: 3px; align-items: flex-end; flex: 1; justify-content: center; }
.bar { width: 9px; border-radius: 4px 4px 0 0; }
.bar.in { background: #3d8b63; }
.bar.out { background: #c9a227; }
.bar-col small { display: block; width: 100%; text-align: center; color: var(--muted); font-size: .7rem; position: absolute; margin-top: 112px; }
.bar-col { position: relative; padding-bottom: 1.2rem; }
.legend { margin-top: .8rem; color: var(--muted); font-size: .85rem; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin: 0 .35rem 0 .7rem; }
.dot.in { background: #3d8b63; } .dot.out { background: #c9a227; }

.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { display: flex; justify-content: space-between; gap: .8rem; padding: .55rem 0; border-bottom: 1px solid #f0e9db; }
.plain-list a { display: grid; color: inherit; }
.plain-list.compact li { display: grid; }
.notes { list-style: none; padding: 0; margin: .6rem 0 0; }
.notes li { padding: .45rem 0; border-bottom: 1px solid #f0e9db; font-size: .88rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .5rem; }
.chip { background: color-mix(in srgb, var(--c, #00a884) 18%, white); color: #17432d; padding: .15rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.pill { display: inline-block; padding: .12rem .45rem; border-radius: 999px; background: #eef3ee; font-size: .75rem; }
.pill.ok { background: var(--mint); color: var(--ok); }
.pill.warn { background: #fff3d6; color: var(--warn); }

.auth-body { min-height: 100%; background: var(--ink); display: grid; place-items: center; padding: 2rem; }
.auth-wrap { width: min(920px, 100%); display: grid; grid-template-columns: 1.1fr .9fr; background: #0f1c15; border-radius: 22px; overflow: hidden; border: 1px solid #2a4636; }
.auth-hero { padding: 2.4rem; color: #e8f3ec; }
.auth-hero h1 { font-size: 1.8rem; margin: 1rem 0 .5rem; color: #fff; }
.auth-hero p { color: #9bb5a6; line-height: 1.5; }
.auth-card { background: var(--card); padding: 2rem; }
.auth-card h2 { margin-bottom: .3rem; }
.checks { list-style: none; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: .3rem .8rem; font-size: .85rem; margin: 0 0 1rem; }
.checks .ok { color: var(--ok); } .checks .bad { color: var(--err); }

.inbox { display: grid; grid-template-columns: 300px 1fr 280px; height: 100vh; }
.inbox-list { border-right: 1px solid #e6dfd0; background: #fffaf1; display: flex; flex-direction: column; min-width: 0; }
.inbox-list header { padding: 1rem .9rem .5rem; }
.inbox-list form { display: grid; gap: .4rem; }
.convos { overflow: auto; }
.convo { display: grid; grid-template-columns: 36px 1fr auto; gap: .6rem; padding: .7rem .9rem; color: inherit; border-bottom: 1px solid #f0e9db; }
.convo:hover, .convo.active { background: #eef7f0; }
.convo strong { display: block; font-size: .92rem; }
.convo p { margin: .15rem 0 0; color: var(--muted); font-size: .8rem; }
.convo aside { text-align: right; }
.convo time { color: var(--muted); font-size: .7rem; }
.convo em {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 .35rem;
  background: var(--green); color: #fff; border-radius: 999px; font-style: normal; font-size: .7rem;
}
.empty, .empty-thread { padding: 2rem 1rem; color: var(--muted); text-align: center; }
.empty-thread { display: grid; place-items: center; height: 100%; }

.inbox-thread { display: flex; flex-direction: column; min-width: 0; background: #ece5d8; }
.thread-head {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .8rem 1rem; background: #fffaf1; border-bottom: 1px solid #e6dfd0;
}
.window-pill { font-size: .75rem; font-weight: 600; padding: .25rem .6rem; border-radius: 999px; }
.window-pill.on { background: var(--mint); color: var(--ok); }
.window-pill.off { background: #fff3d6; color: var(--warn); }
.thread { flex: 1; overflow: auto; padding: 1rem; display: flex; flex-direction: column; gap: .45rem; }
.bubble {
  max-width: min(72%, 520px); padding: .55rem .7rem .35rem; border-radius: 12px; box-shadow: 0 1px 1px rgba(0,0,0,.04);
}
.bubble.in { align-self: flex-start; background: var(--chat-in); border-top-left-radius: 3px; }
.bubble.out { align-self: flex-end; background: var(--chat-out); border-top-right-radius: 3px; }
.bubble p { margin: 0; white-space: pre-wrap; word-break: break-word; }
.bubble img, .bubble video { max-width: 100%; border-radius: 8px; display: block; margin-bottom: .35rem; }
.bubble footer { display: flex; gap: .4rem; justify-content: flex-end; font-size: .68rem; color: #667; margin-top: .2rem; }
.tick.sent { color: #667; } .tick.delivered, .tick.read { color: #34b7f1; } .tick.failed { color: var(--err); }
.file-pill { display: inline-block; background: #eef3ee; padding: .3rem .55rem; border-radius: 8px; }

.composer { background: #fffaf1; border-top: 1px solid #e6dfd0; padding: .6rem .8rem .8rem; }
.composer-tools { display: flex; gap: .4rem; margin-bottom: .45rem; }
.composer-tools select { font-size: .8rem; }
#send-form { display: flex; gap: .45rem; align-items: flex-end; }
#send-form textarea, #send-form input[type="text"] { flex: 1; min-height: 42px; max-height: 120px; }
.composer-hint { color: var(--err); font-size: .8rem; min-height: 0; margin: .3rem 0 0; }
.composer-hint.show { padding: .5rem .65rem; background: #fde8e6; border-radius: 8px; }
.composer-alert { background: #fff3d6; color: var(--warn); padding: .65rem .75rem; border-radius: 10px; font-size: .85rem; margin-bottom: .5rem; line-height: 1.4; }
.composer-alert a { color: inherit; font-weight: 700; text-decoration: underline; }
.bubble-err { color: var(--err); font-size: .8rem; margin-top: .25rem; }

.inbox-meta { background: #fffaf1; border-left: 1px solid #e6dfd0; overflow: auto; padding: .8rem; }

@media (max-width: 1100px) {
  .inbox { grid-template-columns: 260px 1fr; }
  .inbox-meta { display: none; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .split, .grid-2, .auth-wrap { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .sidebar { position: relative; width: 100%; height: auto; }
  .shell { margin-left: 0; }
  .inbox { display: block; height: auto; }
  .page-inbox .shell { height: auto; overflow: auto; }
}
