/* =========================================================================
   Amenify Pro — App chrome CSS
   Inherits design tokens from providers.html / index.html.
   ========================================================================= */

:root {
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --brand-light: #dbeafe;
    --midnight: #0f172a;
    --slate-900: #0f172a;
    --slate-800: #1e293b;
    --slate-700: #334155;
    --slate-600: #475569;
    --slate-500: #64748b;
    --slate-400: #94a3b8;
    --slate-300: #cbd5e1;
    --slate-200: #e2e8f0;
    --slate-100: #f1f5f9;
    --slate-50:  #f8fafc;
    --action-green: #22c55e;
    --action-green-dark: #16a34a;
    --accent-purple: #7c3aed;
    --accent-purple-dark: #6d28d9;
    --warning: #f97316;
    --danger: #dc2626;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --border-soft: #eef2f7;
    --shadow-sm: 0 1px 2px rgba(15,23,42,0.05);
    --shadow:    0 1px 3px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
    --shadow-lg: 0 12px 28px -8px rgba(15,23,42,0.18), 0 2px 6px rgba(15,23,42,0.06);
    --sidebar-w: 252px;
    --topbar-h: 64px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--midnight);
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Inter', sans-serif;
    font-feature-settings: "cv02","cv03","cv04","cv11";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
    font-size: inherit;
}

input, textarea, select {
    font-family: inherit;
    font-size: 14px;
    color: var(--midnight);
}

/* ---------- App shell layout ---------- */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--midnight);
    color: #fff;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    overflow-y: auto;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px 20px;
    color: #fff;
    font-weight: 800;
    font-size: 18px;
    letter-spacing: -0.01em;
}

.sidebar-logo-dot {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    /* The "A" badge used to be a gradient tile; now it's the Atlas
       mark. We use a background-image so legacy markup like
       `<span class="sidebar-logo-dot">A</span>` still works — the letter
       simply gets overlaid with the image and hidden via text-indent. */
    background: #e9d0d2 url("atlas-icon.svg") center / 72% 72% no-repeat;
    text-indent: -9999px;       /* hide any inner text fallback */
    overflow: hidden;
    display: grid;
    place-items: center;
    box-shadow: 0 4px 12px rgba(15,23,42,0.18);
}

.sidebar-business {
    padding: 10px 12px;
    margin: 0 0 16px;
    border-radius: 10px;
    background: rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid rgba(255,255,255,0.08);
}

.sidebar-business img {
    width: 36px; height: 36px;
    border-radius: 50%;
    object-fit: cover;
    background: #334155;
}

.sidebar-business-meta {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-business-meta strong { font-size: 13px; color: #fff; }
.sidebar-business-meta span { font-size: 11px; color: #94a3b8; }

.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--action-green);
    box-shadow: 0 0 0 3px rgba(34,197,94,0.25);
    display: inline-block;
    margin-right: 5px;
    vertical-align: middle;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #64748b;
    padding: 16px 12px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    color: #cbd5e1;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    transition: all 0.15s;
    cursor: pointer;
    margin-bottom: 2px;
    position: relative;
}

.nav-item:hover {
    background: rgba(255,255,255,0.07);
    color: #fff;
    text-decoration: none;
}

.nav-item.active {
    background: rgba(37,99,235,0.22);
    color: #fff;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 25%;
    bottom: 25%;
    width: 3px;
    border-radius: 2px;
    background: var(--brand);
}

.nav-item .nav-icon {
    width: 18px;
    height: 18px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    color: inherit;
}

.nav-item .nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 8px;
    line-height: 1;
}

.nav-item .nav-badge.green { background: var(--action-green); }
.nav-item .nav-badge.blue { background: var(--brand); }

.nav-item .nav-external-icon {
    margin-left: auto;
    font-size: 11px;
    opacity: 0.5;
    font-weight: 700;
    transition: opacity 0.15s, transform 0.15s;
}
.nav-item-external:hover .nav-external-icon {
    opacity: 1;
    transform: translate(1px, -1px);
}

.sidebar-foot {
    margin-top: auto;
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 12px;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ---------- Topbar ---------- */
.main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-bottom: 1px solid var(--border);
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
}

.topbar-title {
    font-weight: 800;
    font-size: 18px;
    letter-spacing: -0.01em;
    color: var(--midnight);
}

.topbar-search {
    flex: 1;
    max-width: 440px;
    margin-left: 24px;
    position: relative;
}

.topbar-search input {
    width: 100%;
    padding: 9px 14px 9px 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--slate-50);
    font-size: 14px;
}
.topbar-search input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
    background: #fff;
}

.topbar-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--slate-400);
    pointer-events: none;
}

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    width: 36px; height: 36px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    color: var(--slate-600);
    background: transparent;
    border: 1px solid transparent;
    transition: all 0.15s;
    position: relative;
}
.icon-btn:hover { background: var(--slate-100); color: var(--midnight); }

.icon-btn .badge {
    position: absolute;
    top: 5px; right: 5px;
    width: 8px; height: 8px;
    background: var(--danger);
    border-radius: 50%;
    border: 2px solid #fff;
}

.topbar-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 4px 4px;
    border-radius: 20px;
    background: var(--slate-100);
    border: 1px solid transparent;
    cursor: pointer;
}
.topbar-profile:hover { border-color: var(--border); }

.topbar-profile img {
    width: 28px; height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.topbar-profile span {
    font-size: 13px;
    font-weight: 600;
    color: var(--midnight);
}

/* ---------- Page container ---------- */
.page {
    padding: 28px 32px 56px;
    max-width: 1600px;
    width: 100%;
}

.page-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.page-title {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--midnight);
    margin: 0 0 4px;
}

.page-subtitle {
    font-size: 14px;
    color: var(--slate-500);
    margin: 0;
}

.page-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ---------- Buttons (match index/providers) ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid transparent;
    white-space: nowrap;
}

.btn-primary {
    background: var(--brand);
    color: #fff;
}
.btn-primary:hover { background: var(--brand-dark); text-decoration: none; }

.btn-green {
    background: var(--action-green);
    color: #fff;
}
.btn-green:hover { background: var(--action-green-dark); text-decoration: none; }

.btn-secondary {
    background: #fff;
    color: var(--midnight);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--slate-50); text-decoration: none; }

.btn-ghost {
    background: transparent;
    color: var(--slate-600);
}
.btn-ghost:hover { background: var(--slate-100); color: var(--midnight); text-decoration: none; }

.btn-danger {
    background: #fff;
    color: var(--danger);
    border-color: #fecaca;
}
.btn-danger:hover { background: #fef2f2; text-decoration: none; }

.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.card-flat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.card h3, .card-flat h3 {
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

/* ---------- KPI Card ---------- */
.kpi {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.kpi-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--midnight);
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.kpi-trend {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    font-size: 12px;
    font-weight: 600;
}
.kpi-trend.up { color: var(--action-green-dark); }
.kpi-trend.down { color: var(--danger); }
.kpi-trend.flat { color: var(--slate-500); }

.kpi-sparkline {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.6;
}

/* ---------- Badges / pills ---------- */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.4;
    white-space: nowrap;
}

.pill-blue   { background: #dbeafe; color: var(--brand-dark); }
.pill-green  { background: #dcfce7; color: var(--action-green-dark); }
.pill-purple { background: #ede9fe; color: var(--accent-purple-dark); }
.pill-orange { background: #ffedd5; color: #c2410c; }
.pill-red    { background: #fee2e2; color: var(--danger); }
.pill-gray   { background: var(--slate-100); color: var(--slate-600); }
.pill-yellow { background: #fef3c7; color: #a16207; }

/* ---------- Tables ---------- */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table thead th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    color: var(--slate-500);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}

.table tbody td {
    padding: 14px;
    border-bottom: 1px solid var(--border-soft);
    color: var(--midnight);
    vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--slate-50); }
.table tbody tr.clickable { cursor: pointer; }

.table .nowrap { white-space: nowrap; }
.table .muted  { color: var(--slate-500); }
.nowrap        { white-space: nowrap; }
.text-green    { color: var(--action-green); }
.text-danger   { color: var(--danger); }
.text-brand    { color: var(--brand); }

/* ---------- Avatar ---------- */
.avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: inline-grid;
    place-items: center;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    object-fit: cover;
    flex-shrink: 0;
    overflow: hidden;
}

.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 48px; height: 48px; font-size: 16px; }
.avatar.xl { width: 64px; height: 64px; font-size: 20px; }

.avatar img {
    width: 100%; height: 100%;
    object-fit: cover;
}

/* ---------- Chat UI ---------- */
.chat-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    min-height: calc(100vh - var(--topbar-h) - 90px);
    overflow: hidden;
}

.chat-list {
    border-right: 1px solid var(--border);
    overflow-y: auto;
    max-height: 100%;
}

.chat-list-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-list-item {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-soft);
    cursor: pointer;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    transition: background 0.15s;
}

.chat-list-item:hover { background: var(--slate-50); }
.chat-list-item.active { background: #eff6ff; border-left: 3px solid var(--brand); padding-left: 13px; }
.chat-list-item .chat-meta {
    flex: 1;
    min-width: 0;
}
.chat-list-item .chat-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--midnight);
    display: flex;
    align-items: center;
    gap: 6px;
}
.chat-list-item .chat-time {
    font-size: 11px;
    color: var(--slate-400);
    margin-left: auto;
    white-space: nowrap;
}
.chat-list-item .chat-preview {
    font-size: 12px;
    color: var(--slate-500);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 210px;
    margin-top: 2px;
}

.chat-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-pane-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: linear-gradient(180deg, #fafbff 0%, #f3f6fc 100%);
}

.chat-message {
    display: flex;
    margin-bottom: 14px;
    gap: 8px;
    max-width: 70%;
}

.chat-message.from-customer {
    justify-content: flex-start;
    align-self: flex-start;
    margin-right: auto;
}

.chat-message.from-maddie, .chat-message.from-pro {
    justify-content: flex-end;
    align-self: flex-end;
    margin-left: auto;
    flex-direction: row-reverse;
}

.chat-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: var(--shadow-sm);
}

.chat-message.from-customer .chat-bubble {
    background: #fff;
    border: 1px solid var(--border);
    color: var(--midnight);
    border-bottom-left-radius: 4px;
}

.chat-message.from-maddie .chat-bubble {
    background: linear-gradient(135deg, var(--accent-purple), var(--brand));
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.from-pro .chat-bubble {
    background: var(--midnight);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.system {
    justify-content: center;
    max-width: 100%;
}

.chat-message.system .chat-bubble {
    background: #fef3c7;
    color: #a16207;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 14px;
}

.chat-message .chat-meta-small {
    font-size: 11px;
    color: var(--slate-400);
    margin-top: 4px;
}

.chat-input {
    border-top: 1px solid var(--border);
    padding: 14px 16px;
    background: #fff;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input textarea {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    resize: none;
    min-height: 40px;
    max-height: 120px;
    font-size: 14px;
}
.chat-input textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* ---------- Grid helpers ---------- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }

.row { display: flex; gap: 12px; align-items: center; }
.row-end { justify-content: flex-end; }
.row-gap-8 { gap: 8px; }
.row-gap-16 { gap: 16px; }

.flex-col { display: flex; flex-direction: column; gap: 12px; }

.muted { color: var(--slate-500); }
.tiny { font-size: 11px; }
.small { font-size: 12px; }
.bold { font-weight: 700; }
.semibold { font-weight: 600; }
.center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

/* ---------- Toast ---------- */
#toast-root {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--midnight);
    color: #fff;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
    animation: toast-in 0.25s ease-out;
    min-width: 240px;
    max-width: 380px;
}

.toast.success { background: var(--action-green-dark); }
.toast.error   { background: var(--danger); }
.toast.info    { background: var(--brand-dark); }

@keyframes toast-in {
    from { transform: translateY(10px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* ---------- Modal & Drawer ---------- */
#modal-root, #drawer-root {
    position: fixed;
    inset: 0;
    z-index: 100;
    pointer-events: none;
}
#modal-root.open, #drawer-root.open { pointer-events: auto; }

.modal-backdrop, .drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15,23,42,0.45);
    opacity: 0;
    transition: opacity 0.2s;
}
#modal-root.open .modal-backdrop,
#drawer-root.open .drawer-backdrop { opacity: 1; }

.modal {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -48%);
    background: #fff;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 28px;
    width: min(560px, 92vw);
    max-height: 85vh;
    overflow-y: auto;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
}
#modal-root.open .modal {
    opacity: 1;
    transform: translate(-50%, -50%);
}

.modal h3 {
    margin: 0 0 6px;
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.modal p.subtitle {
    margin: 0 0 20px;
    color: var(--slate-500);
    font-size: 14px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.drawer {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: min(520px, 92vw);
    background: #fff;
    box-shadow: -20px 0 40px rgba(15,23,42,0.12);
    transform: translateX(100%);
    transition: transform 0.25s ease-out;
    overflow-y: auto;
    padding: 24px;
}
#drawer-root.open .drawer { transform: translateX(0); }

.drawer-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px; height: 32px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: var(--slate-500);
}
.drawer-close:hover { background: var(--slate-100); color: var(--midnight); }

/* ---------- Form controls ---------- */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.field label {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-600);
}

/* Match every input inside .field regardless of whether `type` is set.
   `input[type=text]` only matches when the attribute is literally present,
   so bareword <input> (which defaults to text) was falling back to the
   browser's native dark/thick border. This selector covers all of them. */
.field input,
.field select,
.field textarea {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    background: #fff;
    color: var(--midnight);
    font-family: inherit;
    line-height: 1.4;
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}

/* Checkboxes and radios shouldn't inherit the text-field styling. */
.field input[type=checkbox],
.field input[type=radio] {
    border: initial;
    border-radius: initial;
    padding: initial;
    width: auto;
    box-shadow: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.field input::placeholder,
.field textarea::placeholder {
    color: var(--slate-400);
}

.field-hint {
    font-size: 12px;
    color: var(--slate-500);
}

/* ---------- Toggle ---------- */
.toggle {
    position: relative;
    width: 38px;
    height: 22px;
    background: var(--slate-300);
    border-radius: 11px;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}
.toggle::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 18px; height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle.on { background: var(--action-green); }
.toggle.on::after { transform: translateX(16px); }

/* ---------- Tabs ---------- */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    color: var(--slate-500);
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.15s;
}
.tab:hover { color: var(--midnight); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- Empty states ---------- */
.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--slate-500);
}

.empty-icon {
    width: 64px; height: 64px;
    border-radius: 14px;
    background: var(--slate-100);
    display: inline-grid;
    place-items: center;
    color: var(--slate-400);
    margin-bottom: 16px;
}

.empty h4 {
    font-size: 16px;
    font-weight: 700;
    color: var(--midnight);
    margin: 0 0 4px;
}

/* ---------- Skeleton ---------- */
.skel {
    background: linear-gradient(90deg, var(--slate-100) 25%, var(--slate-200) 50%, var(--slate-100) 75%);
    background-size: 200% 100%;
    animation: skel 1.4s infinite;
    border-radius: 6px;
}
@keyframes skel {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ---------- Progress / charts ---------- */
.bar {
    height: 10px;
    background: var(--slate-100);
    border-radius: 99px;
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    background: var(--brand);
    border-radius: 99px;
    transition: width 0.3s;
}
.bar-fill.green { background: var(--action-green); }
.bar-fill.purple { background: var(--accent-purple); }

/* ---------- Status dots in tables ---------- */
.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
}
.status::before {
    content: '';
    width: 7px; height: 7px;
    border-radius: 50%;
}
.status.completed::before { background: var(--action-green); }
.status.in_progress::before, .status.live::before { background: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,0.2); }
.status.booked::before { background: var(--accent-purple); }
.status.quoted::before { background: var(--warning); }
.status.requested::before { background: var(--slate-400); }
.status.cancelled::before { background: var(--danger); }

/* ---------- Live dot ---------- */
.live-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--action-green);
    margin-right: 6px;
    animation: live-pulse 2s infinite;
    position: relative;
}
@keyframes live-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.6); }
    50%      { box-shadow: 0 0 0 6px rgba(34,197,94,0);  }
}

/* ---------- Responsive ---------- */

/* Wrap any .table in .table-wrap to enable horizontal scroll on narrow screens
   without breaking the desktop layout. Applied in app.js. */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding: 0 4px;
}
.table-wrap .table { min-width: 520px; }

/* Mobile-menu button: hidden on desktop, shown on mobile via media query below. */
.icon-btn#mobile-menu-btn { display: none; }

/* Sidebar backdrop overlay used only when sidebar is open on mobile. */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.45);
    z-index: 39;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
}

/* ===== LAPTOP (< 1200px) — tighten spacing ===== */
@media (max-width: 1199px) {
    :root { --sidebar-w: 220px; }
    .page { padding: 24px 24px 48px; }
    .grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ===== SMALL LAPTOP / TABLET (< 1024px) — icon-only sidebar ===== */
@media (max-width: 1023px) {
    :root { --sidebar-w: 72px; }
    .sidebar-logo span:not(.sidebar-logo-dot),
    .sidebar-business-meta,
    .nav-item > span:not(.nav-badge):not(.nav-external-icon),
    .nav-section-label,
    .sidebar-foot { display: none; }
    .sidebar { padding: 12px 8px; }
    .sidebar-business { padding: 6px; justify-content: center; }
    .nav-item { justify-content: center; padding: 10px; }
    .nav-item .nav-external-icon { display: none; }
    .page { padding: 20px 20px 40px; }
    .grid-4 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .chat-layout { grid-template-columns: 280px 1fr; }
}

/* ===== TABLET (< 900px) — stack grids more aggressively ===== */
@media (max-width: 899px) {
    .grid-3, .grid-4, .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .topbar-search { max-width: 260px; }
}

/* ===== MOBILE (< 768px) — sidebar becomes slide-over, stack everything ===== */
@media (max-width: 767px) {
    .app { grid-template-columns: 1fr; }

    /* Sidebar slides in from the left as an overlay */
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        height: 100vh;
        width: 260px;
        padding: 16px 12px;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform 0.25s ease-out;
        display: flex !important;
        flex-direction: column !important;
    }
    body.sidebar-open .sidebar { transform: translateX(0); }

    /* Re-enable full sidebar content on mobile (the tablet rule hid it) */
    .sidebar-logo span:not(.sidebar-logo-dot),
    .sidebar-business-meta,
    .nav-item > span:not(.nav-badge):not(.nav-external-icon),
    .nav-section-label,
    .sidebar-foot { display: initial; }
    .sidebar-business-meta { display: flex; flex-direction: column; }
    .sidebar-business { padding: 10px 12px; justify-content: flex-start; }
    .nav-item { justify-content: flex-start; padding: 10px 14px; }
    .nav-item .nav-external-icon { display: inline; }

    /* Hamburger shown, content full width */
    .icon-btn#mobile-menu-btn { display: grid !important; }
    .topbar { padding: 0 14px; gap: 8px; }
    .topbar-title { font-size: 16px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .topbar-search { display: none; } /* Cmd+K shortcut still works */
    .topbar-profile span { display: none; }
    .topbar-profile { padding: 4px; }

    /* Content: single column everywhere */
    .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
    .grid { gap: 12px; }

    .page { padding: 16px 14px 40px; max-width: 100%; }
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-bottom: 16px;
    }
    .page-title { font-size: 22px; }
    .page-actions { flex-wrap: wrap; }
    .page-actions .btn { flex: 1 1 auto; justify-content: center; min-width: 0; }

    /* Cards: tighter padding, but still breathable */
    .card, .card-flat { padding: 16px; border-radius: 12px; }
    .kpi { padding: 14px; }
    .kpi-value { font-size: 22px; }
    .kpi-label { font-size: 11px; }

    /* Tables: every .table becomes scrollable horizontally if wrapped */
    .table { font-size: 13px; }
    .table thead th, .table tbody td { padding: 10px 8px; }

    /* Chat pane: stack vertically, list above pane */
    .chat-layout {
        grid-template-columns: 1fr;
        min-height: calc(100vh - var(--topbar-h) - 70px);
    }
    .chat-list {
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .chat-list-item .chat-preview { max-width: 60vw; }
    .chat-message { max-width: 86%; }
    .chat-messages { padding: 14px; }

    /* Modals: full-width bottom sheet on tiny screens */
    .modal {
        width: 100vw;
        max-width: 100vw;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        transform: translateY(100%);
        border-radius: 18px 18px 0 0;
        max-height: 88vh;
        padding: 22px 18px;
    }
    #modal-root.open .modal {
        transform: translateY(0);
    }
    .modal h3 { font-size: 18px; }
    .modal-actions {
        flex-direction: column-reverse;
        gap: 8px;
    }
    .modal-actions .btn { width: 100%; justify-content: center; }

    /* Drawer: slide up from the bottom instead of in from the right */
    .drawer {
        left: 0;
        right: 0;
        width: 100%;
        height: 85vh;
        top: auto;
        bottom: 0;
        transform: translateY(100%);
        border-radius: 18px 18px 0 0;
        padding: 22px 18px;
    }
    #drawer-root.open .drawer { transform: translateY(0); }

    /* Forms: full width inputs */
    .field input, .field textarea, .field select { font-size: 16px; } /* prevents iOS zoom */

    /* Toasts: slide up from bottom, respect safe area */
    #toast-root {
        bottom: calc(16px + env(safe-area-inset-bottom));
        left: 12px;
        right: 12px;
        align-items: stretch;
    }
    .toast { min-width: 0; max-width: none; }

    /* Buttons: slightly beefier touch targets */
    .btn { padding: 11px 16px; min-height: 40px; }
    .btn-sm { padding: 8px 12px; min-height: 32px; }

    /* Tap targets for icon buttons */
    .icon-btn { width: 40px; height: 40px; }
}

/* ===== SMALL MOBILE (< 420px) — last-mile polish ===== */
@media (max-width: 419px) {
    .page-title { font-size: 20px; }
    .page-subtitle { font-size: 13px; }
    .kpi-value { font-size: 20px; }
    .maddie-orb { width: 40px !important; height: 40px !important; font-size: 14px !important; }
    .topbar-title { max-width: 100px; }
}

/* Print: strip chrome so the dashboard prints cleanly */
@media print {
    .sidebar, .topbar, .icon-btn, .btn, #toast-root, .maddie-orb { display: none !important; }
    .app { grid-template-columns: 1fr; }
    .page { padding: 0; max-width: 100%; }
    .card, .kpi { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
}

/* ---------- Utility: scrollbar styling ---------- */
.scroll-y { overflow-y: auto; }
.scroll-y::-webkit-scrollbar { width: 8px; }
.scroll-y::-webkit-scrollbar-thumb { background: var(--slate-300); border-radius: 4px; }
.scroll-y::-webkit-scrollbar-thumb:hover { background: var(--slate-400); }

/* ---------- Printable receipt / invoice box ---------- */
.surface-gradient {
    background: linear-gradient(135deg, rgba(37,99,235,0.06), rgba(124,58,237,0.06));
}

/* ---------- AI Receptionist "brain" pulse ---------- */
.maddie-orb {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-purple), var(--brand));
    position: relative;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 800;
    font-size: 13px;
    letter-spacing: 0.02em;
}
.maddie-orb::after {
    content: '';
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    border: 2px solid rgba(124,58,237,0.3);
    animation: maddie-pulse 2.5s infinite;
}
@keyframes maddie-pulse {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.25); opacity: 0; }
}

/* ---------- Animated typing indicator ---------- */
.typing {
    display: inline-flex;
    gap: 3px;
    align-items: center;
}
.typing span {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--slate-400);
    animation: typing 1.4s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Sparkline + bar chart ---------- */
.spark-svg { display: block; }
.chart-wrap { position: relative; width: 100%; height: 200px; }

/* ---------- Inline spinner (used in buttons during async ops) ---------- */
.spinner {
    display: inline-block;
    width: 12px; height: 12px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: -2px;
    margin-right: 6px;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Linear progress bar used underneath buttons during long ops */
.progress-bar {
    position: relative;
    height: 3px;
    border-radius: 2px;
    background: rgba(0,0,0,0.08);
    overflow: hidden;
    margin-top: 10px;
}
.progress-bar::before {
    content: '';
    position: absolute;
    left: -40%;
    top: 0;
    width: 40%;
    height: 100%;
    background: var(--brand, #2563eb);
    border-radius: 2px;
    animation: progress-slide 1.2s ease-in-out infinite;
}
@keyframes progress-slide {
    0%   { left: -40%; }
    100% { left: 100%; }
}
