:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #111827;
  background: #f5f6f8;
  font-synthesis: none;
  --ink: #111827;
  --ink-soft: #344054;
  --muted: #667085;
  --line: #e4e7ec;
  --surface: #ffffff;
  --canvas: #f5f6f8;
  --accent: #175cd3;
  --accent-soft: #eff4ff;
  --green: #067647;
  --green-soft: #ecfdf3;
  --red: #b42318;
  --red-soft: #fef3f2;
  --amber: #b54708;
  --amber-soft: #fffaeb;
  --shadow: 0 8px 24px rgba(16, 24, 40, .055);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--canvas); color: var(--ink); }
body.drawer-open { overflow: hidden; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .6; }
input, textarea { color: var(--ink); }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(23, 92, 211, .2); outline-offset: 2px; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #f2f4f7; }
.login-card { width: min(420px, 100%); padding: 36px; border: 1px solid var(--line); border-radius: 18px; background: #fff; box-shadow: 0 24px 60px rgba(16, 24, 40, .1); }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 13px; background: #175cd3; color: #fff; font-size: 21px; font-weight: 800; }
.brand-mark.small { width: 36px; height: 36px; border-radius: 10px; flex: 0 0 auto; font-size: 16px; }
.login-card h1 { margin: 22px 0 0; font-size: 28px; letter-spacing: -.035em; }
.login-copy { margin: 7px 0 0; color: var(--muted); font-size: 14px; }
.login-form { display: grid; gap: 16px; margin-top: 28px; }
label { display: grid; gap: 7px; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
input, textarea { width: 100%; border: 1px solid #d0d5dd; border-radius: 9px; padding: 11px 12px; background: #fff; outline: none; transition: border-color .16s, box-shadow .16s; }
input:focus, textarea:focus { border-color: #528bdf; box-shadow: 0 0 0 3px rgba(23, 92, 211, .1); }
textarea { resize: vertical; line-height: 1.5; }
.form-message { min-height: 18px; margin: 0; color: var(--red); font-size: 12px; font-weight: 700; }

.primary, .secondary, .ghost, .table-action, .icon-button { border: 0; border-radius: 9px; font-weight: 750; transition: background .16s, color .16s, transform .16s, box-shadow .16s; }
.primary { padding: 10px 15px; background: #175cd3; color: #fff; box-shadow: 0 1px 2px rgba(16, 24, 40, .1); }
.primary:hover { background: #134ba9; }
.secondary { padding: 9px 13px; border: 1px solid #d0d5dd; background: #fff; color: var(--ink-soft); box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }
.secondary:hover { background: #f9fafb; }
.ghost { padding: 9px 11px; background: transparent; color: var(--ink-soft); }
.ghost:hover { background: #f2f4f7; color: var(--ink); }
.compact { padding: 7px 9px; }
.wide { width: 100%; }
.refresh-button { display: inline-flex; align-items: center; gap: 7px; }
.refresh-button span { font-size: 17px; line-height: 1; }

.app-shell { min-height: 100vh; }
.topbar { height: 68px; padding: 0 max(24px, calc((100vw - 1480px) / 2)); display: flex; align-items: center; gap: 32px; position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .97); backdrop-filter: blur(12px); }
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: transparent; }
.brand { min-width: 146px; display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; line-height: 1.1; }
.brand small { margin-top: 3px; color: var(--muted); font-size: 10px; font-weight: 650; letter-spacing: .04em; }
.main-nav { align-self: stretch; display: flex; gap: 4px; }
.nav-item { position: relative; border: 0; padding: 0 14px; background: transparent; color: #475467; font-size: 13px; font-weight: 750; }
.nav-item:hover { color: var(--ink); }
.nav-item.active { color: #1849a9; }
.nav-item.active::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: 0; height: 2px; border-radius: 2px 2px 0 0; background: var(--accent); }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: 9px; }
.username { color: #475467; font-size: 12px; font-weight: 700; }
.live-pill { display: inline-flex; align-items: center; gap: 7px; padding: 6px 9px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 10px; font-weight: 800; }
.live-pill i { width: 7px; height: 7px; border-radius: 50%; background: #17b26a; box-shadow: 0 0 0 3px rgba(23, 178, 106, .12); }
.live-pill.offline { background: var(--red-soft); color: var(--red); }
.live-pill.offline i { display: none; }
.live-pill.loading { opacity: .65; }

.content { width: min(100%, 1480px); margin: 0 auto; padding: 28px 28px 56px; }
.page-heading { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 22px; margin-bottom: 20px; }
.page-heading h1 { margin: 0; color: var(--ink); font-size: 27px; line-height: 1.2; letter-spacing: -.035em; }
.page-context { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.eyebrow, .panel-heading p { margin: 0; color: #667085; font-size: 9px; font-weight: 800; letter-spacing: .09em; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.stat-card { min-height: 92px; display: flex; align-items: center; gap: 14px; padding: 17px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: 0 2px 8px rgba(16, 24, 40, .03); }
.stat-icon { width: 40px; height: 40px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 11px; background: var(--accent-soft); color: #1849a9; font-size: 18px; font-weight: 800; }
.stat-icon.answered { background: var(--green-soft); color: var(--green); }
.stat-icon.missed { background: var(--red-soft); color: var(--red); }
.stat-icon.contacts { background: #f4f3ff; color: #5925dc; font-size: 13px; }
.stat-card span { display: block; color: #475467; font-size: 11px; font-weight: 700; }
.stat-card strong { display: block; margin-top: 4px; color: var(--ink); font-size: 25px; line-height: 1; letter-spacing: -.04em; }

.dashboard-grid { display: grid; grid-template-columns: minmax(360px, 400px) minmax(0, 1fr); gap: 16px; align-items: start; }
.panel { overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.panel-heading { min-height: 65px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid #eaecf0; }
.panel-heading h2 { margin: 3px 0 0; color: var(--ink); font-size: 16px; line-height: 1.25; }
.device-pill, .count-pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 8px; background: #f2f4f7; color: #475467; font-size: 9px; font-weight: 800; white-space: nowrap; }
.empty-state { min-height: 300px; padding: 40px 24px; display: grid; align-content: center; justify-items: center; text-align: center; color: var(--muted); }
.empty-state strong { margin: 11px 0 0; color: var(--ink-soft); font-size: 13px; }
.empty-icon { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font-size: 21px; }
.active-call-slot { min-height: 300px; }
.active-card { min-height: 300px; padding: 20px; }
.call-status-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 10px; }
.caller-identity { display: flex; align-items: center; gap: 13px; margin: 22px 0 17px; }
.caller-identity h3 { margin: 0; color: var(--ink); font-size: 20px; line-height: 1.2; letter-spacing: -.025em; }
.caller-identity p { margin: 4px 0 0; color: #475467; font-size: 12px; font-weight: 650; }
.avatar { width: 36px; height: 36px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 10px; background: #eff4ff; color: #1849a9; font-size: 10px; font-weight: 850; }
.avatar.xl { width: 52px; height: 52px; border-radius: 14px; font-size: 15px; }
.call-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.call-facts div { min-width: 0; padding: 11px; border: 1px solid #f0f1f3; border-radius: 10px; background: #f9fafb; }
.call-facts span, .call-facts strong { display: block; }
.call-facts span { color: #667085; font-size: 8px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.call-facts strong { overflow: hidden; margin-top: 4px; color: var(--ink-soft); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

.status-badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 8px; background: #f2f4f7; color: #475467; font-size: 9px; font-weight: 800; white-space: nowrap; }
.status-badge.large { padding: 6px 9px; font-size: 10px; }
.status-badge.ringing { background: var(--amber-soft); color: var(--amber); }
.status-badge.answered { background: var(--green-soft); color: var(--green); }
.status-badge.missed { background: var(--red-soft); color: var(--red); }
.status-badge.ended { background: #eff4ff; color: #3538cd; }
.status-badge.incomplete { background: #f2f4f7; color: #475467; }

.table-wrap { position: relative; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 14px; background: #f9fafb; color: #667085; text-align: left; font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .065em; white-space: nowrap; }
td { padding: 12px 14px; border-top: 1px solid #eaecf0; color: var(--ink-soft); font-size: 11px; }
tbody tr { transition: background .16s, box-shadow .16s; }
tbody tr:hover { background: #f9fafb; }
.call-row.missed td:first-child { box-shadow: inset 2px 0 0 #f04438; }
.call-row.incomplete td:first-child { box-shadow: inset 2px 0 0 #98a2b3; }
.person-cell { min-width: 190px; display: flex; align-items: center; gap: 10px; }
.person-cell strong, .person-cell small { display: block; }
.person-cell strong { color: var(--ink); font-size: 11px; }
.person-cell small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.date-cell { color: #667085; white-space: nowrap; }
.action-column { text-align: right; }
.table-action { padding: 7px 9px; background: var(--accent-soft); color: #1849a9; font-size: 9px; white-space: nowrap; }
.table-action:hover { background: #dbe7ff; }
.table-empty { padding: 54px 20px; color: var(--muted); text-align: center; font-size: 11px; }

.contacts-panel { min-height: 430px; }
.toolbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 12px 16px; border-bottom: 1px solid #eaecf0; }
.search-box { width: min(430px, 100%); position: relative; display: block; }
.search-box span { position: absolute; left: 12px; top: 7px; color: #667085; font-size: 21px; font-weight: 400; }
.search-box input { padding-left: 38px; background: #f9fafb; }
.contacts-table { min-width: 830px; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 49; background: rgba(16, 24, 40, .38); backdrop-filter: blur(2px); }
.drawer { width: min(760px, 96vw); height: 100vh; display: flex; flex-direction: column; position: fixed; z-index: 50; top: 0; right: 0; background: #fff; box-shadow: -24px 0 70px rgba(16, 24, 40, .2); transform: translateX(105%); transition: transform .24s ease; }
.drawer.open { transform: translateX(0); }
.drawer-header { min-height: 72px; padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.drawer-header h2 { margin: 0; color: var(--ink); font-size: 19px; }
.icon-button { width: 36px; height: 36px; padding: 0; background: #f2f4f7; color: #475467; font-size: 23px; font-weight: 400; }
.icon-button:hover { background: #eaecf0; color: var(--ink); }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.contact-form { padding: 18px; border: 1px solid var(--line); border-radius: 13px; background: #fcfcfd; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin-top: 16px; }
.form-actions .form-message { margin-right: auto; }
.contact-history { margin-top: 16px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.detail-section { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 13px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-title h3 { margin: 0; color: var(--ink); font-size: 13px; }
.note-form { display: grid; justify-items: end; gap: 8px; margin-bottom: 12px; }
.note-form .secondary { padding: 8px 10px; font-size: 10px; }
.activity-list { display: grid; gap: 8px; }
.activity-item { padding: 10px; border: 1px solid #eaecf0; border-radius: 9px; background: #fff; }
.note-item p { margin: 0; color: var(--ink-soft); font-size: 11px; line-height: 1.55; white-space: pre-wrap; }
.note-item footer { margin-top: 7px; color: var(--muted); font-size: 9px; font-weight: 650; }
.event-item { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 9px; }
.event-item strong { color: var(--ink-soft); font-size: 10px; }
.event-item p { margin: 3px 0 0; color: var(--muted); font-size: 9px; }
.event-item > span:last-child { color: #475467; font-size: 9px; font-weight: 750; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #98a2b3; }
.status-dot.ringing { background: #f79009; }
.status-dot.answered { background: #12b76a; }
.status-dot.missed { background: #f04438; }
.status-dot.ended { background: #6172f3; }
.mini-empty { padding: 20px 8px; color: var(--muted); text-align: center; font-size: 10px; }

.toast { max-width: 380px; padding: 13px 16px; position: fixed; z-index: 70; right: 24px; bottom: 24px; border-radius: 10px; background: #344054; color: #fff; box-shadow: 0 14px 36px rgba(16, 24, 40, .24); font-size: 12px; font-weight: 750; animation: toast-in .24s ease-out both; }
.toast.error { background: #912018; }
.toast.call { padding-left: 42px; background: #075e45; }
.toast.call::before { content: "☎"; width: 24px; height: 24px; display: grid; place-items: center; position: absolute; left: 11px; top: 9px; border-radius: 50%; background: rgba(255,255,255,.16); animation: phone-ring .55s ease-in-out 3; }

.incoming-call .topbar::after { background: linear-gradient(90deg, transparent, #12b76a 35%, #12b76a 65%, transparent); animation: incoming-bar 1.1s ease-in-out 3; }
.active-card.is-new-call { animation: card-attention 1.1s ease-out 3; }
tr.is-new-call td { animation: row-attention 1.15s ease-out 3; }

@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes phone-ring { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }
@keyframes incoming-bar { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }
@keyframes card-attention { 0%, 100% { background: #fff; box-shadow: inset 0 0 0 0 rgba(18, 183, 106, 0); } 45% { background: #f3fff8; box-shadow: inset 0 0 0 2px rgba(18, 183, 106, .28); } }
@keyframes row-attention { 0%, 100% { background: transparent; } 45% { background: #ecfdf3; } }

@media (max-width: 1080px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .active-card, .active-call-slot, .empty-state { min-height: auto; }
}

@media (max-width: 760px) {
  .topbar { height: auto; min-height: 64px; padding: 9px 14px 0; gap: 10px; flex-wrap: wrap; }
  .brand { min-width: 0; }
  .brand > span:last-child, .username { display: none; }
  .user-menu { margin-left: auto; }
  .main-nav { width: 100%; height: 38px; order: 3; }
  .nav-item { flex: 1; }
  .content { padding: 22px 14px 42px; }
  .page-heading { align-items: flex-start; }
  .page-heading h1 { font-size: 24px; }
  .stat-grid { gap: 9px; }
  .stat-card { min-height: 82px; padding: 13px; gap: 10px; }
  .stat-icon { width: 34px; height: 34px; border-radius: 9px; font-size: 15px; }
  .stat-card strong { font-size: 22px; }
  .panel-heading { min-height: 60px; }
  .form-grid, .detail-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .form-actions .primary { width: 100%; }
  .drawer-body { padding: 13px; }
  .contact-form, .detail-section { padding: 13px; }
}

@media (max-width: 480px) {
  .login-card { padding: 28px 22px; }
  .page-heading { gap: 12px; }
  .page-heading .secondary, .page-heading .primary { padding: 9px 10px; font-size: 11px; }
  .stat-card { display: block; }
  .stat-icon { margin-bottom: 9px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .count-pill { align-self: flex-start; }
  .call-facts { grid-template-columns: 1fr; }
  .toast { left: 14px; right: 14px; bottom: 14px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
