:root {
  font-family: Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  color: #334155;
  background: #f8fafc;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-glow: rgba(79, 70, 229, .12);
  --heading: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --sidebar-width: 260px;
}
* { box-sizing: border-box; }
body { margin: 0; font-size: .92rem; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }
.hidden { display: none !important; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3, strong { color: var(--heading); }

.brand { display: flex; align-items: center; gap: .5rem; color: var(--primary); font-size: 1.3rem; font-weight: 800; letter-spacing: -.03em; white-space: nowrap; }
.brand i { font-size: 1.35rem; }
.entry-view { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, #e0e7ff, #f1f5f9); }
.entry-card { width: min(100%, 440px); display: grid; gap: 16px; padding: 2.5rem; background: #fff; border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 10px 15px -3px #0f172a0d, 0 4px 6px -4px #0f172a0d; }
.entry-card .brand { justify-content: center; font-size: 1.8rem; }
.entry-card h1 { text-align: center; font-size: 1.55rem; margin: 8px 0 0; }
.entry-card p { color: var(--muted); text-align: center; line-height: 1.5; }
.entry-card label { display: grid; gap: 7px; font-size: .88rem; font-weight: 600; }

input, textarea, select { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: var(--heading); outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
button { min-height: 44px; border: 1px solid transparent; border-radius: 8px; padding: 10px 14px; font-weight: 600; }
.primary { background: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-hover); }
.secondary { background: #fff; border-color: #cbd5e1; color: #334155; }
.secondary:hover { background: #f1f5f9; }
.text-button { background: transparent; color: var(--primary); }
.app-link { display: grid; place-items: center; min-height: 44px; border: 1px solid #cbd5e1; border-radius: 8px; padding: 10px 14px; color: #334155; text-align: center; text-decoration: none; font-weight: 600; }
.app-link:hover { background: #f1f5f9; }
.schedule-card { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-radius: 12px; background: #f1f5f9; }
.schedule-card strong { font-size: 23px; color: var(--primary); }
.notice { margin: 0; font-size: .85rem; color: #92400e !important; }

.app { min-height: 100dvh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.sidebar { display: flex; flex-direction: column; min-height: 100dvh; background: #fff; border-right: 1px solid var(--border); }
.sidebar > .brand { height: 70px; padding: 0 24px; border-bottom: 1px solid var(--border); }
.sidebar nav { display: flex; flex-direction: column; gap: 3px; padding: 18px 12px; }
.menu-label { color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 13px 12px 6px; }
.sidebar nav button, .back-link { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 43px; padding: 9px 12px; border: 0; border-radius: 8px; background: transparent; color: #334155; text-align: left; text-decoration: none; font-weight: 500; }
.sidebar nav button i, .back-link i { font-size: 1.05rem; }
.sidebar nav button:hover, .back-link:hover { background: #f8fafc; color: var(--heading); }
.sidebar nav button.active { background: var(--primary-glow); color: var(--primary); font-weight: 700; }
.indicator { display: inline-block; width: 8px; height: 8px; margin-left: auto; border-radius: 50%; background: #94a3b8; }
.indicator.ready { background: #10b981; }
.sidebar-foot { display: grid; gap: 7px; margin-top: auto; padding: 16px 20px; border-top: 1px solid var(--border); background: #f8fafc; font-size: .84rem; }
.sidebar-foot > span { color: var(--heading); font-weight: 700; padding: 2px 0 8px; }
.sidebar-foot > button { min-height: 40px; padding: 7px 10px; border: 1px solid var(--border); background: #fff; color: #334155; text-align: left; }
.sidebar-foot > button:hover { border-color: #cbd5e1; }
.sidebar-foot summary { cursor: pointer; padding: 8px 0; color: var(--muted); }
.sidebar-foot details form { padding: 10px 0; }
.sidebar-foot input { min-width: 0; }

.workspace { min-width: 0; padding: 0 30px 32px; }
.workspace header { display: flex; justify-content: space-between; align-items: center; gap: 14px; min-height: 70px; margin: 0 -30px 30px; padding: 10px 30px; background: #fff; border-bottom: 1px solid var(--border); }
.workspace h1 { font-size: 1.42rem; margin: 2px 0 0; }
.eyebrow { color: var(--muted); font-size: .68rem; font-weight: 700; letter-spacing: .08em; }
.workspace header span { color: var(--muted); font-size: .84rem; }
.section-grid { display: grid; grid-template-columns: minmax(270px, 350px) minmax(0, 1fr); gap: 18px; min-height: calc(100dvh - 132px); }
.panel { min-width: 0; padding: 22px; background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 1px 2px #0f172a0d; }
.panel h2 { font-size: 1.12rem; }
.list-panel { display: flex; flex-direction: column; gap: 12px; }
.scroll-list { display: grid; align-content: start; gap: 8px; max-height: calc(100dvh - 265px); overflow: auto; }
.list-item { display: grid; gap: 5px; width: 100%; text-align: left; background: #fff; color: var(--heading); border: 1px solid var(--border); }
.list-item:hover, .list-item.selected { background: #f5f3ff; border-color: #a5b4fc; }
.list-item small, .small-muted { color: var(--muted); font-size: .8rem; }
.detail-panel { max-height: calc(100dvh - 132px); overflow: auto; }
.empty { display: grid; place-items: center; min-height: 180px; height: 100%; color: var(--muted); text-align: center; }
.meta { display: flex; flex-wrap: wrap; gap: 7px; margin: 10px 0 18px; }
.chip { padding: 6px 9px; background: #f1f5f9; border-radius: 8px; color: #475569; font-size: .78rem; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.stack { display: grid; gap: 12px; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.case-card, .message-card { padding: 14px; margin-bottom: 9px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.case-card { display: grid; gap: 7px; }
.case-card button { justify-self: start; }
.message-card p { white-space: pre-wrap; margin: 8px 0; }
.message-card small { color: var(--muted); }
.system-status { display: grid; gap: 10px; padding: 16px; margin: 14px 0; border: 1px solid #c7d2fe; border-radius: 12px; background: #f8faff; }
.system-status h3 { margin: 0; font-size: .95rem; }
.system-device { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.system-device > .status-pill { justify-self: start; }
.system-device .meta { margin: 0; }
.system-device p { margin: 0; }
.case-close { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.message { padding: 11px 15px; border: 1px solid #a7f3d0; border-radius: 8px; background: #ecfdf5; color: #065f46; }
.message.error { border-color: #fecaca; background: #fef2f2; color: #991b1b; }
.inline-form { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; }
.inline-form > * { flex: 1; }
.team-panel { max-width: 1000px; }
.archive-toggle { display: flex; align-items: center; gap: 8px; width: fit-content; margin: 16px 0 4px; color: var(--muted); font-size: .83rem; cursor: pointer; }
.archive-toggle input { width: 18px; min-height: 18px; height: 18px; }
.team-user { padding: 16px; margin-top: 14px; border: 1px solid var(--border); border-radius: 10px; }
.team-user .inline-form { margin-top: 12px; }
.team-user > .primary { margin-top: 12px; }
.form-error { color: #b91c1c !important; }
.form-success { color: #047857 !important; }
.credentials-text { white-space: pre-wrap; user-select: text; }
.schedule-days { display: grid; grid-template-columns: repeat(7, minmax(95px, 1fr)); gap: 8px; margin-top: 12px; }
.schedule-days label { color: var(--muted); font-size: .78rem; }
.schedule-days input { margin-top: 5px; }

.chat-workspace { grid-template-columns: minmax(300px, 360px) minmax(0, 1fr); }
.chat-list-head, .chat-item-title, .chat-detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.chat-list-head h2 { margin: 3px 0 0; }
.count-pill, .status-pill { flex: none; padding: 6px 9px; border-radius: 999px; background: #eef2ff; color: var(--primary); font-size: .72rem; font-weight: 700; }
.status-pill { background: #f1f5f9; color: var(--muted); }
.status-pill.is-open { background: #dcfce7; color: #166534; }
.chat-filters { display: flex; gap: 8px; }
.chat-filters select { flex: 1; }
.chat-filters button { flex: none; }
.chat-inbox .scroll-list { gap: 7px; }
.chat-item { padding: 13px; border-radius: 12px; }
.chat-item.needs-reply { border-left: 4px solid #f59e0b; }
.reply-needed { justify-self: start; padding: 3px 7px; border-radius: 999px; background: #fffbeb; color: #92400e; font-size: .7rem; font-weight: 700; }
.chat-item-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-title small { flex: none; font-size: .7rem; }
.unread-pill { flex: none; min-width: 21px; padding: 2px 6px; border-radius: 99px; background: #4f46e5; color: #fff; text-align: center; font-size: .7rem; font-weight: 700; }
.chat-notifications { width: 100%; font-size: .78rem; }
.chat-item-meta { color: #4338ca !important; font-weight: 600; }
.chat-item-preview { overflow: hidden; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; font-size: .82rem; }
.chat-detail { display: flex; flex-direction: column; gap: 10px; max-height: calc(100dvh - 132px); }
.chat-detail-head { position: sticky; top: -22px; z-index: 1; margin: -22px -22px 3px; padding: 22px; border-bottom: 1px solid var(--border); background: #fff; }
.chat-detail-head h2 { margin: 4px 0; }
.chat-detail-head p { margin: 0; }
.chat-head-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chat-head-actions button { min-height: 36px; padding: 7px 10px; font-size: .78rem; }
.chat-thread { display: flex; flex: 1; flex-direction: column; gap: 10px; min-height: 220px; max-height: 48vh; overflow-y: auto; padding: 16px; border-radius: 12px; background: #f8fafc; }
.chat-day { align-self: center; padding: 4px 10px; border-radius: 999px; background: #e2e8f0; color: #475569; font-size: .72rem; font-weight: 700; }
.chat-bubble { width: fit-content; max-width: min(85%, 620px); margin: 0; box-shadow: 0 1px 2px #0f172a0d; }
.chat-bubble.inbound { align-self: flex-start; }
.chat-bubble.outbound { align-self: flex-end; background: #eef2ff; border-color: #c7d2fe; }
.chat-bubble p { overflow-wrap: anywhere; }
.reply-notice { margin: 2px 0; color: var(--muted); font-size: .8rem; }
.reply-composer { display: flex; align-items: end; gap: 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.reply-composer textarea { min-height: 80px; resize: vertical; }
.reply-composer button { flex: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { min-height: 0; }
  .sidebar > .brand { height: 60px; }
  .sidebar nav { flex-direction: row; overflow: auto; padding: 8px 12px; }
  .sidebar nav button, .back-link { width: auto; flex-shrink: 0; white-space: nowrap; }
  .menu-label { display: none; }
  .sidebar-foot { display: flex; align-items: center; flex-wrap: wrap; }
  .workspace { padding: 0 16px 24px; }
  .workspace header { margin: 0 -16px 20px; padding: 10px 16px; }
  .section-grid { grid-template-columns: 1fr; min-height: 0; }
  .scroll-list, .detail-panel { max-height: none; }
  .schedule-days { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chat-workspace { grid-template-columns: 1fr; }
  .chat-inbox .scroll-list { max-height: 280px; }
  .chat-detail { max-height: none; }
  .chat-detail-head { top: 0; }
  .chat-thread { min-height: 300px; max-height: 52vh; }
  .reply-composer { flex-direction: column; align-items: stretch; }
}
