/* ============================================================
   Support console — visual system

   Palette is the client's: deep forest for structure, sage for
   anything the bot did on its own, slate for anything a person
   touched, pale sage for washes. One colour sits outside that
   set — a muted clay for destructive actions — because a green
   "delete" reads as safe, and it must not.

   Colour carries state and nothing else. No decorative accents.
   ============================================================ */

:root {
  /* client palette */
  --forest: #404e3b;
  --sage: #7b9669;
  --slate: #6c8480;
  --pale: #bac8b1;
  --canvas: #e6e6e6;

  /* derived */
  --sage-wash: #eef3ea;
  --sage-line: #cfdcc6;
  --slate-wash: #e9eeed;
  --pale-wash: #f1f5ee;

  /* the one addition: destructive actions must not read as safe */
  --clay: #9c5a4f;
  --clay-wash: #f7ebe8;

  --surface: #ffffff;
  --surface-sunk: #f4f6f2;
  --ink: #2c3628;
  --ink-soft: #4e5a48;
  --muted: #71806c;
  --line: #d8ded2;
  --line-soft: #e8ede3;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(44, 54, 40, 0.05), 0 8px 20px rgba(44, 54, 40, 0.06);

  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

html,
body {
  max-width: 100%;
  overflow-x: clip;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
}

a {
  color: var(--forest);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--sage);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- shell ---------- */

.shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  min-width: 0;
  background: var(--forest);
  color: #d3ddcd;
  padding: 22px 14px 28px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 10px;
}
.brand strong {
  color: #fff;
  font-size: 16px;
  letter-spacing: -0.015em;
}
.brand span {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--pale);
  opacity: 0.65;
}

.nav-group + .nav-group {
  margin-top: 20px;
}
.nav-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--pale);
  opacity: 0.6;
  padding: 0 10px 7px;
}
.nav a {
  display: block;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: #d3ddcd;
  font-size: 14.5px;
  line-height: 1.3;
}
.nav a:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  text-decoration: none;
}
.nav a.current {
  background: var(--sage);
  color: #fff;
  font-weight: 500;
}

.sidebar footer {
  margin-top: auto;
  padding: 0 10px;
}
.sidebar footer .btn {
  color: #d3ddcd;
  border-color: rgba(211, 221, 205, 0.28);
  background: transparent;
  width: 100%;
}
.sidebar footer .btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-color: rgba(211, 221, 205, 0.5);
}

.main {
  padding: 28px 32px 64px;
  max-width: 1240px;
  min-width: 0;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-head h1 {
  margin: 0;
  font-size: 25px;
  letter-spacing: -0.025em;
  color: var(--forest);
}
.page-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-bottom: 18px;
}
.card > h2 {
  margin: 0 0 5px;
  font-size: 16px;
  letter-spacing: -0.015em;
  color: var(--forest);
}
.card > h2 + p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13.5px;
  max-width: min(68ch, 100%);
}

/* Auto-fit means cards pack to whatever the window allows instead of
   collapsing into one tall column the moment it narrows. */
.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr));
}
.grid.metrics {
  grid-template-columns: repeat(auto-fit, minmax(min(158px, 100%), 1fr));
}
.grid.wide {
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
}
.grid.split {
  grid-template-columns: minmax(0, 2fr) minmax(min(280px, 100%), 1fr);
  align-items: start;
}

/* ---------- metrics ---------- */

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--sage);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.metric .value {
  font-family: var(--mono);
  font-size: 27px;
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.1;
  color: var(--forest);
}
.metric .label {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 4px;
}
.metric.alert {
  border-left-color: var(--clay);
}
.metric.alert .value {
  color: var(--clay);
}

.meter {
  height: 6px;
  border-radius: 3px;
  background: var(--line-soft);
  overflow: hidden;
  margin-top: 8px;
}
.meter i {
  display: block;
  height: 100%;
  background: var(--sage);
  border-radius: 3px;
}
.meter.warn i {
  background: var(--slate);
}
.meter.over i {
  background: var(--clay);
}

/* ---------- forms ---------- */

.field {
  margin-bottom: 18px;
}
.field > label {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ink);
}
.field .help {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 6px;
  max-width: min(68ch, 100%);
  line-height: 1.5;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
}
textarea {
  resize: vertical;
  line-height: 1.55;
}
textarea.mono,
input.mono {
  font-family: var(--mono);
  font-size: 13px;
}
input:hover,
select:hover,
textarea:hover {
  border-color: var(--pale);
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--sage);
  outline: none;
  box-shadow: 0 0 0 3px rgba(123, 150, 105, 0.2);
}

/* A toggle is a decision, so it gets a row of its own that is entirely
   clickable, rather than a small control floating beside a label. */
.switch {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-sunk);
  font-weight: 500;
  font-size: 14px;
}
.switch:hover {
  border-color: var(--pale);
  background: var(--pale-wash);
}
.switch input {
  appearance: none;
  width: 40px;
  height: 23px;
  border-radius: 12px;
  background: #c3ccbc;
  position: relative;
  transition: background 0.15s;
  flex: none;
  margin: 0;
  cursor: pointer;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.switch input:checked {
  background: var(--sage);
}
.switch input:checked::after {
  transform: translateX(17px);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--sage);
  background: var(--sage);
  color: #fff;
  cursor: pointer;
  min-height: 40px;
}
.btn:hover {
  background: #6c874f;
  border-color: #6c874f;
  text-decoration: none;
  color: #fff;
}
.btn.ghost {
  background: var(--surface);
  color: var(--forest);
  border-color: var(--line);
}
.btn.ghost:hover {
  background: var(--pale-wash);
  border-color: var(--pale);
  color: var(--forest);
}
.btn.danger {
  background: var(--clay);
  border-color: var(--clay);
}
.btn.danger:hover {
  background: #874c42;
  border-color: #874c42;
}
.btn.small {
  padding: 6px 12px;
  font-size: 13.5px;
  min-height: 34px;
}

.actions {
  display: flex;
  gap: 9px;
  align-items: center;
  flex-wrap: wrap;
}
.actions form {
  margin: 0;
}

/* ---------- tabs, chips, badges ---------- */

.tabs {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px;
  margin-bottom: 20px;
}
.tabs a {
  padding: 8px 14px;
  font-size: 14px;
  color: var(--ink-soft);
  border-radius: var(--radius-sm);
}
.tabs a:hover {
  background: var(--pale-wash);
  color: var(--forest);
  text-decoration: none;
}
.tabs a.current {
  background: var(--forest);
  color: #fff;
  font-weight: 500;
}

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--surface-sunk);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.bot {
  background: var(--sage-wash);
  color: #4b6339;
  border-color: var(--sage-line);
}
.badge.human {
  background: var(--slate-wash);
  color: #4a5f5b;
  border-color: #c8d5d2;
}
.badge.danger {
  background: var(--clay-wash);
  color: var(--clay);
  border-color: #e5c9c3;
}
a.badge:hover {
  text-decoration: none;
  border-color: var(--sage);
}

.notice {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 18px;
  border-left: 4px solid var(--sage);
  background: var(--sage-wash);
  color: #3f5530;
}
.notice.warn {
  border-left-color: var(--slate);
  background: var(--slate-wash);
  color: #3f524e;
}
.notice.error {
  border-left-color: var(--clay);
  background: var(--clay-wash);
  color: #7d4038;
}
.notice a {
  color: inherit;
  text-decoration: underline;
}

/* ---------- tables ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th {
  text-align: left;
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  padding: 0 11px 9px;
  border-bottom: 1px solid var(--line);
}
td {
  padding: 12px 11px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
tbody tr:hover {
  background: var(--pale-wash);
}
td.num,
th.num {
  font-family: var(--mono);
  text-align: right;
}
.empty {
  padding: 40px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.empty strong {
  display: block;
  color: var(--forest);
  font-size: 15px;
  margin-bottom: 5px;
}

/* ---------- conversation rail ----------
   Every message hangs off one vertical rail, and the dot colour says who
   spoke: slate for the customer, sage for the bot, forest for you. A stretch
   where the bot was held back is drawn as a band across the rail, so silence
   is something you can see rather than infer. */

.rail {
  position: relative;
  padding-left: 28px;
}
.rail::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--line);
  border-radius: 1px;
}

.turn {
  position: relative;
  margin-bottom: 18px;
}
.turn::before {
  content: "";
  position: absolute;
  left: -25px;
  top: 8px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--slate);
}
.turn.from-bot::before {
  background: var(--sage);
}
.turn.from-human::before {
  background: var(--forest);
}

.turn .meta {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 5px;
  flex-wrap: wrap;
}
.turn .meta strong {
  color: var(--ink-soft);
  font-size: 11.5px;
}

.turn .bubble {
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: min(74ch, 100%);
  font-size: 14.5px;
}
.turn.from-bot .bubble {
  background: var(--sage-wash);
  border-color: var(--sage-line);
}
.turn.from-human .bubble {
  background: var(--slate-wash);
  border-color: #c8d5d2;
}

.pause-band {
  position: relative;
  margin: 6px 0 18px -28px;
  padding: 7px 0 7px 28px;
  background: repeating-linear-gradient(
    135deg,
    rgba(108, 132, 128, 0.11),
    rgba(108, 132, 128, 0.11) 7px,
    transparent 7px,
    transparent 14px
  );
  font-family: var(--mono);
  font-size: 11px;
  color: #4a5f5b;
}

/* ---------- reply box ---------- */

.reply-box {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 -6px 20px rgba(44, 54, 40, 0.07);
}
.quick-replies {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.quick-replies button {
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--surface-sunk);
  color: var(--ink-soft);
  cursor: pointer;
}
.quick-replies button:hover {
  border-color: var(--sage);
  background: var(--sage-wash);
  color: #4b6339;
}

/* ---------- misc ---------- */

.toolbar {
  display: flex;
  gap: 9px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.toolbar input[type="search"] {
  max-width: 300px;
  flex: 1 1 190px;
}
.toolbar select {
  max-width: 210px;
  flex: 0 1 190px;
}

.pager {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 18px;
  font-size: 14px;
  color: var(--muted);
  flex-wrap: wrap;
}

.mono {
  font-family: var(--mono);
  overflow-wrap: anywhere;
}

.card,
.metric,
.notice,
.toolbar,
.review-item {
  max-width: 100%;
}
.dim {
  color: var(--muted);
}
.truncate {
  display: block;
  max-width: min(46ch, 100%);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.review-item {
  border: 1px solid var(--line);
  border-left: 3px solid var(--slate);
  border-radius: var(--radius-sm);
  padding: 16px;
  background: var(--surface-sunk);
}

/* ---------- login ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--forest);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(44, 54, 40, 0.28);
  padding: 32px;
}
.login-card h1 {
  margin: 0 0 5px;
  font-size: 20px;
  color: var(--forest);
}
.login-card p.sub {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- responsive ---------- */

@media (max-width: 960px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  /* At narrow widths the sidebar becomes one scrolling strip. Wrapping it
     into columns turned the navigation into a puzzle. */
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: auto;
    overflow: visible;
    padding: 12px 14px;
    gap: 10px;
  }
  .brand {
    padding: 0;
  }
  .nav {
    display: flex;
    gap: 5px;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 3px;
    scrollbar-width: thin;
  }
  .nav-group {
    display: contents;
  }
  .nav-group + .nav-group {
    margin-top: 0;
  }
  .nav-label {
    display: none;
  }
  .nav a {
    white-space: nowrap;
    padding: 8px 13px;
    font-size: 14px;
  }
  .sidebar footer {
    display: none;
  }

  .main {
    padding: 20px 16px 56px;
  }
  .page-head h1 {
    font-size: 22px;
  }
  .page-head,
  .row-between {
    align-items: flex-start;
  }

  /* Tabs scroll rather than stacking into a tall block of rows. */
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: thin;
  }
  .tabs a {
    white-space: nowrap;
  }
  .grid.split {
    grid-template-columns: 1fr;
  }
  .truncate {
    max-width: min(30ch, 100%);
  }
}

@media (max-width: 620px) {
  .card {
    padding: 16px;
  }

  table,
  thead,
  tbody,
  th,
  td,
  tr {
    display: block;
  }
  thead {
    display: none;
  }
  tr {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    margin-bottom: 11px;
    padding: 12px;
    background: var(--surface);
  }
  tbody tr:hover {
    background: var(--surface);
  }
  td {
    border: none;
    padding: 5px 0;
  }
  td::before {
    content: attr(data-label);
    display: block;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 2px;
  }
  td.num {
    text-align: left;
  }
  .truncate {
    max-width: 100%;
    white-space: normal;
  }
  .btn {
    width: 100%;
  }
  .actions .btn {
    width: auto;
    flex: 1 1 auto;
  }
}
