/* =====================================================================
   Debt Management CRM - Design Tokens & Core Styles
   ===================================================================== */

:root {
    /* Color tokens */
    --color-navy-900: #0B1E33;
    --color-navy-800: #0F2A4A;
    --color-navy-700: #1E3A5F;
    --color-navy-100: #E8EDF3;
    --color-teal: #0E7C7B;
    --color-teal-light: #E3F4F3;
    --color-amber: #B8860B;
    --color-amber-light: #FBF1DE;
    --color-red: #A02334;
    --color-red-light: #FBE7EA;
    --color-green: #1E7B45;
    --color-green-light: #E6F4EA;
    --color-ink: #1A1F29;
    --color-ink-soft: #5B6472;
    --color-bg: #F7F8FA;
    --color-surface: #FFFFFF;
    --color-border: #E2E6EC;

    /* Type */
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;

    /* Layout */
    --sidebar-width: 248px;
    --topbar-height: 64px;
    --radius-sm: 4px;
    --radius-md: 8px;
    --shadow-sm: 0 1px 2px rgba(15, 42, 74, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 42, 74, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-ui);
    background: var(--color-bg);
    color: var(--color-ink);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 600; color: var(--color-navy-900); letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }

/* ---- Layout shell ---- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--color-navy-800);
    color: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand .mark {
    width: 32px; height: 32px;
    background: var(--color-teal);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 15px; color: #fff;
}
.sidebar-brand .name { font-weight: 700; font-size: 15px; line-height: 1.2; }
.sidebar-brand .sub { font-size: 11px; color: rgba(255,255,255,0.55); }

.sidebar-nav { padding: 12px; flex: 1; }
.sidebar-section-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
    color: rgba(255,255,255,0.4); padding: 16px 12px 6px;
}
.sidebar-section-label.collapsible {
    cursor: pointer; user-select: none;
    display: flex; align-items: center; justify-content: space-between;
    border-radius: var(--radius-sm);
}
.sidebar-section-label.collapsible:hover { color: rgba(255,255,255,0.75); background: rgba(255,255,255,0.05); }
.sidebar-section-label .section-chevron {
    font-size: 9px; transition: transform 0.15s ease; opacity: 0.8;
}
.sidebar-section-label.is-collapsed .section-chevron { transform: rotate(-90deg); }
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; margin: 1px 0;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.8);
    font-size: 13.5px; font-weight: 500;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.08); text-decoration: none; color: #fff; }
.sidebar-nav a.active { background: var(--color-teal); color: #fff; }
.sidebar-nav .icon { width: 16px; text-align: center; opacity: 0.9; }

.sidebar-footer {
    padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 12px; color: rgba(255,255,255,0.5);
}

.main {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky; top: 0; z-index: 10;
}
.topbar .page-title { font-size: 17px; font-weight: 600; color: var(--color-navy-900); }
.topbar .user-chip {
    display: flex; align-items: center; gap: 10px;
    font-size: 13px;
}
.topbar .user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--color-navy-100); color: var(--color-navy-800);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 13px;
}
.topbar .role-tag {
    font-size: 11px; color: var(--color-ink-soft);
    background: var(--color-navy-100); padding: 2px 8px; border-radius: 10px;
}

.content { padding: 24px; flex: 1; }

/* ---- Cards ---- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between;
}
.card-body { padding: 20px; }

/* ---- Stat grid (dashboard) ---- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
@media (max-width: 1100px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}
.stat-card .stat-label {
    font-size: 12px; color: var(--color-ink-soft);
    text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600;
    margin-bottom: 8px;
}
.stat-card .stat-value { font-size: 26px; font-weight: 700; color: var(--color-navy-900); }
.stat-card .stat-sub { font-size: 12px; color: var(--color-ink-soft); margin-top: 4px; }
.stat-card.accent-teal { border-left: 3px solid var(--color-teal); }
.stat-card.accent-amber { border-left: 3px solid var(--color-amber); }
.stat-card.accent-red { border-left: 3px solid var(--color-red); }
.stat-card.accent-navy { border-left: 3px solid var(--color-navy-700); }

/* Same text styling as .stat-card's label/value/sub, for use when a stat needs
   to sit inside another card's body (e.g. a merged summary row) without the
   nested box/border/shadow of a full standalone .stat-card. */
.stat-inline .stat-label {
    font-size: 12px; color: var(--color-ink-soft);
    text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600;
    margin-bottom: 6px;
}
.stat-inline .stat-value { font-size: 26px; font-weight: 700; color: var(--color-navy-900); }
.stat-inline .stat-sub { font-size: 12px; color: var(--color-ink-soft); margin-top: 4px; }

/* ---- Status pills (signature element) ---- */
.pill {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11.5px; font-weight: 600;
    padding: 3px 10px; border-radius: 100px;
    text-transform: none;
    white-space: nowrap;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-new { background: #EEF1F5; color: #4A5568; }
.pill-assigned { background: var(--color-navy-100); color: var(--color-navy-800); }
.pill-contacted { background: var(--color-teal-light); color: var(--color-teal); }
.pill-negotiation { background: var(--color-amber-light); color: var(--color-amber); }
.pill-promise-to-pay { background: var(--color-amber-light); color: var(--color-amber); }
.pill-partially-paid { background: #FFF4E0; color: #946200; }
.pill-settled { background: var(--color-green-light); color: var(--color-green); }
.pill-closed { background: var(--color-green-light); color: var(--color-green); }
.pill-legal-action { background: var(--color-red-light); color: var(--color-red); }

/* ---- Call Log Timeline ---- */
.call-log-list { display: flex; flex-direction: column; gap: 16px; }
.call-log-item {
    display: flex; gap: 14px;
    padding: 16px; border: 1px solid var(--color-border);
    border-left: 4px solid var(--outcome-accent, var(--color-navy-700));
    border-radius: var(--radius-md); background: var(--color-surface);
}
.call-log-icon {
    flex-shrink: 0; width: 38px; height: 38px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    background: var(--outcome-bg, var(--color-navy-100));
    color: var(--outcome-accent, var(--color-navy-800));
}
.call-log-body { flex: 1; min-width: 0; }
.call-log-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.call-log-time { font-size: 12px; color: var(--color-ink-soft); font-weight: 500; }
.call-log-officer { font-size: 12.5px; color: var(--color-navy-800); font-weight: 600; margin-top: 6px; }
.call-log-remarks {
    margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--color-border);
    font-size: 14px; color: var(--color-ink); line-height: 1.5;
}
.call-log-meta { margin-top: 8px; font-size: 12px; color: var(--color-ink-soft); display: flex; gap: 14px; flex-wrap: wrap; }
.call-log-meta strong { color: var(--color-ink-soft); font-weight: 600; }

/* ---- Update Cards (Follow-Ups / Promise to Pay / Recovery Updates) ----
   Deliberately different visual language from Call Log cards: a top accent
   border + rounded icon badge instead of a left border + circular icon,
   and a shadow instead of a border, so the two card families read distinctly. */
.update-list { display: flex; flex-direction: column; gap: 14px; }
.update-card {
    display: flex; gap: 14px;
    padding: 16px 18px;
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    border-top: 3px solid var(--accent-color, var(--color-navy-700));
}
.update-card-icon {
    flex-shrink: 0; width: 34px; height: 34px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px;
    background: var(--accent-bg, var(--color-navy-100));
    color: var(--accent-color, var(--color-navy-800));
}
.update-card-body { flex: 1; min-width: 0; }
.update-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.update-card-title { font-size: 15px; font-weight: 600; color: var(--color-ink); }
.update-card-meta { margin-top: 6px; font-size: 12px; color: var(--color-ink-soft); display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.update-card-remarks {
    margin-top: 10px; font-size: 13.5px; color: var(--color-ink); line-height: 1.5;
    background: var(--color-navy-50, #F5F8FB); padding: 10px 12px; border-radius: var(--radius-sm);
}
.update-card-actions { margin-top: 12px; display: flex; gap: 8px; }

/* ---- Topbar Updates bell ---- */
.updates-wrap { position: relative; }
.updates-bell-btn {
    position: relative; background: none; border: none; cursor: pointer;
    font-size: 19px; padding: 6px; border-radius: 50%; line-height: 1;
    display: flex; align-items: center; justify-content: center;
}
.updates-bell-btn:hover { background: var(--color-navy-100); }
.updates-badge {
    position: absolute; top: 0; right: 0; background: var(--color-red); color: #fff;
    font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center; padding: 0 4px;
    border: 2px solid var(--color-surface);
}
.updates-dropdown {
    display: none; position: absolute; top: calc(100% + 10px); right: 0;
    width: 340px; max-height: 420px; overflow-y: auto;
    background: var(--color-surface); border-radius: var(--radius-md);
    box-shadow: var(--shadow-md); border: 1px solid var(--color-border);
    z-index: 50;
}
.updates-dropdown.open { display: block; }
.updates-dropdown-header {
    padding: 12px 16px; font-weight: 700; font-size: 13px; color: var(--color-navy-900);
    border-bottom: 1px solid var(--color-border);
}
.updates-dropdown-empty { padding: 24px 16px; text-align: center; font-size: 13px; color: var(--color-ink-soft); }
.updates-dropdown-item {
    display: block; padding: 12px 16px; text-decoration: none; color: inherit;
    border-bottom: 1px solid var(--color-border);
}
.updates-dropdown-item:last-child { border-bottom: none; }
.updates-dropdown-item:hover { background: var(--color-navy-50, #F5F8FB); }
.updates-item-title { font-size: 13.5px; font-weight: 600; color: var(--color-navy-900); }
.updates-item-meta { font-size: 12px; color: var(--color-ink-soft); margin-top: 3px; }
.type-chip {
    font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
    color: var(--color-ink-soft); background: var(--color-navy-50, #F2F4F7);
    border: 1px solid var(--color-border); padding: 2px 8px; border-radius: 20px;
}

/* generic badges (used for status fallback class names) */
.badge-secondary { background: #EEF1F5; color: #4A5568; }
.badge-info { background: var(--color-navy-100); color: var(--color-navy-800); }
.badge-warning { background: var(--color-amber-light); color: var(--color-amber); }
.badge-success { background: var(--color-green-light); color: var(--color-green); }
.badge-danger { background: var(--color-red-light); color: var(--color-red); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em;
    color: var(--color-ink-soft); font-weight: 600;
    padding: 10px 14px; border-bottom: 1px solid var(--color-border);
    background: #FAFBFC;
}
table.data-table td {
    padding: 11px 14px; border-bottom: 1px solid var(--color-border);
    color: var(--color-ink); vertical-align: middle;
}
table.data-table tr:hover td { background: #FAFBFD; }
table.data-table tr:last-child td { border-bottom: none; }

/* ---- Forms ---- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--color-navy-900); }
.form-control {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--color-border); border-radius: var(--radius-sm);
    font-size: 13.5px; font-family: var(--font-ui);
    background: var(--color-surface); color: var(--color-ink);
}
.form-control:focus {
    outline: none; border-color: var(--color-teal);
    box-shadow: 0 0 0 3px var(--color-teal-light);
}
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-hint { font-size: 12px; color: var(--color-ink-soft); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--color-red); margin-top: 4px; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 16px; border-radius: var(--radius-sm);
    font-size: 13.5px; font-weight: 600; font-family: var(--font-ui);
    border: 1px solid transparent; cursor: pointer;
    transition: background 0.15s ease;
}
.btn:disabled, .btn.is-submitting { opacity: 0.6; cursor: wait; pointer-events: none; }
.btn.is-submitting::after { content: "…"; margin-left: 2px; }
.btn-primary { background: var(--color-navy-800); color: #fff; }
.btn-primary:hover { background: var(--color-navy-900); }
.btn-teal { background: var(--color-teal); color: #fff; }
.btn-teal:hover { background: #0a6362; }
.btn-outline { background: transparent; border-color: var(--color-border); color: var(--color-ink); }
.btn-outline:hover { background: #F2F4F7; }
.btn-danger { background: var(--color-red); color: #fff; }
.btn-danger:hover { background: #861d2c; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* ---- Alerts / flash messages ---- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13.5px; }
.alert-success { background: var(--color-green-light); color: var(--color-green); border: 1px solid #BFE3CC; }
.alert-error { background: var(--color-red-light); color: var(--color-red); border: 1px solid #EFC4CB; }
.alert-info { background: var(--color-navy-100); color: var(--color-navy-800); border: 1px solid #CBD9E8; }

/* ---- Login page ---- */
.login-shell {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--color-navy-900);
    background-image: radial-gradient(circle at 20% 20%, var(--color-navy-700) 0%, var(--color-navy-900) 55%);
    padding: 20px;
}
.login-card {
    background: var(--color-surface); border-radius: var(--radius-md);
    width: 100%; max-width: 380px; padding: 36px 32px;
    box-shadow: var(--shadow-md);
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.login-brand .mark {
    width: 38px; height: 38px; background: var(--color-teal); border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700;
}
.login-brand .title { font-weight: 700; font-size: 16px; color: var(--color-navy-900); }
.login-brand .subtitle { font-size: 12px; color: var(--color-ink-soft); }

/* ---- Utility ---- */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.text-muted { color: var(--color-ink-soft); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.w-100 { width: 100%; }
.empty-state {
    text-align: center; padding: 48px 20px; color: var(--color-ink-soft);
}
.empty-state .icon { font-size: 32px; margin-bottom: 12px; opacity: 0.5; }

/* ---- Tabs (case detail activity sections) ---- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--color-border); margin-bottom: 0; }
.tab-btn {
    padding: 10px 16px; font-size: 13px; font-weight: 600;
    color: var(--color-ink-soft); background: none; border: none;
    border-bottom: 2px solid transparent; cursor: pointer; font-family: var(--font-ui);
}
.tab-btn:hover { color: var(--color-navy-900); }
.tab-btn.active { color: var(--color-navy-900); border-bottom-color: var(--color-teal); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.activity-item {
    padding: 12px 0; border-bottom: 1px solid var(--color-border);
}
.activity-item:last-child { border-bottom: none; }
.activity-item .meta { font-size: 12px; color: var(--color-ink-soft); margin-top: 2px; }
.doc-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--color-border); }
.doc-row:last-child { border-bottom: none; }
.doc-icon { width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--color-navy-100); display: flex; align-items: center; justify-content: center; font-size: 13px; color: var(--color-navy-800); font-weight: 700; flex-shrink: 0; }

/* ---- Mobile responsive ---- */
.mobile-menu-toggle {
    display: none; background: none; border: none; cursor: pointer;
    font-size: 20px; padding: 6px 8px; border-radius: 6px; color: var(--color-navy-900);
    margin-right: 4px; flex-shrink: 0;
}
.mobile-menu-toggle:hover { background: var(--color-navy-100); }
.sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
    z-index: 150;
}
.sidebar-overlay.active { display: block; }

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 200;
        width: min(var(--sidebar-width), 82vw);
    }
    .sidebar.mobile-open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.25); }
    .main { margin-left: 0; }
    .mobile-menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
    .topbar { padding: 0 14px; gap: 10px; }
    .topbar .page-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
    .updates-wrap form[action*="search"] { display: none; } /* search box hidden on small screens to save space; still reachable via full Search page link */
}

@media (max-width: 600px) {
    .stat-grid { grid-template-columns: 1fr !important; }
    .form-row { grid-template-columns: 1fr; }
    .topbar .role-tag { display: none; }
    .updates-dropdown { width: calc(100vw - 32px); right: -8px; }
    .card-body, .card-header { padding-left: 14px; padding-right: 14px; }
    .btn { padding: 8px 12px; font-size: 13px; }
    .data-table th, .data-table td { padding: 8px 10px; font-size: 12.5px; }
}
