:root {
  color-scheme: light;
  --navy: #071a3b;
  --navy-2: #0b285b;
  --blue: #0a73ff; /* stronger accent blue for SaaS look */
  --blue-strong: #064eb5;
  --blue-soft: #eaf4ff;
  --cyan: #4bc5ff;
  --ink: #17233d;
  --muted: #70809f;
  --line: #e4eaf3;
  --surface: #ffffff;
  --canvas: #eef6ff; /* light blue background */
  --green: #17a673;
  --amber: #d58a13;
  --danger: #c94b5b;
  --shadow: 0 18px 50px rgba(8, 30, 69, 0.06);
  --soft-shadow: 0 8px 20px rgba(10, 37, 90, 0.06);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* App shell: three/four column layout retained */
.app-shell {
  display: grid;
  grid-template-columns: 90px minmax(310px, 360px) minmax(440px, 1fr) minmax(250px, 310px);
  height: 100vh;
  background: transparent; /* background handled by body */
  gap: 18px;
  padding: 20px;
}

/* Sidebar (rail) redesigned to be white with blue active nav) */
.rail {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 18px 10px;
  background: var(--surface);
  color: var(--navy);
  border-radius: 16px;
  box-shadow: var(--soft-shadow);
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--blue), #47c6f4);
  box-shadow: 0 10px 22px rgba(10,115,255,0.12);
  overflow: hidden;
}

.brand-mark img {
  width: 80%;
  height: 80%;
  object-fit: contain;
  display: block;
}

.brand-mark.large {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 18px;
}
.rail nav { display: grid; gap: 8px; }
.rail-button {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 0;
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  font-size: 20px;
  transition: all .14s ease;
}
.rail-button:hover { color: var(--blue-strong); background: rgba(10,115,255,0.06); }
.rail-button.active {
  color: white;
  background: linear-gradient(180deg, var(--blue), var(--blue-strong));
  box-shadow: 0 8px 22px rgba(10,115,255,0.14);
  transform: translateY(-2px);
  border-left: 0; /* keep compact */
}
.rail-button.bottom { margin-top: auto; }

/* Panels: left inbox, center chat, right details */
.inbox-panel, .details-panel {
  min-width: 0;
  background: transparent; /* panels will have card-like sections */
}
.inbox-panel { display: flex; flex-direction: column; gap: 12px; }
.panel-heading, .chat-heading, .details-panel > header {
  display: flex;
  align-items: center;
  min-height: 86px;
  padding: 8px 18px;
  gap: 12px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; color: var(--navy); font-size: 22px; letter-spacing: -.035em; }
h2 { margin-bottom: 0; color: var(--navy); font-size: 16px; letter-spacing: -.025em; }
.eyebrow { margin-bottom: 4px; color: var(--blue); font-size: 10px; font-weight: 800; letter-spacing: .12em; }
.muted { color: var(--muted); }
.live-indicator { display: flex; align-items: center; gap: 6px; color: var(--green); font-size: 12px; font-weight: 650; }
.live-indicator i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(23,166,115,.12); }

/* Stats card (kept but softened) */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 8px 14px;
  overflow: hidden;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--soft-shadow);
  border: 1px solid var(--line);
}
.stats div { padding: 10px 8px; text-align: center; border-right: 1px solid var(--line); }
.stats div:last-child { border-right: 0; }

/* Search row and top controls (rounded search + New Chat button) */
.search-row { display: grid; grid-template-columns: 1fr 120px; gap: 10px; padding: 6px 14px 14px; align-items:center; }
.search-box { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 12px; background: #f7fbff; color: var(--muted); border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(12,40,85,0.03); }
.search-box input, .search-row select { width: 100%; height: 40px; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 13px; }

/* NEW CHAT button - prominent */
.new-conversation-button, .btn-new-chat {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  color: #fff;
  background: linear-gradient(90deg, var(--blue), var(--blue-strong));
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(10,115,255,0.14);
}

/* Conversation list - rounded cards with avatars and badges */
.conversation-list { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: grid; gap: 12px; }
.conversation-item {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border: 0;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--soft-shadow);
  text-align: left;
  align-items: center;
  transition: transform .12s ease, box-shadow .12s ease;
}
.conversation-item:hover { transform: translateY(-3px); box-shadow: 0 14px 30px rgba(12,40,85,0.06); }
.conversation-item.active { background: linear-gradient(90deg, rgba(10,115,255,0.06), rgba(47,143,255,0.02)); box-shadow: 0 8px 26px rgba(10,115,255,0.06); border-left: 4px solid var(--blue); }

.avatar {
  display: grid;
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, #dbeaff, #edf5ff);
  color: var(--blue-strong);
  font-weight: 900;
}

.conversation-copy { min-width: 0; }
.conversation-top { display: flex; align-items: center; gap: 8px; }
.conversation-copy strong { overflow: hidden; color: var(--navy); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-copy p { overflow: hidden; margin: 6px 0 0; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.mode-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; }
.mode-dot.ai { background: var(--blue); }
.mode-dot.human { background: var(--amber); }
.conversation-time { color: #9aa6bd; font-size: 11px; white-space: nowrap; }

/* Center chat panel - card with rounded corners and soft shadow */
.chat-panel { min-width: 0; background: var(--surface); border-radius: 14px; box-shadow: var(--soft-shadow); display: flex; flex-direction: column; overflow: hidden; }
.blank-chat { display: grid; height: 100%; place-content: center; padding: 30px; text-align: center; }
.blank-chat p { color: var(--muted); }
.blank-icon { display: grid; width: 64px; height: 64px; margin: 0 auto 18px; place-items: center; border-radius: 22px; background: var(--blue-soft); color: var(--blue-strong); font-size: 27px; }
.chat-content { display: grid; grid-template-rows: auto auto 1fr auto; height: 100%; }
.chat-heading { gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); background: transparent; }
.chat-identity { min-width: 0; flex: 1; }
.chat-identity p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.assignment-badge { padding: 6px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; letter-spacing: .06em; }
.assignment-badge.ai { color: var(--blue-strong); background: var(--blue-soft); }
.assignment-badge.human { color: #a36707; background: #fff4dd; }
.assignment-button { padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--navy); background: white; font-size: 12px; font-weight: 750; }
.assignment-button:hover { border-color: var(--blue); color: var(--blue); }

/* Messages */
.messages { min-height: 0; padding: 20px; overflow-y: auto; display:flex; flex-direction:column; gap:12px; background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.02) 100%); }
.message-row { display: flex; margin-bottom: 8px; }
.message-row.outbound { justify-content: flex-end; }
.bubble { max-width: min(78%, 520px); padding: 12px 14px; border-radius: 14px; background: var(--surface); box-shadow: 0 6px 18px rgba(12,40,85,0.04); }
.outbound .bubble { color: #fff; border-radius: 14px; background: linear-gradient(135deg, var(--blue), var(--blue-strong)); }
.bubble.failed { outline: 2px solid rgba(201,75,91,.32); }
.bubble p { margin: 0; font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.bubble footer { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; color: #97a3ba; font-size: 11px; }
.outbound .bubble footer { color: rgba(255,255,255,.85); }
.sender-label { font-weight: 800; text-transform: uppercase; font-size: 11px; }

/* Composer / reply box */
.composer { padding: 12px 20px 18px; border-top: 1px solid var(--line); background: transparent; }
.composer-notice { margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.composer-row { display: flex; align-items: flex-end; gap: 9px; }
.composer textarea { width: 100%; max-height: 140px; resize: none; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; outline: 0; background: #f7fbff; font-size: 14px; }
.composer textarea:focus { border-color: rgba(10,115,255,0.18); box-shadow: 0 8px 24px rgba(10,115,255,0.06); }
.send-button { display: grid; width: 46px; height: 46px; flex: 0 0 auto; place-items: center; border: 0; border-radius: 12px; color: white; background: var(--blue); font-size: 20px; box-shadow: 0 10px 26px rgba(10,115,255,0.12); }
.send-button:disabled { cursor: not-allowed; opacity: .5; box-shadow: none; }

/* Details / profile panel */
.details-panel { border-right: 0; border-left: 0; overflow-y: auto; }
.details-panel .profile-card { margin: 18px; padding: 16px; border-radius: 14px; background: var(--surface); box-shadow: var(--soft-shadow); }
.order-details { padding: 18px; }
.order-card { overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.order-status-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 13px; background: var(--blue-soft); }
.order-status-row span { color: var(--muted); font-size: 11px; font-weight: 750; text-transform: uppercase; }

.detail-row { padding: 12px 13px; border-top: 1px solid var(--line); }
.detail-row label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.detail-row p { margin: 0; color: var(--ink); font-size: 13px; line-height: 1.45; white-space: pre-wrap; }
.missing { color: #a9b2c4 !important; font-style: italic; }
.empty-state { padding: 32px 20px; color: var(--muted); font-size: 12px; text-align: center; }
.empty-state.compact { padding: 20px 5px; }

/* Overlays and modals - keep existing behaviour */
.auth-overlay { position: fixed; z-index: 20; display: grid; inset: 0; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 10%, #133c7f, #061735 58%); }
.auth-card { width: min(100%, 420px); padding: 28px; border: 1px solid rgba(255,255,255,.10); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.auth-card h1 { text-align: center; }
.auth-card > p { text-align: center; }
.auth-card label { display: block; margin: 18px 0 7px; color: var(--ink); font-size: 12px; font-weight: 750; }
.auth-card input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 11px; outline: 0; }
.auth-card input:focus { border-color: var(--blue); box-shadow: 0 8px 28px rgba(10,115,255,0.06); }
.primary { padding: 12px 16px; border: 0; border-radius: 11px; color: white; background: var(--blue); font-weight: 750; }
.wide { width: 100%; }
.form-error { min-height: 18px; margin: 8px 0; color: var(--danger); font-size: 12px; }
.toast { position: fixed; z-index: 30; right: 22px; bottom: 22px; max-width: 360px; padding: 12px 15px; border-radius: 11px; opacity: 0; transform: translateY(12px); pointer-events: none; color: white; background: var(--blue); box-shadow: 0 8px 20px rgba(10,115,255,0.12); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

/* Responsive adjustments */
@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 78px 320px 1fr; }
  .details-panel { display: none; }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 62px 1fr; }
  .rail { padding: 14px 8px; }
  .brand-mark { width: 36px; height: 36px; border-radius: 11px; font-size: 13px; }
  .rail-button { width: 38px; height: 38px; }
  .inbox-panel { grid-column: 2; }
  .chat-panel { position: fixed; z-index: 5; display: none; inset: 0 0 0 58px; }
  body.chat-open .chat-panel { display: block; }
  .mobile-back { display: block; }
  .chat-heading { padding: 12px; }
  .chat-heading .avatar { display: none; }
  .assignment-badge { display: none; }
  .assignment-button { padding: 8px; }
  .messages { padding: 16px 12px; }
  .bubble { max-width: 88%; }
}
