:root {
  --violet: #7c3aed;
  --indigo: #4f46e5;
  --blue: #2563eb;
  --sky: #0ea5e9;
  --brand-gradient: linear-gradient(135deg, var(--violet) 0%, var(--indigo) 45%, var(--blue) 75%, var(--sky) 100%);
  --accent: var(--indigo);
  --accent-soft: #eef0ff;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --border: #ecedf4;
  --text: #16172b;
  --muted: #80829c;
  --bubble-in: #ffffff;
  --bubble-out: #ece9ff;
  --ink: #15162a;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }

@media (prefers-reduced-motion: no-preference) {
  .panel-card, .kpi-tile, .page-fade { animation: fadeUp .35s ease both; }
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--brand-gradient); }
.login-card { background: var(--panel); padding: 38px 34px; border-radius: 16px; box-shadow: 0 20px 50px rgba(79,70,229,.25); width: 320px; animation: fadeUp .4s ease both; }
.login-logo { display: block; width: 64px; height: 64px; border-radius: 14px; object-fit: cover; margin: 0 auto 14px; }
.login-card h1 { margin: 0; font-size: 20px; text-align: center; background: var(--brand-gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-card .sub { margin: 4px 0 20px; color: var(--muted); font-size: 13px; text-align: center; }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.login-card input { width: 100%; margin-top: 4px; padding: 10px; border: 1px solid var(--border); border-radius: 9px; font-size: 14px; transition: border-color .15s, box-shadow .15s; }
.login-card input:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button { width: 100%; padding: 11px; background: var(--brand-gradient); color: #fff; border: none; border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer; transition: transform .12s, box-shadow .12s; }
.login-card button:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(79,70,229,.3); }
.login-card .error { background: #fde8e8; color: #b42318; padding: 8px 10px; border-radius: 6px; font-size: 13px; margin-bottom: 14px; }

/* ===== App shell: white sidebar, pill active state, top appbar ===== */
.shell { height: 100vh; display: flex; }

.sidebar { width: 216px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.sidebar-brand { padding: 20px 18px 16px; font-weight: 700; font-size: 14.5px; display: flex; align-items: center; gap: 9px; color: var(--ink); }
.brand-logo { width: 26px; height: 26px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
.brand-sub { display: block; font-weight: 400; font-size: 10.5px; color: var(--muted); margin-left: 4px; }
.sidebar-nav { flex: 1; padding: 6px 12px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: #585a72; text-decoration: none; font-size: 13.5px; transition: background .15s, color .15s; }
.sidebar-nav a:hover { background: #f4f4fa; color: var(--ink); }
.sidebar-nav a.active { background: var(--ink); color: #fff; font-weight: 600; }
.nav-icon { font-size: 12px; width: 16px; text-align: center; }
.sidebar-user { display: flex; align-items: center; gap: 9px; padding: 14px 18px 4px; border-top: 1px solid var(--border); margin-top: 6px; }
.sidebar-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-gradient); color: #fff; font-size: 11.5px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-user-name { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.sidebar-user-role { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.sidebar-signout { display: block; margin: 6px 18px 16px; font-size: 12px; color: var(--muted); text-decoration: none; transition: color .15s; }
.sidebar-signout:hover { color: var(--indigo); text-decoration: underline; }

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.appbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--panel); flex-shrink: 0; }
.appbar-search { flex: 1; max-width: 340px; display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.appbar-search-icon { font-size: 12px; opacity: .6; }
.appbar-search input { border: none; background: none; outline: none; font-size: 13px; width: 100%; color: var(--text); }
.appbar-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.appbar-clock { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.appbar-icon-btn { width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--border); background: var(--panel); cursor: pointer; font-size: 13px; transition: background .15s; }
.appbar-icon-btn:hover { background: var(--bg); }
.appbar-account { display: flex; align-items: center; gap: 9px; padding-left: 12px; border-left: 1px solid var(--border); }
.appbar-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-gradient); color: #fff; font-size: 11.5px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.appbar-account-name { font-size: 12.5px; font-weight: 600; }
.appbar-account-role { font-size: 11px; color: var(--muted); }

.content-body { flex: 1; overflow-y: auto; padding: 22px 26px 30px; min-height: 0; }
.content-body--flush { padding: 0; overflow: hidden; display: flex; }

.page-heading { margin-bottom: 18px; }
.page-heading h1 { margin: 0; font-size: 21px; letter-spacing: -.2px; }
.page-heading p { margin: 3px 0 0; font-size: 13px; color: var(--muted); }

@media (max-width: 860px) {
  .sidebar { width: 64px; }
  .brand-sub, .sidebar-nav a span:not(.nav-icon), .sidebar-user-name, .sidebar-user-role, .sidebar-signout, .sidebar-user > div { display: none; }
  .sidebar-nav a { justify-content: center; }
  .sidebar-brand { justify-content: center; padding: 20px 0 16px; }
  .appbar-search { max-width: 160px; }
  .appbar-account-name, .appbar-account-role { display: none; }
}

/* ===== KPI tiles ===== */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi-tile { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; position: relative; overflow: hidden; transition: transform .15s, box-shadow .15s; }
.kpi-tile:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(21,22,42,.08); }
.kpi-tile .num { font-size: 25px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }
.kpi-tile .label { font-size: 11.5px; color: var(--muted); margin-top: 3px; text-transform: uppercase; letter-spacing: .3px; }
.kpi-tile--highlight { background: var(--brand-gradient); border: none; color: #fff; }
.kpi-tile--highlight .num { color: #fff; }
.kpi-tile--highlight .label { color: rgba(255,255,255,.8); }
.kpi-tile--highlight::after { content: "IN FOCUS"; position: absolute; top: 14px; right: 14px; font-size: 9px; font-weight: 700; letter-spacing: .4px; background: rgba(255,255,255,.2); padding: 3px 8px; border-radius: 20px; }

.panel-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; margin-bottom: 20px; }
.panel-card h2 { margin: 0 0 14px; font-size: 14px; }

/* ===== Tables ===== */
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--border); }
table.data-table td { padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tr { transition: background .12s; }
table.data-table tr:hover td { background: #fafafe; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table select, table.data-table input[type=text] { padding: 5px 7px; border: 1px solid var(--border); border-radius: 6px; font-size: 12.5px; font-family: inherit; background: var(--bg); }
.link-btn { background: none; border: none; color: var(--indigo); cursor: pointer; font-size: 13px; padding: 0; text-decoration: none; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }

.name-cell { display: flex; align-items: center; gap: 10px; }
.avatar-circle { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; }
.name-cell-text strong { display: block; font-size: 13px; }
.name-cell-text span { font-size: 11.5px; color: var(--muted); }

.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; padding: 3px 10px 3px 8px; border-radius: 20px; text-transform: capitalize; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.status-new { background: #eef0ff; color: var(--indigo); } .status-new .status-dot { background: var(--indigo); animation: pulse 2s ease-in-out infinite; }
.status-contacted { background: #fff6da; color: #8a6d0a; } .status-contacted .status-dot { background: #c99a0a; }
.status-quoted { background: #e0f2fe; color: #0369a1; } .status-quoted .status-dot { background: var(--sky); }
.status-booked { background: #dcf7e8; color: #0a7a3d; } .status-booked .status-dot { background: #16a34a; }
.status-lost { background: #f1f1f6; color: #80829c; } .status-lost .status-dot { background: #80829c; }

/* Segmented tabs (status filter) */
.seg-tabs { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg-tab { border: none; background: none; padding: 6px 13px; font-size: 12.5px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; transition: background .15s, color .15s; }
.seg-tab.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(21,22,42,.12); }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: var(--panel); }
.toolbar input[type=text] { flex: 1; min-width: 160px; }

.btn-primary { background: var(--brand-gradient); color: #fff; border: none; border-radius: 9px; padding: 9px 16px; font-size: 13px; cursor: pointer; font-weight: 600; transition: transform .12s, box-shadow .12s; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(79,70,229,.28); }
.btn-primary:disabled { opacity: .6; cursor: default; transform: none; box-shadow: none; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.form-grid label { font-size: 12px; color: var(--muted); display: block; }
.form-grid input, .form-grid select { width: 100%; margin-top: 4px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; transition: border-color .15s, box-shadow .15s; }
.form-grid input:focus, .form-grid select:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px var(--accent-soft); }

.pill { display: inline-block; font-size: 10.5px; padding: 2px 9px; border-radius: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.pill-active { background: #dcf7e8; color: #0a7a3d; }
.pill-inactive { background: #f1f1f6; color: #80829c; }
.toast { font-size: 12.5px; color: #0a7a3d; margin-top: 4px; height: 16px; transition: opacity .2s; }
.hint { font-size: 12px; color: var(--muted); margin-top: -6px; margin-bottom: 14px; }

/* ===== Inbox (conversation list / thread / lead panel) ===== */
.layout { flex: 1; display: grid; grid-template-columns: 300px 1fr 280px; min-height: 0; width: 100%; }

.conv-list { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.conv-filters { padding: 10px; border-bottom: 1px solid var(--border); }
.conv-filters select { width: 100%; padding: 6px; border-radius: 8px; border: 1px solid var(--border); }
.conv-items { overflow-y: auto; flex: 1; }
.conv-item { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; border-left: 3px solid transparent; transition: background .12s, border-color .12s; }
.conv-item:hover { background: #fafafe; }
.conv-item.active { background: var(--accent-soft); border-left-color: var(--indigo); }
.conv-item-top { display: flex; justify-content: space-between; align-items: baseline; }
.conv-item-name { font-weight: 600; font-size: 14px; }
.conv-item-time { font-size: 11px; color: var(--muted); }
.conv-item-preview { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-block; font-size: 10px; padding: 2px 7px; border-radius: 10px; margin-top: 5px; text-transform: uppercase; letter-spacing: .3px; }
.badge-new { background: #eef0ff; color: var(--indigo); animation: pulse 2s ease-in-out infinite; }
.badge-contacted { background: #fff6da; color: #92740c; }
.badge-quoted { background: #e0f2fe; color: #0369a1; }
.badge-booked { background: #dcf7e8; color: #0a7a3d; }
.badge-lost { background: #f1f1f6; color: #80829c; }

.thread { display: flex; flex-direction: column; min-height: 0; background: #f0eefb; }
.thread-empty { margin: auto; color: var(--muted); }
.thread-active { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.thread-header { background: var(--panel); padding: 12px 18px; border-bottom: 1px solid var(--border); }
.thread-name { font-weight: 600; }
.thread-phone { font-size: 12px; color: var(--muted); }
.thread-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 60%; padding: 8px 12px; border-radius: 10px; font-size: 14px; line-height: 1.4; box-shadow: 0 1px 2px rgba(21,22,42,.06); animation: fadeUp .2s ease both; }
.msg-in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 2px; }
.msg-out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 2px; }
.msg-meta { font-size: 10px; color: var(--muted); margin-top: 4px; text-align: right; }
.media-dl { color: var(--indigo); font-weight: 600; text-decoration: none; margin-left: 4px; }
.media-dl:hover { text-decoration: underline; }
.thread-reply { display: flex; gap: 8px; padding: 12px; background: var(--panel); border-top: 1px solid var(--border); }
.thread-reply textarea { flex: 1; resize: none; height: 42px; padding: 10px; border-radius: 9px; border: 1px solid var(--border); font-family: inherit; font-size: 14px; transition: border-color .15s, box-shadow .15s; }
.thread-reply textarea:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px var(--accent-soft); }
.thread-reply button { padding: 0 20px; background: var(--brand-gradient); color: #fff; border: none; border-radius: 9px; cursor: pointer; font-size: 14px; font-weight: 600; transition: transform .12s, box-shadow .12s; }
.thread-reply button:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(79,70,229,.28); }

.lead-panel { background: var(--panel); border-left: 1px solid var(--border); padding: 16px; overflow-y: auto; }
.lead-panel h3 { margin-top: 0; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.lead-panel label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.lead-panel input, .lead-panel select, .lead-panel textarea { width: 100%; margin-top: 4px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit; transition: border-color .15s, box-shadow .15s; }
.lead-panel input:focus, .lead-panel select:focus, .lead-panel textarea:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px var(--accent-soft); }
.lead-panel textarea { height: 80px; resize: vertical; }
.lead-panel button { width: 100%; padding: 9px; background: var(--brand-gradient); color: #fff; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; transition: transform .12s, box-shadow .12s; }
.lead-panel button:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(79,70,229,.28); }
.saved-msg { font-size: 12px; color: #0a7a3d; margin-top: 8px; height: 14px; }
.click-id { font-size: 10.5px; color: var(--muted); background: var(--bg); border-radius: 7px; padding: 6px 8px; margin-top: 14px; word-break: break-all; border: 1px dashed var(--border); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .lead-panel, .conv-list { display: none; }
}
