/* MainelyCRM — shared admin theme. Per-pack accent comes from --accent. */
:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --ink: #1c2128;
    --ink-soft: #5b6470;
    --line: #e4e7ec;
    --side: #161b22;
    --side-ink: #aeb6c2;
    --side-ink-bright: #ffffff;
    --accent: #2f7dd1;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.5;
}

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.side {
    width: 234px;
    flex: none;
    background: var(--side);
    color: var(--side-ink);
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
}
.brand { display: flex; gap: 11px; align-items: center; padding: 6px 8px 20px; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 9px;
    background: var(--accent); color: #fff;
    display: grid; place-items: center;
    font-weight: 700; letter-spacing: .5px; font-size: 14px;
}
.brand-name { color: var(--side-ink-bright); font-weight: 650; font-size: 15px; }
.brand-pack { font-size: 11.5px; color: var(--side-ink); opacity: .8; }

nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.nav-link {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 11px; border-radius: 8px;
    color: var(--side-ink); text-decoration: none;
    font-weight: 500; transition: background .12s, color .12s;
}
.nav-link:hover { background: rgba(255, 255, 255, .06); color: var(--side-ink-bright); }
.nav-link.active { background: var(--accent); color: #fff; }
.nav-ico { width: 18px; height: 18px; flex: none; opacity: .9; }

.side-foot { margin-top: auto; padding: 14px 10px 2px; font-size: 11px; opacity: .55; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: 60px; flex: none;
    background: var(--panel); border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 26px;
}
.client-id { display: flex; align-items: center; gap: 9px; font-size: 15px; }
.client-id .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.switcher { display: flex; align-items: center; gap: 9px; font-size: 12.5px; color: var(--ink-soft); }
.switcher select {
    font: inherit; padding: 7px 10px; border: 1px solid var(--line);
    border-radius: 8px; background: #fff; color: var(--ink); cursor: pointer;
}
.switcher select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.content { padding: 26px; max-width: 1180px; width: 100%; }

/* ---------- Headings ---------- */
.page-head { margin-bottom: 20px; }
.page-head.row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-head h1 { font-size: 22px; margin: 0; font-weight: 680; letter-spacing: -.2px; }
.page-head .sub { margin: 3px 0 0; color: var(--ink-soft); }
.back { color: var(--ink-soft); text-decoration: none; font-size: 12.5px; }
.back:hover { color: var(--accent); }

/* ---------- KPI tiles ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.kpi {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.kpi-val { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.kpi-label { color: var(--ink-soft); font-size: 12.5px; margin-top: 2px; }

/* ---------- Panels / lists ---------- */
.list-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.panel h2 { font-size: 14px; margin: 0 0 12px; font-weight: 650; }

/* ---------- Tables ---------- */
table.data { width: 100%; border-collapse: collapse; }
table.data.card {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
table.data th {
    text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--ink-soft); font-weight: 600; padding: 10px 14px;
    border-bottom: 1px solid var(--line);
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--line); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover { background: #f8fafc; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600; line-height: 1.6;
    background: #eef1f5; color: #44505f;
}
.badge-won, .badge-paid, .badge-active, .badge-complete, .badge-completed,
.badge-accepted, .badge-confirmed { background: #e3f5ea; color: #1c7a48; }
.badge-lost, .badge-overdue, .badge-cancelled, .badge-declined,
.badge-expired, .badge-inactive { background: #fbe6e6; color: #b3392f; }
.badge-new, .badge-scheduled, .badge-draft, .badge-sent, .badge-pending,
.badge-pending-deposit, .badge-outstanding { background: #e6effb; color: #1f5fa8; }
.badge-emergency, .badge-en-route, .badge-on-site { background: #fdeede; color: #b5651d; }

/* ---------- Search ---------- */
.search input {
    font: inherit; padding: 9px 13px; width: 260px;
    border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- Detail ---------- */
.detail.card {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.detail-row { display: grid; grid-template-columns: 200px 1fr; border-bottom: 1px solid var(--line); }
.detail-row:last-child { border-bottom: none; }
.detail-key { padding: 11px 16px; color: var(--ink-soft); background: #fafbfc; font-weight: 500; }
.detail-val { padding: 11px 16px; }
.longtext { white-space: pre-wrap; }

/* ---------- Misc ---------- */
.empty {
    background: var(--panel); border: 1px dashed var(--line);
    border-radius: var(--radius); padding: 40px; text-align: center; color: var(--ink-soft);
}
.muted { color: #9aa4b0; }
.err { color: #b3392f; }

/* ---------- Mobile: hamburger + off-canvas sidebar ---------- */
.menu-btn { display: none; }
.nav-overlay { display: none; }

@media (max-width: 860px) {
    .menu-btn {
        display: inline-flex; align-items: center; justify-content: center;
        width: 40px; height: 40px; margin-right: 4px; flex: none;
        background: transparent; border: 1px solid var(--line);
        border-radius: 9px; color: var(--ink); cursor: pointer;
    }
    /* sidebar slides in over content */
    .side {
        position: fixed; top: 0; left: 0; bottom: 0; width: 252px; z-index: 60;
        transform: translateX(-100%); transition: transform .22s ease; overflow-y: auto;
    }
    body.nav-open .side { transform: translateX(0); box-shadow: 0 0 48px rgba(0,0,0,.45); }
    /* drawer shows full labels (undo any desktop collapse) */
    .brand > div, .brand-pack, .side-foot { display: block; }
    .nav-link span { display: inline; }

    .nav-overlay {
        display: block; position: fixed; inset: 0; z-index: 55;
        background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .2s;
    }
    body.nav-open .nav-overlay { opacity: 1; pointer-events: auto; }

    .main { width: 100%; min-width: 0; }
    .topbar { padding: 0 14px; gap: 8px; }
    .content { padding: 16px; }

    /* keep the top bar from overflowing on narrow screens */
    .client-id { font-size: 14px; min-width: 0; overflow: hidden; }
    .client-id strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .topbar-right { gap: 10px; }
    .switcher span { display: none; }
    .switcher select { max-width: 150px; }
    .user-chip { display: none; }

    /* wide data tables scroll inside their card instead of breaking the page */
    table.data, table.data.card { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }

    /* stack two-column layouts */
    .kpi-row { grid-template-columns: repeat(2, 1fr); }
    .list-grid, .rgrid-2, .rgrid-3 { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .detail-row { grid-template-columns: 1fr; }
    .page-head.row { flex-direction: column; align-items: stretch; gap: 12px; }
    .head-tools { flex-wrap: wrap; }
    .login-card { width: min(360px, 92vw); }
}

@media (max-width: 480px) {
    .kpi-row { grid-template-columns: 1fr 1fr; }
    .page-head h1 { font-size: 20px; }
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-block; padding: 8px 15px; border-radius: 8px;
    border: 1px solid var(--line); background: #fff; color: var(--ink);
    font: inherit; font-weight: 550; cursor: pointer; text-decoration: none;
    line-height: 1.2; transition: filter .12s, background .12s;
}
.btn:hover { background: #f5f7fa; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-danger { color: #b3392f; border-color: #f0c8c4; }
.btn-danger:hover { background: #fbe6e6; }

.head-tools { display: flex; align-items: center; gap: 10px; }
.topbar-right { display: flex; align-items: center; gap: 18px; }
.logout { color: var(--ink-soft); text-decoration: none; font-size: 12.5px; }
.logout:hover { color: var(--accent); }

/* ---------- Forms ---------- */
.entity-form.card {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 22px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-wide { grid-column: 1 / -1; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.field input[type=text], .field input[type=number], .field input[type=date],
.field input[type=datetime-local], .field input[type=password], .field select, .field textarea {
    font: inherit; padding: 9px 11px; border: 1px solid var(--line);
    border-radius: 8px; background: #fff; color: var(--ink); width: 100%;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
    outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
.field .check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); font-size: 14px; }
.field .check input { width: auto; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; background: var(--side); }
.login-card {
    background: #fff; border-radius: 14px; padding: 34px 32px; width: 340px;
    display: flex; flex-direction: column; gap: 4px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-mark {
    width: 46px; height: 46px; border-radius: 11px; background: var(--accent); color: #fff;
    display: grid; place-items: center; font-weight: 700; margin-bottom: 8px;
}
.login-card h1 { margin: 0; font-size: 21px; }
.login-card .sub { margin: 0 0 16px; color: var(--ink-soft); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 12px; }
.login-card input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login-card button {
    font: inherit; font-weight: 600; padding: 11px; border: none; border-radius: 8px;
    background: var(--accent); color: #fff; cursor: pointer; margin-top: 4px;
}
.login-err { background: #fbe6e6; color: #b3392f; padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.login-hint { text-align: center; color: var(--ink-soft); font-size: 12px; margin: 14px 0 0; }

/* ---------- Flash ---------- */
.flash { padding: 11px 15px; border-radius: 9px; margin-bottom: 18px; font-weight: 500; }
.flash-ok { background: #e3f5ea; color: #1c7a48; border: 1px solid #bfe6cd; }
.flash-warn { background: #fdeede; color: #b5651d; border: 1px solid #f3d6b0; }
.flash-err { background: #fbe6e6; color: #b3392f; border: 1px solid #f0c8c4; }

/* ---------- Action mini-forms ---------- */
.action-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; max-width: 560px; }
.action-card h2 { margin: 0 0 16px; font-size: 17px; }

/* ---------- User chip / topbar extras (auth + RBAC) ---------- */
.user-chip { display: flex; flex-direction: column; line-height: 1.2; text-align: right; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--ink-soft); }
.topbar-btn { padding: 7px 13px; font-size: 13px; }
.topbar-right { gap: 16px; }
.inline-form { display: inline; margin: 0; }
.action-card code, .muted code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ============================================================
   RICH UI KIT  — structure only; packs reskin via theme.css
   ============================================================ */
.rgrid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; align-items: start; }
.rgrid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-items: start; }
.rstack { display: grid; gap: 18px; align-items: start; }

/* KPI cards (with delta + icon) */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 17px 19px; box-shadow: var(--shadow); }
.kpi-ic { position: absolute; top: 15px; right: 15px; color: var(--accent); opacity: .85; }
.kpi-ic svg { width: 20px; height: 20px; }
.kpi-lab { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.kpi-num { font-family: var(--display-font, inherit); font-size: 30px; font-weight: 700; letter-spacing: -.5px; margin-top: 4px; line-height: 1.1; }
.kpi-delta { font-size: 12px; margin-top: 5px; color: var(--ink-soft); }
.kpi-delta.up { color: #1c7a48; }
.kpi-delta.down { color: #b3392f; }

/* Rich panel */
.rpanel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.rpanel + .rpanel, .rstack > .rpanel { margin-top: 0; }
.panel-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-h h3 { margin: 0; font-size: 14px; font-weight: 650; font-family: var(--display-font, inherit); }
.panel-sub { font-weight: 400; color: var(--ink-soft); font-size: 12px; font-family: inherit; }
.panel-act { font-size: 12.5px; }
.panel-act a { color: var(--accent); text-decoration: none; }
.panel-b { padding: 16px 18px; }
.panel-b.flush { padding: 0; }

/* List rows */
.list-row { display: flex; align-items: center; gap: 13px; padding: 12px 18px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.panel-b.flush .list-row:last-child { border-bottom: none; }
a.list-row:hover { background: #00000005; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow b { font-size: 13.5px; font-weight: 600; display: block; }
.list-row .grow p { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-soft); }
.lr-right { text-align: right; flex: none; font-size: 13px; }

/* Date box */
.datebox { flex: none; width: 50px; text-align: center; background: var(--accent-soft, #eef1f5); border-radius: 8px; padding: 6px 0; }
.datebox b { display: block; font-size: 18px; font-weight: 700; font-family: var(--display-font, inherit); line-height: 1; }
.datebox span { font-size: 10.5px; text-transform: uppercase; color: var(--ink-soft); letter-spacing: .04em; }

/* Avatar / pill */
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; flex: none;
    border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 46px; height: 46px; font-size: 15px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 6px; background: #00000008; border: 1px solid var(--line); font-size: 11.5px; color: var(--ink-soft); }

/* Activity feed */
.feed-row { display: flex; align-items: center; gap: 11px; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.feed-row:last-child { border-bottom: none; }
.feed-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.feed-row .grow b { font-weight: 500; font-size: 13px; }
.feed-time { font-size: 11.5px; color: var(--ink-soft); flex: none; }

/* Progress */
.rprogress { background: var(--line); border-radius: 999px; height: 7px; overflow: hidden; min-width: 70px; }
.rprogress i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* Chart */
.chart-wrap { position: relative; width: 100%; }
.rempty { padding: 26px; text-align: center; color: var(--ink-soft); font-size: 13px; }

@media (max-width: 1000px) { .rgrid-2, .rgrid-3 { grid-template-columns: 1fr; } }

/* ---------- Dashboard widget drill-down modals ---------- */
.kpi-card.drill { cursor: pointer; transition: transform .12s, box-shadow .12s, border-color .12s; }
.kpi-card.drill:hover { transform: translateY(-2px); box-shadow: 0 1px 2px rgba(16,24,40,.06), 0 16px 30px -18px rgba(16,24,40,.5); }
.kpi-card.drill::after { content: "↗"; position: absolute; bottom: 11px; right: 13px; font-size: 13px; color: var(--ink-soft); opacity: .55; }
.kpi-card.drill:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.uimodal { position: fixed; inset: 0; z-index: 80; display: none; align-items: center; justify-content: center;
    background: rgba(16,20,28,.55); padding: 18px; }
.uimodal.open { display: flex; animation: uimodalfade .14s ease; }
@keyframes uimodalfade { from { opacity: 0; } to { opacity: 1; } }
.uimodal-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius, 10px);
    width: 100%; max-width: 720px; max-height: 86vh; display: flex; flex-direction: column;
    box-shadow: 0 24px 60px -12px rgba(0,0,0,.4); overflow: hidden; }
.uimodal-h { display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 14px 18px; border-bottom: 1px solid var(--line); }
.uimodal-h h3 { margin: 0; font-size: 15px; font-weight: 650; font-family: var(--display-font, inherit); }
.uimodal-close { background: none; border: none; font-size: 24px; line-height: 1; color: var(--ink-soft); cursor: pointer; padding: 0 4px; }
.uimodal-close:hover { color: var(--ink); }
.uimodal-b { padding: 16px 18px; overflow: auto; }
.uimodal-foot { margin-top: 14px; display: flex; justify-content: flex-end; }
@media (max-width: 860px) { .uimodal-card { max-height: 92vh; } }

/* ---------- "All CRMs" topbar link (replaces the switcher) ---------- */
.all-crms { display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px;
    border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
    color: var(--ink); text-decoration: none; font-size: 12.5px; font-weight: 600; }
.all-crms:hover { border-color: var(--accent); color: var(--accent); }
.all-crms svg { opacity: .8; }

/* ---- generic record detail: themed profile (modules/record.php) ---- */
.rec-subline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 7px; }
.rec-id { font-size: 12px; color: var(--ink-soft); font-weight: 600; letter-spacing: .02em; }
.rec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); gap: 1px; background: var(--line); }
.rec-cell { background: var(--panel, #fff); padding: 13px 18px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.rec-cell .rec-k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-soft); font-weight: 600; }
.rec-cell .rec-v { font-size: 14px; color: var(--ink, #1f2733); font-weight: 500; word-break: break-word; }
.rec-cell .rec-v a { color: var(--accent); text-decoration: none; }
.rec-cell .rec-v a:hover { text-decoration: underline; }
.rec-cell--wide { grid-column: 1 / -1; }
.rec-longtext { font-weight: 400; line-height: 1.6; color: var(--ink, #1f2733); white-space: pre-wrap; }
.rec-meta { font-size: 12px; color: var(--ink-soft); margin: 14px 2px 0; }
@media (max-width: 560px) { .rec-grid { grid-template-columns: 1fr; } }
