:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f7f9fb;
  --line: #e3e8ee;
  --text: #16202b;
  --muted: #66727f;
  --faint: #98a3ae;
  --accent: #2f7cf6;
  --accent-soft: #e6f0ff;
  --green: #1f9d55;
  --green-soft: #e3f6ea;
  --amber: #b7791f;
  --amber-soft: #fdf3e1;
  --red: #d64545;
  --red-soft: #fde8e8;
  --violet: #7c5cd6;
  --violet-soft: #efeafd;
  --bubble-in: #ffffff;
  --bubble-out: #e3efff;
  --chat-bg: #eef2f6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1118; --panel: #111a23; --panel-2: #15202b; --line: #223040; --text: #e6edf3; --muted: #93a1b0;
    --faint: #66768a; --accent: #4b8ff8; --accent-soft: #15294a; --green: #3ccf7c; --green-soft: #12301f;
    --amber: #e5a645; --amber-soft: #33260f; --red: #f06767; --red-soft: #3a1616; --violet: #a68cf3;
    --violet-soft: #251d43; --bubble-in: #182430; --bubble-out: #1c3a63; --chat-bg: #0e161f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1118; --panel: #111a23; --panel-2: #15202b; --line: #223040; --text: #e6edf3; --muted: #93a1b0;
  --faint: #66768a; --accent: #4b8ff8; --accent-soft: #15294a; --green: #3ccf7c; --green-soft: #12301f;
  --amber: #e5a645; --amber-soft: #33260f; --red: #f06767; --red-soft: #3a1616; --violet: #a68cf3;
  --violet-soft: #251d43; --bubble-in: #182430; --bubble-out: #1c3a63; --chat-bg: #0e161f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.hidden { display: none !important; }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); border-radius: 8px; padding: 7px 12px; cursor: pointer;
  white-space: nowrap; line-height: 1.2;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--red); }
.btn.green { color: var(--green); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.icon { padding: 6px 8px; }
.input, .select, textarea.input {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 10px; outline: none;
  min-width: 0;
}
.input:focus, .select:focus { border-color: var(--accent); }
label.field { display: block; margin: 10px 0 4px; font-size: 12px; color: var(--muted); }

/* pills */
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px;
  font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.pill.pp { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.customer { background: var(--green-soft); color: var(--green); border-color: transparent; }
.pill.dm { background: var(--panel-2); color: var(--muted); }
.pill.request { background: var(--panel-2); color: var(--faint); border-style: dashed; }
.pill.started { background: var(--violet-soft); color: var(--violet); border-color: transparent; }
.pill.warn { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.pill.bad { background: var(--red-soft); color: var(--red); border-color: transparent; }
.pill.ok { background: var(--green-soft); color: var(--green); border-color: transparent; }

/* shell */
.shell { display: flex; height: 100vh; height: 100dvh; }
.rail {
  width: 76px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex;
  flex-direction: column; align-items: center; padding: 10px 0; gap: 4px;
}
.rail .logo {
  width: 40px; height: 40px; border-radius: 11px; background: var(--accent); display: grid; place-items: center;
  margin-bottom: 10px;
}
.rail a {
  position: relative; width: 64px; padding: 8px 0 6px; border-radius: 10px; color: var(--muted); display: flex;
  flex-direction: column; align-items: center; gap: 3px; font-size: 11px; text-decoration: none;
}
.rail a svg { width: 22px; height: 22px; }
.rail a:hover { background: var(--panel-2); color: var(--text); }
.rail a.active { background: var(--accent-soft); color: var(--accent); }
.rail .badge, .tabbar .badge {
  position: absolute; top: 3px; right: 9px; background: var(--red); color: #fff; border-radius: 999px;
  font-size: 10px; font-weight: 700; padding: 0 5px; min-width: 17px; height: 17px; line-height: 17px; text-align: center;
}
.rail .spacer { flex: 1; }
.main { flex: 1; min-width: 0; display: flex; }
.tabbar { display: none; }

/* inbox */
.list-col {
  width: 380px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex;
  flex-direction: column; min-height: 0;
}
.list-head { padding: 12px 12px 8px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.list-head h2 { margin: 0; font-size: 18px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 11px; cursor: pointer;
  white-space: nowrap; font-size: 12.5px; color: var(--muted);
}
.chip b { font-weight: 700; margin-left: 3px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.list { flex: 1; overflow-y: auto; min-height: 0; }
.conv {
  display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
  text-decoration: none !important; color: inherit;
}
.conv:hover { background: var(--panel-2); }
.conv.active { background: var(--accent-soft); }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff;
  font-weight: 700; font-size: 15px;
}
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }
.conv .top { display: flex; align-items: center; gap: 6px; }
.conv .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .time { margin-left: auto; font-size: 11.5px; color: var(--faint); white-space: nowrap; }
.conv .preview {
  color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.conv .bottom { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.conv .meta { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.unread {
  background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; min-width: 20px;
  height: 20px; line-height: 20px; text-align: center; padding: 0 6px;
}
.star { color: var(--amber); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.more { padding: 12px; text-align: center; }

/* chat */
.chat-col { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--chat-bg); }
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); min-height: 60px;
}
.chat-head .title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 6% 8px; min-height: 0; display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; margin: 10px 0 6px; font-size: 12px; color: var(--muted); background: var(--panel);
  padding: 2px 10px; border-radius: 999px; box-shadow: var(--shadow); }
.msg {
  max-width: min(560px, 78%); padding: 7px 10px 5px; border-radius: 12px; background: var(--bubble-in);
  box-shadow: var(--shadow); align-self: flex-start; position: relative; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.out { align-self: flex-end; background: var(--bubble-out); }
.msg.deleted { opacity: .55; }
.msg .text { white-space: pre-wrap; }
.msg .meta { display: flex; justify-content: flex-end; align-items: center; gap: 6px; font-size: 11px; color: var(--faint); margin-top: 2px; }
.msg .kind { font-size: 10.5px; font-weight: 600; padding: 0 6px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.msg .kind.dm { background: var(--violet-soft); color: var(--violet); }
.msg .kind.followup { background: var(--amber-soft); color: var(--amber); }
.msg .kind.panel { background: var(--green-soft); color: var(--green); }
.msg .fwd { font-size: 12px; color: var(--accent); margin-bottom: 3px; font-weight: 600; }
.msg .quote {
  border-left: 3px solid var(--accent); padding: 2px 8px; margin-bottom: 4px; font-size: 12.5px; color: var(--muted);
  background: rgba(127, 127, 127, .08); border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
}
.msg .tick { color: var(--faint); }
.msg .tick.read { color: var(--accent); }
.msg .act {
  position: absolute; top: 4px; right: -30px; opacity: 0; transition: opacity .15s; border: none; background: var(--panel);
  border-radius: 50%; width: 24px; height: 24px; cursor: pointer; box-shadow: var(--shadow); color: var(--muted);
}
.msg.in .act { right: -30px; }
.msg.out .act { right: auto; left: -30px; }
.msg:hover .act { opacity: 1; }
.msg.flash { outline: 2px solid var(--accent); }
.media { margin: -2px -5px 4px; border-radius: 9px; overflow: hidden; }
.media img, .media video { display: block; max-width: 100%; max-height: 340px; border-radius: 9px; cursor: zoom-in; background: var(--panel-2); }
.media.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 3px; }
.media.grid img, .media.grid video { width: 100%; height: 160px; object-fit: cover; }
.media audio { width: 260px; max-width: 100%; }
.media img.sticker { max-width: 160px; background: transparent; cursor: default; }
.doc {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: rgba(127, 127, 127, .1);
  margin-bottom: 4px; color: inherit;
}
.doc .ic { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.spoiler { background: var(--muted); color: transparent; border-radius: 3px; cursor: pointer; }
.spoiler.show { background: transparent; color: inherit; }
.msg code, .msg pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.msg pre { background: rgba(127, 127, 127, .12); padding: 6px 8px; border-radius: 6px; white-space: pre-wrap; margin: 2px 0; }
.msg blockquote { margin: 2px 0; padding-left: 8px; border-left: 3px solid var(--accent); }

.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
.composer .from { font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.composer .box { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 18px; padding: 9px 14px; max-height: 180px;
  background: var(--panel-2); outline: none; min-height: 40px;
}
.composer textarea:focus { border-color: var(--accent); }
.composer .round { width: 40px; height: 40px; border-radius: 50%; padding: 0; flex: none; }
.replybar, .filebar {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 5px 8px; margin-bottom: 6px;
  border-left: 3px solid var(--accent); background: var(--panel-2); border-radius: 4px;
}
.replybar .grow, .filebar .grow { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notice { padding: 8px 12px; background: var(--amber-soft); color: var(--amber); font-size: 12.5px; }

/* details */
.details-col {
  width: 330px; flex: none; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto;
  padding: 16px; min-height: 0;
}
.details-col h3 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kv { display: grid; grid-template-columns: 104px 1fr; gap: 5px 8px; font-size: 13px; }
.kv .k { color: var(--muted); }
.person { display: flex; gap: 12px; align-items: center; }
.person .n { font-size: 16px; font-weight: 700; }
.fu-row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.dep-row { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.close-details { display: none; }

/* pages */
.page { flex: 1; overflow-y: auto; padding: 22px 26px 40px; min-width: 0; }
.page h1 { margin: 0 0 4px; font-size: 22px; }
.page .lead { color: var(--muted); margin: 0 0 18px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card .v { font-size: 24px; font-weight: 700; margin-top: 2px; }
.card .l { color: var(--muted); font-size: 12.5px; }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; }
.section > .h { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.section > .h h2 { margin: 0; font-size: 15px; }
.section > .b { padding: 14px 16px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--panel-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }
.jobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; margin-bottom: 18px; }
.feed-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.feed-item:last-child { border-bottom: none; }
.feed-item .ic { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 13px; }
.feed-item .ic.out { background: var(--violet-soft); color: var(--violet); }
.feed-item .ic.in { background: var(--accent-soft); color: var(--accent); }
.feed-item .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login h1 { margin: 10px 0 2px; font-size: 20px; }
.login .input { width: 100%; }
.login .btn { width: 100%; margin-top: 16px; padding: 10px; }
.err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* toast, lightbox, modal */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #111a23; color: #fff; padding: 10px 16px;
  border-radius: 10px; z-index: 50; max-width: 90vw; box-shadow: 0 6px 24px rgba(0, 0, 0, .3); font-size: 13.5px;
}
.toast.bad { background: #8f2525; }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .86); z-index: 40; display: grid; place-items: center; cursor: zoom-out; }
.lightbox img, .lightbox video { max-width: 96vw; max-height: 92vh; border-radius: 6px; }
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 30; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; padding: 20px; width: 100%; max-width: 400px; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 6px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* narrower screens */
@media (max-width: 1280px) {
  .details-col { position: fixed; right: 0; top: 0; bottom: 0; z-index: 20; box-shadow: -8px 0 24px rgba(0, 0, 0, .18); }
  .details-col.closed { display: none; }
  .close-details { display: inline-flex; }
}
@media (max-width: 900px) {
  .rail { display: none; }
  .shell { flex-direction: column; }
  .main { min-height: 0; flex: 1; }
  .tabbar {
    display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 6px;
    color: var(--muted); font-size: 10.5px; text-decoration: none;
  }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a.active { color: var(--accent); }
  .tabbar .badge { right: calc(50% - 22px); }
  .list-col { width: 100%; border-right: none; }
  .main.chat-open .list-col { display: none; }
  .main:not(.chat-open) .chat-col { display: none; }
  .main.chat-open + .tabbar { display: none; }
  .back { display: inline-flex; }
  .msgs { padding: 10px 10px 8px; }
  .msg { max-width: 88%; }
  .msg .act { display: none; }
  .details-col { width: 100%; }
  .page { padding: 16px 14px 30px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .tbl.cards-sm thead { display: none; }
}
