:root {
  --purple: #6c3cff;
  --purple-dark: #5125d8;
  --purple-soft: #f0ebff;
  --navy: #0f172a;
  --green: #22c55e;
  --blue: #0ea5e9;
  --orange: #f59e0b;
  --red: #ef4444;
  --slate: #64748b;
  --line: #e2e8f0;
  --bg: #f8fafc;
  --card: #ffffff;
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--navy); background: var(--bg); }
a { color: var(--purple); text-decoration: none; }
h1,h2,h3,p { margin-top: 0; }
input, textarea, select, button { font: inherit; }
input, textarea, select {
  width: 100%; border: 1px solid #cbd5e1; border-radius: 10px; padding: 11px 12px;
  background: #fff; color: var(--navy); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(108,60,255,.12); }
label { display: grid; gap: 7px; font-weight: 650; font-size: 14px; color: #334155; }
small { display: block; color: var(--slate); margin-top: 4px; font-weight: 500; }
code { display: block; overflow-wrap: anywhere; margin-top: 7px; padding: 10px; border-radius: 9px; background: #160c3b; color: #d9ccff; }
.muted { color: var(--slate); font-weight: 500; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; background: #fff; border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 5px 10px 24px; font-size: 28px; font-weight: 850; color: var(--navy); }
.brand > span:last-child > span { color: var(--purple); }
.brand-icon { display: grid; place-items: center; width: 42px; height: 36px; border-radius: 12px 12px 12px 4px; color: white; background: linear-gradient(135deg, #7c3cff, #5316d2); font-size: 15px; letter-spacing: 1px; box-shadow: 0 10px 24px rgba(108,60,255,.23); }
.sidebar nav { display: grid; gap: 5px; }
.nav-link { padding: 12px 14px; border-radius: 10px; color: #334155; font-weight: 650; }
.nav-link:hover, .nav-link.active { color: var(--purple); background: var(--purple-soft); }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); padding: 16px 10px 2px; }
.workspace-chip { font-weight: 750; margin-bottom: 12px; }
.link-button { border: 0; background: none; padding: 0; color: var(--slate); cursor: pointer; }
.main-content { min-width: 0; }
.topbar { height: 68px; padding: 0 30px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.92); }
.topbar > div:first-child { display: grid; gap: 2px; }
.user-chip { background: var(--purple-soft); color: var(--purple); width: auto; min-width: 38px; height: 38px; border-radius: 20px; padding: 0 13px; display: flex; align-items: center; gap: 9px; font-weight: 800; }
.user-chip span { color: #334155; font-weight: 650; }
.page { padding: 28px 32px 48px; max-width: 1500px; margin: 0 auto; }
.page-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
.page-heading h1 { font-size: 30px; margin-bottom: 5px; }
.page-heading p { color: var(--slate); margin-bottom: 0; }
.alert { border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; margin-bottom: 16px; background: #fff; }
.alert-success { border-color: #86efac; background: #f0fdf4; color: #166534; }
.alert-error { border-color: #fca5a5; background: #fef2f2; color: #991b1b; }
.secret-panel { background: linear-gradient(135deg, #20104e, #492099); color: white; border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: 0 15px 40px rgba(72,32,153,.16); }
.secret-panel h2 { margin-bottom: 5px; }
.secret-panel p { color: #ddd2ff; }
.secret-panel label { color: white; margin-top: 13px; }
.stat-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: 0 4px 13px rgba(15,23,42,.03); }
.stat-card span { color: var(--slate); font-size: 13px; font-weight: 700; }
.stat-card strong { display: block; font-size: 30px; margin-top: 7px; }
.stat-card strong small { display: inline; font-size: 17px; color: #94a3b8; }
.stat-card .small-value, .small-value { font-size: 17px; overflow-wrap: anywhere; }
.stat-card.danger strong { color: var(--red); }
.dashboard-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 18px; margin-bottom: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 5px 16px rgba(15,23,42,.035); overflow: hidden; }
.card:not(.table-card):not(.inbox-shell) { padding: 22px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; gap: 12px; }
.card-head h2 { font-size: 20px; margin-bottom: 4px; }
.card-head p { color: var(--slate); font-size: 14px; margin-bottom: 0; }
.stack { display: grid; gap: 15px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn { border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 750; cursor: pointer; width: fit-content; }
.btn-primary { color: white; background: linear-gradient(135deg, #7c3cff, #5a23df); box-shadow: 0 8px 18px rgba(108,60,255,.22); }
.btn-primary:hover { background: var(--purple-dark); }
.device-list { display: grid; }
.device-row { display: grid; grid-template-columns: 12px 1fr auto; gap: 12px; align-items: center; padding: 13px 2px; border-bottom: 1px solid var(--line); color: var(--navy); }
.device-row:last-child { border-bottom: 0; }
.device-row b { font-size: 12px; color: var(--slate); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #94a3b8; }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 4px rgba(34,197,94,.12); }
.status-dot.offline { background: #94a3b8; }
.table-card .card-head { padding: 20px 22px 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 14px 16px; text-align: left; border-top: 1px solid var(--line); vertical-align: middle; }
th { color: var(--slate); background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td { font-size: 14px; }
.message-cell { max-width: 330px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-cell { text-align: center; color: var(--slate); padding: 34px; }
.badge { display: inline-flex; align-items: center; padding: 5px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; letter-spacing: .02em; background: #e2e8f0; color: #475569; }
.status-online, .status-delivered, .status-received, .status-sent { background: #dcfce7; color: #166534; }
.status-sent { background: #e0f2fe; color: #075985; }
.status-queued, .status-assigned { background: #fef3c7; color: #92400e; }
.status-failed, .status-revoked { background: #fee2e2; color: #991b1b; }
.status-offline, .status-pending { background: #e2e8f0; color: #475569; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--slate); }
.empty-state.compact { padding: 34px 16px; }
.empty-state h2, .empty-state h3 { color: var(--navy); }
.sim-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.sim-card { border: 1px solid var(--line); background: #fafafa; border-radius: 12px; padding: 15px; display: grid; gap: 5px; }
.sim-card span { color: var(--purple); font-weight: 800; font-size: 12px; }
.inbox-shell { min-height: 680px; display: grid; grid-template-columns: 360px 1fr; }
.conversation-list { border-right: 1px solid var(--line); min-width: 0; }
.conversation-head, .thread-head { padding: 20px; border-bottom: 1px solid var(--line); }
.conversation-head h2, .thread-head h2 { margin-bottom: 0; font-size: 20px; }
.thread-head p { color: var(--slate); margin: 4px 0 0; }
.conversation-item { display: grid; grid-template-columns: 42px 1fr auto; gap: 11px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); color: var(--navy); }
.conversation-item:hover, .conversation-item.active { background: var(--purple-soft); }
.avatar { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: #e9e1ff; color: var(--purple); font-weight: 850; }
.unread { min-width: 22px; height: 22px; border-radius: 11px; display: grid; place-items: center; background: var(--purple); color: white; font-size: 11px; }
.thread-panel { min-width: 0; display: flex; flex-direction: column; }
.thread-messages { flex: 1; padding: 22px; overflow-y: auto; max-height: 520px; background: #fbfcff; }
.bubble-row { display: flex; margin-bottom: 13px; }
.bubble-row.outbound { justify-content: flex-end; }
.bubble { max-width: 70%; border-radius: 15px 15px 15px 4px; background: #fff; border: 1px solid var(--line); padding: 11px 13px; box-shadow: 0 3px 10px rgba(15,23,42,.035); }
.outbound .bubble { background: var(--purple); color: white; border-color: var(--purple); border-radius: 15px 15px 4px 15px; }
.bubble p { margin-bottom: 6px; white-space: pre-wrap; }
.bubble small { font-size: 11px; }
.outbound .bubble small { color: #ddd2ff; }
.composer { padding: 16px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.composer-controls { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.composer textarea { min-height: 75px; }
.composer .btn { align-self: stretch; }
.thread-empty { margin: auto; }
.empty-icon { margin: 0 auto 15px; width: 58px; height: 50px; display: grid; place-items: center; background: var(--purple-soft); color: var(--purple); border-radius: 16px; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top, #eee8ff, #f8fafc 48%); }
.auth-card { width: min(430px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 30px; box-shadow: 0 22px 60px rgba(15,23,42,.11); }
.auth-card.wide { width: min(520px, 100%); }
.auth-brand { padding: 0 0 24px; }
.auth-card h1 { margin-bottom: 7px; }
.auth-switch { text-align: center; margin: 18px 0 0; color: var(--slate); }
.field-error, .errorlist { color: #b91c1c; font-size: 12px; list-style: none; margin: 4px 0 0; padding: 0; }

@media (max-width: 1050px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .inbox-shell { grid-template-columns: 310px 1fr; }
}
@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 10px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding-bottom: 10px; }
  .sidebar nav { grid-template-columns: repeat(3, 1fr); }
  .nav-link { text-align: center; padding: 10px 5px; font-size: 13px; }
  .sidebar-foot, .topbar { display: none; }
  .page { padding: 20px 14px 40px; }
  .stat-grid, .stat-grid.four { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .inbox-shell { display: block; }
  .conversation-list { border-right: 0; }
  .thread-panel { min-height: 580px; }
  .bubble { max-width: 88%; }
}
