/* ==========================================================================
   Relay: customer communications
   MiniBytez product demonstration

   Visual language: charcoal rail, soft white content, deep green accent.
   Three panes and no dashboard. There is no home screen other than the inbox.
   The composer is the most designed object here: in note mode it turns amber and
   changes its verb, so confusing a note with a reply is impossible.
   ========================================================================== */

:root {
  --char:      #23282b;
  --char-2:    #2e3438;
  --char-3:    #3d4549;
  --paper:     #f7f8f7;
  --panel:     #ffffff;
  --ink:       #1b2020;
  --ink-2:     #414a4a;
  --muted:     #6d7776;
  --faint:     #98a19f;
  --line:      #e2e6e4;
  --line-2:    #eef1ef;

  --green:     #14532d;
  --green-2:   #0e3d21;
  --green-soft:#eaf2ed;
  --green-line:#c9ddd1;
  --amber:     #8a5a08;
  --amber-soft:#fdf3e0;
  --amber-line:#e8cf9c;
  --red:       #a8322a;
  --red-soft:  #fbedeb;

  --rail: 208px;
  --list: 352px;
  --ctx: 296px;
  --ff: "Segoe UI", -apple-system, BlinkMacSystemFont, Inter, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; height: 100%; }

body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font: 400 13.5px/1.55 var(--ff);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--green); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 3px; }

.skip { position: absolute; left: -9999px; background: var(--char); color: #fff; padding: 9px 14px; z-index: 100; }
.skip:focus { left: 6px; top: 6px; }

/* --- Frame ---------------------------------------------------------------- */

/* The explicit row matters: without it the row sizes to the tallest pane and the composer
   is pushed below the fold. Every pane scrolls inside itself instead. */
.frame {
  display: grid;
  grid-template-columns: var(--rail) var(--list) minmax(0, 1fr) var(--ctx);
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
}
.frame--nocontext { grid-template-columns: var(--rail) var(--list) minmax(0, 1fr); }
.frame--page { grid-template-columns: var(--rail) minmax(0, 1fr); }
.rail, .list, .thread, .ctx, .page { min-height: 0; }

/* --- Rail ----------------------------------------------------------------- */

.rail { background: var(--char); color: #b9c2c0; display: flex; flex-direction: column; overflow-y: auto; }
.rail__brand { padding: 14px 16px 12px; }
.rail__brand b { display: block; font-size: 16px; font-weight: 660; color: #fff; letter-spacing: -0.02em; }
.rail__brand span { font-size: 10.5px; color: #7f8a88; }

.rail__group { font-size: 9.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #6d7a78; padding: 14px 16px 5px; }
.rail a.v, .rail button.v {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 6px 16px; color: #b9c2c0; text-decoration: none; font-size: 13px;
  background: none; border: 0; cursor: pointer; text-align: left; border-left: 3px solid transparent;
}
.rail a.v:hover, .rail button.v:hover { background: var(--char-2); color: #fff; }
.rail a.v[aria-current="page"], .rail button.v[aria-pressed="true"] {
  background: var(--char-2); color: #fff; border-left-color: #4d9c6d; font-weight: 600;
}
.rail .n { margin-left: auto; font-size: 11px; font-variant-numeric: tabular-nums; color: #7f8a88; }
.rail .n--alert { color: #e79b93; font-weight: 700; }
.rail .ch { width: 20px; font-size: 9.5px; font-weight: 700; color: #7f8a88; letter-spacing: .04em; }

.rail__foot { margin-top: auto; padding: 12px 16px 14px; border-top: 1px solid var(--char-2); }
.rail__foot button { background: none; border: 0; color: #b9c2c0; cursor: pointer; padding: 0; font-size: 12px; text-align: left; }
.rail__foot button:hover { color: #fff; }
.rail__foot .st { font-size: 10.5px; color: #7f8a88; margin-top: 3px; display: flex; align-items: center; gap: 6px; }
.rail__foot .st i { width: 7px; height: 7px; border-radius: 50%; background: #4d9c6d; display: inline-block; }
.rail__foot .st i.off { background: #7f8a88; }

.demobar {
  padding: 5px 16px; background: var(--char-2); color: #8b9694; font-size: 10.5px;
  display: flex; flex-direction: column; gap: 4px;
}
.demobar strong { color: #d3dad8; font-weight: 600; }
.demobar .row { display: flex; gap: 8px; }
.demobar button, .demobar a {
  background: none; border: 1px solid var(--char-3); border-radius: 3px;
  padding: 1px 7px; font-size: 10.5px; color: #b9c2c0; cursor: pointer; text-decoration: none;
}
.demobar button:hover, .demobar a:hover { border-color: #4d9c6d; color: #fff; }

/* --- Conversation list ---------------------------------------------------- */

.list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-width: 0; }
.list__head { padding: 10px 13px; border-bottom: 1px solid var(--line); flex: none; }
.list__head h1 { font-size: 15px; font-weight: 640; margin: 0 0 7px; letter-spacing: -0.015em; }
.list__head input {
  width: 100%; height: 30px; padding: 0 9px; font: inherit; font-size: 13px;
  background: var(--paper); border: 1px solid transparent; border-radius: 5px; color: var(--ink);
}
.list__head input:focus { background: var(--panel); border-color: var(--green); outline: none; }
.list__filters { display: flex; gap: 5px; margin-top: 7px; flex-wrap: wrap; }
.list__filters button {
  font-size: 11px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 11px;
  background: var(--panel); cursor: pointer; color: var(--muted);
}
.list__filters button[aria-pressed="true"] { background: var(--green-soft); border-color: var(--green-line); color: var(--green); font-weight: 600; }

.list__body { flex: 1; overflow-y: auto; }

.conv {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  border-bottom: 1px solid var(--line-2); padding: 10px 13px; cursor: pointer;
  border-left: 3px solid transparent;
}
.conv:hover { background: #fafbfa; }
.conv[aria-current="true"] { background: var(--green-soft); border-left-color: var(--green); }
.conv__top { display: flex; align-items: baseline; gap: 8px; }
.conv__who { font-size: 13.5px; font-weight: 640; letter-spacing: -0.01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv__when { font-size: 11px; color: var(--faint); white-space: nowrap; }
.conv__sub { font-size: 12.5px; color: var(--ink-2); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv__pre { font-size: 12px; color: var(--muted); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.conv__foot { display: flex; align-items: center; gap: 6px; margin-top: 7px; flex-wrap: wrap; }
.conv__ch { font-size: 9.5px; font-weight: 700; letter-spacing: .05em; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; }
.conv__who-av { font-size: 11px; color: var(--muted); margin-left: auto; }

/* The SLA chip ages in the list. It is the only thing that changes colour there. */
.slachip {
  font-size: 10.5px; font-weight: 650; font-variant-numeric: tabular-nums;
  border-radius: 3px; padding: 1px 6px; border: 1px solid transparent;
}
.slachip--ok { background: var(--green-soft); color: var(--green); border-color: var(--green-line); }
.slachip--warn { background: var(--amber-soft); color: var(--amber); border-color: var(--amber-line); }
.slachip--bad { background: var(--red-soft); color: var(--red); border-color: #eccbc7; }

.tagchip { font-size: 10.5px; padding: 1px 7px; border-radius: 10px; color: #fff; }

.list__empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.list__empty strong { display: block; color: var(--ink); font-size: 14px; font-weight: 640; margin-bottom: 5px; }

/* --- Thread --------------------------------------------------------------- */

.thread { display: flex; flex-direction: column; min-width: 0; background: var(--paper); }
.thread__head {
  padding: 11px 18px; background: var(--panel); border-bottom: 1px solid var(--line); flex: none;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.thread__head h2 { margin: 0; font-size: 15px; font-weight: 640; letter-spacing: -0.015em; }
.thread__head .meta { font-size: 12px; color: var(--muted); }
.thread__head .acts { margin-left: auto; display: flex; gap: 7px; flex-wrap: wrap; }

.thread__body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }

.msg { max-width: 78%; }
.msg--in { align-self: flex-start; }
.msg--out { align-self: flex-end; }
.msg--note { align-self: stretch; max-width: 100%; }

.msg__bubble { padding: 10px 13px; border-radius: 10px; font-size: 13.5px; line-height: 1.55; }
.msg--in .msg__bubble { background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.msg--out .msg__bubble { background: var(--green-soft); border: 1px solid var(--green-line); border-bottom-right-radius: 3px; }
.msg--note .msg__bubble {
  background: var(--amber-soft); border: 1px solid var(--amber-line); border-left: 4px solid #d19b31;
  border-radius: 4px; color: #5c4008;
}
.msg__meta { font-size: 11px; color: var(--faint); margin-top: 4px; display: flex; gap: 7px; }
.msg--out .msg__meta { justify-content: flex-end; }
.msg--note .msg__meta { color: var(--amber); }
.msg__label {
  font-size: 9.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--amber); margin-bottom: 4px;
}

.thread__event { align-self: center; font-size: 11.5px; color: var(--muted); background: var(--line-2); border-radius: 11px; padding: 2px 11px; }

/* --- Composer: the most designed object in this product ------------------- */

.composer { flex: none; border-top: 1px solid var(--line); background: var(--panel); }
.composer--note { background: var(--amber-soft); border-top: 2px solid #d19b31; }

.composer__modes { display: flex; gap: 0; padding: 8px 18px 0; }
.composer__modes button {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 5px 11px;
  font-size: 12.5px; color: var(--muted); cursor: pointer;
}
.composer__modes button[aria-pressed="true"] { color: var(--green); border-bottom-color: var(--green); font-weight: 650; }
.composer--note .composer__modes button[aria-pressed="true"] { color: var(--amber); border-bottom-color: #d19b31; }

.composer__body { padding: 9px 18px 14px; }
.composer__body textarea {
  width: 100%; min-height: 74px; padding: 10px 12px; font: inherit; font-size: 13.5px;
  border: 1px solid var(--line); border-radius: 6px; resize: vertical; background: var(--panel); color: var(--ink);
}
.composer--note .composer__body textarea { border-color: var(--amber-line); background: #fffdf7; }
.composer__body textarea:focus { border-color: var(--green); outline: none; }
.composer--note .composer__body textarea:focus { border-color: #d19b31; }

.composer__foot { display: flex; align-items: center; gap: 9px; margin-top: 9px; flex-wrap: wrap; }
.composer__foot .hint { font-size: 11.5px; color: var(--muted); }
.composer--note .composer__foot .hint { color: var(--amber); font-weight: 550; }
.composer__foot .gap { flex: 1; }

.btn {
  height: 32px; padding: 0 13px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 5px; font-size: 13px; cursor: pointer; color: var(--ink-2); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: #c9d0cd; color: var(--ink); }
.btn--send { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.btn--send:hover { background: var(--green-2); border-color: var(--green-2); color: #fff; }
.btn--note { background: #a06c12; border-color: #a06c12; color: #fff; font-weight: 600; }
.btn--note:hover { background: #855a0d; border-color: #855a0d; color: #fff; }
.btn--sm { height: 27px; padding: 0 10px; font-size: 12.5px; }

select.field, input.field, textarea.field {
  height: 32px; padding: 0 9px; font: inherit; font-size: 13px;
  border: 1px solid var(--line); border-radius: 5px; background: var(--panel); color: var(--ink);
}
textarea.field { height: auto; padding: 8px 9px; resize: vertical; }
.field:focus { border-color: var(--green); outline: none; }
.lbl { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }

/* --- Context pane --------------------------------------------------------- */

.ctx { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; min-width: 0; }
.ctx__head { padding: 15px 15px 12px; border-bottom: 1px solid var(--line); }
.ctx__avatar {
  width: 44px; height: 44px; border-radius: 50%; background: var(--green-soft); color: var(--green);
  display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 660; margin-bottom: 9px;
}
.ctx__head h3 { margin: 0 0 2px; font-size: 15px; font-weight: 650; letter-spacing: -0.015em; }
.ctx__head .sub { font-size: 12px; color: var(--muted); }
.ctx__head .vip { font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--amber); }

.ctx__sec { padding: 12px 15px; border-bottom: 1px solid var(--line-2); }
.ctx__sec h4 {
  font-size: 9.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--faint); margin: 0 0 8px;
}
.ctx__kv { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 5px 9px; font-size: 12.5px; margin: 0; }
.ctx__kv dt { color: var(--muted); }
.ctx__kv dd { margin: 0; }

.order { padding: 8px 0; border-bottom: 1px solid var(--line-2); font-size: 12.5px; }
.order:last-child { border-bottom: 0; }
.order .p { font-weight: 600; }
.order .m { color: var(--muted); font-size: 11.5px; display: flex; gap: 7px; margin-top: 2px; }
.order .st { font-weight: 600; }
.order .st--Delivered { color: var(--green); }
.order .st--Scheduled, .order .st--In { color: var(--amber); }
.order .st--Returned, .order .st--Cancelled { color: var(--red); }

.pastconv { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 0; border-bottom: 1px solid var(--line-2); cursor: pointer; font-size: 12.5px; }
.pastconv:last-child { border-bottom: 0; }
.pastconv:hover .s { text-decoration: underline; }
.pastconv .s { font-weight: 550; }
.pastconv .m { color: var(--muted); font-size: 11.5px; }

.nothread { display: flex; align-items: center; justify-content: center; height: 100%; text-align: center; padding: 30px; }
.nothread div { max-width: 40ch; color: var(--muted); font-size: 13px; }
.nothread strong { display: block; color: var(--ink); font-size: 15px; font-weight: 640; margin-bottom: 6px; }

/* --- Secondary pages (replies, team, reports) ----------------------------- */

.page { overflow-y: auto; padding: 22px 24px 60px; }
.page h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.025em; margin: 0 0 3px; }
.page .lede { font-size: 13.5px; color: var(--muted); margin: 0 0 20px; max-width: 70ch; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 15px 17px; margin-bottom: 12px; }
.card h3 { margin: 0 0 4px; font-size: 14.5px; font-weight: 640; }
.card .body { font-size: 13px; color: var(--ink-2); white-space: pre-wrap; }
.card .foot { margin-top: 11px; display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }

table.t { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; font-size: 13px; overflow: hidden; }
table.t th { text-align: left; font-size: 11.5px; font-weight: 650; color: var(--muted); padding: 10px 13px; border-bottom: 1px solid var(--line); }
table.t td { padding: 11px 13px; border-bottom: 1px solid var(--line-2); }
table.t tr:last-child td { border-bottom: 0; }
table.t .r { text-align: right; font-variant-numeric: tabular-nums; }

.figrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; margin-bottom: 22px; }
.figrow > div { background: var(--panel); padding: 13px 15px; }
.figrow dt { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.figrow dd { margin: 0; font-size: 22px; font-weight: 660; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }

/* --- Modal and toast ------------------------------------------------------ */

.overlay { position: fixed; inset: 0; z-index: 80; background: rgba(27,32,32,.42); display: flex; align-items: flex-start; justify-content: center; padding: 9vh 20px 20px; overflow-y: auto; }
.overlay[hidden] { display: none; }
.modal { background: var(--panel); border-radius: 8px; width: 100%; max-width: 500px; box-shadow: 0 18px 46px rgba(27,32,32,.3); }
.modal__head { padding: 16px 20px 12px; border-bottom: 1px solid var(--line); }
.modal__head h2 { margin: 0; font-size: 16px; font-weight: 650; }
.modal__head p { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }
.modal__body { padding: 16px 20px; display: grid; gap: 12px; max-height: 56vh; overflow-y: auto; }
.modal__foot { padding: 12px 20px 16px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line-2); }
.modal .field { width: 100%; }

.pickreply { text-align: left; background: none; border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; cursor: pointer; width: 100%; }
.pickreply:hover { border-color: var(--green); background: var(--green-soft); }
.pickreply strong { display: block; font-size: 13.5px; margin-bottom: 3px; }
.pickreply span { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 90; display: grid; gap: 7px; }
.toast { background: var(--char); color: #fff; font-size: 13px; padding: 9px 15px; border-radius: 5px; box-shadow: 0 6px 20px rgba(27,32,32,.3); display: flex; gap: 13px; align-items: center; }
.toast button { background: none; border: 0; color: #8fd0a8; cursor: pointer; font-size: 12.5px; }

/* --- Responsive: a real navigation stack, not a squeeze ------------------- */

.backbtn { display: none; }

@media (max-width: 1240px) {
  .frame { grid-template-columns: var(--rail) var(--list) minmax(0, 1fr); }
  .ctx { display: none; }
  .frame--showctx { grid-template-columns: var(--rail) minmax(0, 1fr) var(--ctx); }
  .frame--showctx .list { display: none; }
  .frame--showctx .ctx { display: block; }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .frame, .frame--showctx, .frame--nocontext, .frame--page {
    grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); height: 100vh;
  }
  .rail {
    flex-direction: row; align-items: center; overflow-x: auto; gap: 3px; padding: 0 8px;
    scrollbar-width: none; flex: none;
  }
  .rail::-webkit-scrollbar { display: none; }
  .rail__brand { padding: 9px 8px; white-space: nowrap; }
  .rail__brand span { display: none; }
  .rail__group, .rail__foot { display: none; }
  .rail .demobar { display: none; }
  .rail a.v, .rail button.v { width: auto; white-space: nowrap; border-left: 0; border-bottom: 3px solid transparent; padding: 7px 9px; }
  .rail a.v[aria-current="page"], .rail button.v[aria-pressed="true"] { border-left: 0; border-bottom-color: #4d9c6d; }
  .rail .ch { display: none; }

  /* One pane at a time. Back moves up the stack. */
  .list, .thread, .ctx { display: none; }
  .pane-list .list { display: flex; border-right: 0; }
  .pane-thread .thread { display: flex; }
  .pane-ctx .ctx { display: block; border-left: 0; }
  .backbtn { display: inline-flex; }
  .msg { max-width: 88%; }
  .page { padding: 16px 14px 50px; }
}

@media (prefers-reduced-motion: reduce) { * { animation-duration: .001ms !important; transition-duration: .001ms !important; } }
