/*
 * CrushIt support dashboard styles.
 *
 * BRANDING LIVES IN ONE PLACE -- the :root block below. Every colour in this
 * file is a var() reference, so rebranding is a matter of changing those
 * values and nothing else. The seed palette is taken from the CrushIt app
 * icon (teal #0f7a65); swap it for the official brand hexes when you have them.
 *
 * Both colour schemes are styled. Agents work night shifts around exam season
 * and a hardcoded light theme is genuinely painful at 3am.
 */

:root {
  /* --- Brand ---------------------------------------------------------- */
  --brand: #0f7a65;
  --brand-hover: #0c6150;
  --brand-deep: #0a5c4c;
  --brand-soft: #d1fae5;
  --brand-contrast: #ffffff;

  /* --- Surfaces ------------------------------------------------------- */
  --bg: #f4f7f6;
  --panel: #ffffff;
  --panel-alt: #f8faf9;
  --line: #e2e8e4;
  --line-strong: #cbd5d0;

  /* --- Text ----------------------------------------------------------- */
  --ink: #1e293b;
  --ink-soft: #475569;
  --muted: #64748b;

  /* --- Message bubbles ------------------------------------------------ */
  --incoming: #ffffff;
  --outgoing: #dcf8e8;
  --agent-bubble: #e0e7ff;

  /* --- Status --------------------------------------------------------- */
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --success: #059669;
  --success-soft: #d1fae5;

  /* --- Geometry ------------------------------------------------------- */
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.12);
  --sidebar-width: 340px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #2dd4a7;
    --brand-hover: #14b88c;
    --brand-deep: #0f7a65;
    --brand-soft: #10352c;
    --brand-contrast: #04211a;

    --bg: #0f1512;
    --panel: #161d1a;
    --panel-alt: #1c2521;
    --line: #263029;
    --line-strong: #35423a;

    --ink: #e8efeb;
    --ink-soft: #b8c5be;
    --muted: #8b9a92;

    --incoming: #1c2521;
    --outgoing: #14342a;
    --agent-bubble: #1e2540;

    --danger: #f87171;
    --danger-soft: #3b1717;
    --warning: #fbbf24;
    --warning-soft: #3a2a08;
    --success: #34d399;
    --success-soft: #0d3225;

    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--brand); }

/* ====================================================================== */
/* Auth pages (login, setup)                                              */
/* ====================================================================== */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px;
}

.auth-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.auth-card .subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 14px;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  font-weight: 700;
  font-size: 17px;
}

.brand-mark img { width: 34px; height: 34px; border-radius: 8px; }

/* ====================================================================== */
/* Forms                                                                  */
/* ====================================================================== */
label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}

input[type="text"], input[type="email"], input[type="password"],
input[type="color"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 16px;
  background: var(--panel-alt);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  border-color: var(--brand);
}

textarea { resize: vertical; min-height: 120px; font-family: ui-monospace, "Cascadia Code", Menlo, monospace; font-size: 13px; }

.hint { margin: -10px 0 16px; font-size: 12px; color: var(--muted); }

button {
  padding: 10px 16px;
  background: var(--brand);
  color: var(--brand-contrast);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover:not(:disabled) { background: var(--brand-hover); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

button.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line-strong);
}
button.secondary:hover:not(:disabled) { background: var(--panel-alt); }

button.danger { background: var(--danger); }
button.block { width: 100%; }
button.small { padding: 5px 10px; font-size: 13px; }

/* ====================================================================== */
/* Messages / banners                                                     */
/* ====================================================================== */
.notice {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}

.notice.error   { background: var(--danger-soft);  color: var(--danger);  border-color: var(--danger); }
.notice.warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning); }
.notice.success { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.notice[hidden] { display: none; }

/*
 * The outage banner (landmine #9). Deliberately loud and pinned to the top of
 * the viewport: a total AI outage produces plausible-looking fallback replies,
 * so without something impossible to ignore it can run for days unnoticed.
 */
.outage-banner {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--danger);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

.outage-banner[hidden] { display: none; }
.outage-banner .spacer { flex: 1; }
.outage-banner button {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.4);
  color: #fff;
}

/* ====================================================================== */
/* App shell                                                              */
/* ====================================================================== */
.app-shell { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.topbar .brand-mark { margin: 0; }
.topbar .spacer { flex: 1; }

.topbar nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}
.topbar nav a:hover { background: var(--panel-alt); }
.topbar nav a.active { background: var(--brand-soft); color: var(--brand-deep); }

.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-size: 12px; font-weight: 700;
  flex: 0 0 auto;
}

/* ====================================================================== */
/* Inbox layout                                                           */
/* ====================================================================== */
.workspace {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  flex: 1;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.sidebar-head { padding: 12px; border-bottom: 1px solid var(--line); }
.sidebar-head input { margin-bottom: 10px; }

.filter-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.chip {
  padding: 4px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.chip.active { background: var(--brand); color: var(--brand-contrast); border-color: var(--brand); }

.contact-list { flex: 1; overflow-y: auto; }

.contact-row {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.contact-row:hover { background: var(--panel-alt); }
.contact-row.active { background: var(--brand-soft); }

.contact-row .body { min-width: 0; flex: 1; }
.contact-row .name {
  display: flex; align-items: center; gap: 6px;
  font-weight: 600; font-size: 14px;
}
.contact-row .preview {
  color: var(--muted); font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.contact-row .meta { font-size: 11px; color: var(--muted); text-align: right; flex: 0 0 auto; }

.pill {
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.pill.human { background: var(--warning-soft); color: var(--warning); }
.pill.bot   { background: var(--brand-soft);   color: var(--brand-deep); }

.tag-row { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.tag {
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  color: #fff;
}

/*
 * The segment is the work queue, so it is styled as an outlined label rather
 * than a filled tag. That difference is load-bearing: a chat carries one
 * segment and any number of tags, and an agent scanning the inbox needs to tell
 * "which queue" from "which exam" at a glance without reading either.
 */
.segment-label {
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid currentColor;
  background: transparent;
  white-space: nowrap;
}

/* The segment chips sit directly under the status chips; a little separation
   keeps the two filter dimensions visually distinct. */
#segment-filters { margin-top: 6px; }

/* ====================================================================== */
/* Conversation                                                           */
/* ====================================================================== */
.conversation { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.conversation-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.conversation-head .spacer { flex: 1; }
.conversation-head .who { min-width: 0; }
.conversation-head .who strong { display: block; }
.conversation-head .who span { font-size: 12px; color: var(--muted); }

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: min(640px, 78%);
  padding: 8px 12px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.bubble.user      { align-self: flex-start; background: var(--incoming); border-bottom-left-radius: 4px; }
.bubble.assistant { align-self: flex-end;   background: var(--outgoing); border-bottom-right-radius: 4px; }
.bubble.agent     { align-self: flex-end;   background: var(--agent-bubble); border-bottom-right-radius: 4px; }

.bubble .stamp {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  color: var(--muted);
  text-align: right;
}

.bubble .stamp .failed { color: var(--danger); font-weight: 700; }

.bubble img, .bubble video {
  max-width: 100%;
  max-height: 320px;
  border-radius: var(--radius);
  display: block;
  margin-bottom: 6px;
}
.bubble audio { width: 100%; min-width: 240px; margin-bottom: 6px; }

.doc-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel-alt);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--ink);
  font-size: 13px;
  margin-bottom: 6px;
}

.composer {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  margin: 0;
  min-height: 44px;
  max-height: 160px;
  font-family: inherit;
  font-size: 15px;
}

.bot-notice {
  padding: 10px 16px;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-size: 13px;
  border-top: 1px solid var(--line);
}

.empty-state {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 40px;
}

/* ====================================================================== */
/* Settings page                                                          */
/* ====================================================================== */
.page { max-width: 860px; margin: 0 auto; padding: 24px 20px 64px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card h2 { margin: 0 0 4px; font-size: 17px; }
.card .card-hint { margin: 0 0 18px; color: var(--muted); font-size: 13px; }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row > * { margin-bottom: 0; }

.provider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.provider-row .spacer { flex: 1; }
.provider-row.active { border-color: var(--brand); background: var(--brand-soft); }

.badge {
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge.ok    { background: var(--success-soft); color: var(--success); }
.badge.off   { background: var(--danger-soft);  color: var(--danger); }
.badge.info  { background: var(--brand-soft);   color: var(--brand-deep); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

.scroll-x { overflow-x: auto; }

/* ====================================================================== */
/* Responsive: on a phone the inbox and conversation become separate views */
/* ====================================================================== */
@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { border-right: none; }
  body.viewing-chat .sidebar { display: none; }
  body:not(.viewing-chat) .conversation { display: none; }
  .bubble { max-width: 88%; }
}

@media (min-width: 861px) {
  .back-to-list { display: none; }
}
