:root {
    /* ---- Alfonica brand palette (from "Alfonica-New_colours_4.pdf") ----
       Where the guide's HEX and RGB lines disagree, the HEX is used (it
       matches the swatch artwork) - except Lilac, not used here.
       Muted Blue / Sky Blue (#98B8D4) is deliberately NOT used: the guide
       reserves it for the logo only. */
    --brand-rich-blue: #3b52a0;
    --brand-mauve: #8371b2;
    --brand-pink: #dba3ca;
    --brand-teal: #9ad3d4;
    --brand-text-grey: #58595b;   /* body copy - guide: never 100% black */
    --brand-cornflower: #718ce3;
    --brand-punch: #f17592;
    --brand-tangerine: #e49c71;
    --brand-sea: #57c1a6;

    /* Brand gradient: always blue top-left -> teal bottom-right. */
    --brand-gradient: linear-gradient(135deg,
        var(--brand-rich-blue) 0%, var(--brand-mauve) 35%,
        var(--brand-pink) 70%, var(--brand-teal) 100%);

    /* ---- Semantic roles ---- */
    --bg: #f4f6fb;                 /* faint tint of Rich blue */
    --card: #ffffff;
    --border: #dfe3ef;
    --text: var(--brand-text-grey);
    --text-muted: #6b6c6f;         /* lighter grey, still >= 4.5:1 on white */
    --primary: var(--brand-rich-blue);
    --primary-hover: #2f4182;      /* Rich blue, darkened */
    --success: var(--brand-sea);
    --error: var(--brand-punch);
    /* Punch is too light for text or white-on-fill (2.7:1), so anywhere an
       error needs to be READ (delete button, inline error text) uses this
       darkened Punch (5.3:1) instead. */
    --error-dark: #c2365a;
    --warning: var(--brand-tangerine);
    --focus: var(--brand-cornflower);

    /* Pale tints of palette colours, used as backgrounds under grey text. */
    --tint-primary: #eff1f7;
    --tint-hover: #eef1fa;
    --tint-success: #e6f6f2;
    --tint-error: #fdeaef;
    --tint-warning: #fbf0ea;

    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* ---- Login page ---- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-card {
    position: relative;
    overflow: hidden;            /* clips the gradient strip to the rounded corners */
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 320px;
    box-shadow: 0 4px 16px rgba(59, 82, 160, 0.12);
}
.login-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: var(--brand-gradient);
}
.login-card h1 {
    font-size: 20px;
    margin: 0 0 20px;
    text-align: center;
    color: var(--primary);
}
.login-card label {
    display: block;
    font-size: 13px;
    margin: 12px 0 4px;
    color: var(--text-muted);
}
.login-card input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}
.login-card button {
    margin-top: 20px;
    width: 100%;
}

/* ---- Layout ---- */
.topbar {
    position: relative;
    background: var(--card);
    padding: 14px 24px 18px;     /* extra bottom padding makes room for the strip */
    display: flex;
    align-items: center;
    justify-content: space-between;
}
/* The brand gradient, in one deliberate place. */
.topbar::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 4px;
    background: var(--brand-gradient);
}
.topbar h1 {
    font-size: 18px;
    margin: 0;
    color: var(--primary);
}
.topbar nav a {
    margin-left: 16px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
}
.topbar nav a.active,
.topbar nav a:hover {
    color: var(--primary);
}
.container {
    max-width: 1100px;
    margin: 24px auto;
    padding: 0 20px 60px;
}

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

/* ---- Form controls ---- */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
}
.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.field label {
    font-size: 12px;
    color: var(--text-muted);
}
input[type="date"], input[type="time"], input[type="text"], input[type="password"] {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text);          /* browsers default inputs to pure black */
}

button, .btn {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 9px 18px;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}
button:hover, .btn:hover { background: var(--primary-hover); }
button.secondary, .btn.secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
}
button.secondary:hover { background: var(--tint-hover); }
button.danger { background: var(--error-dark); }
button.danger:hover { filter: brightness(0.92); }
button:disabled { opacity: 0.6; cursor: default; }

/* Visible keyboard focus, in the brand's Cornflower. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

/* ---- Table ---- */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
tr:last-child td { border-bottom: none; }
form.row-form { display: contents; }
.row-form input[type="text"] { width: 100%; }
td.num, th.num { text-align: right; }
tr.unmapped { background: var(--tint-warning); }
.badge {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--warning);
    color: #3f4042;              /* dark grey: 4.5:1+ on Tangerine, which white is not */
}

/* Status colours are fills and edges only (Punch, Sea and Tangerine are
   all below 3:1 on white, so they can't carry text); the text stays in
   the brand grey on a pale tint. */
.alert {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 14px;
    margin: 0 0 14px;
    color: var(--text);
    border-left: 4px solid transparent;
}
.alert-error   { background: var(--tint-error);   border-left-color: var(--error); }
.alert-success { background: var(--tint-success); border-left-color: var(--success); }
.alert-warning { background: var(--tint-warning); border-left-color: var(--warning); }

.muted { color: var(--text-muted); font-size: 13px; }
.spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: -2px;
}
/* The default spinner is white (for the blue primary buttons); on the white
   secondary/icon buttons it needs to be blue or it can't be seen. */
button.secondary .spinner {
    border-color: rgba(59, 82, 160, 0.25);
    border-top-color: var(--primary);
}
@keyframes spin { to { transform: rotate(360deg); } }

.totals-row {
    display: flex;
    gap: 28px;
    margin: 4px 0 18px;
    flex-wrap: wrap;
}
.totals-row .stat {
    background: var(--tint-primary);
    border-radius: 6px;
    padding: 10px 16px;
    min-width: 120px;
}
.totals-row .stat .num-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
}
.totals-row .stat .label {
    font-size: 12px;
    color: var(--text-muted);
}

/* ---- Client name link (opens call detail modal) ---- */
.client-link {
    background: none;
    border: none;
    /* Padding gives the hover highlight some room around the text; the
       equal negative margin cancels it out so the name itself doesn't
       move, and neither does the row height. */
    padding: 2px 6px;
    margin: -2px -6px;
    color: var(--primary);
    text-decoration: underline;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
}
/* On hover the link gets a dark Rich blue highlight (the global button hover
   style), so the text turns white to stay readable on it, and the underline
   is dropped because it pokes out of the highlighted area. Both go back to
   normal as soon as the mouse moves away. The highlight colour is set
   explicitly here rather than inherited from the general button rule. */
.client-link:hover {
    background: var(--primary-hover);
    color: #fff;
    text-decoration: none;
}

/* ---- Call detail modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(32, 42, 92, 0.5);      /* Rich blue, darkened - not a neutral navy */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal-box {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    width: 100%;
    max-width: 1180px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(32, 42, 92, 0.30);
}
.modal-box.small-modal-box {
    max-width: 420px;
    max-height: none;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
.modal-header h2 { margin: 0; font-size: 16px; color: var(--primary); }
.modal-scroll {
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    min-height: 0;
}
/* Fixed layout + per-column widths + ellipsis truncation guarantees this
   table can never force a horizontal scrollbar, no matter how long a
   customer name or caller number happens to be - it truncates cleanly
   instead, rather than the modal growing a scroll box. */
.modal-scroll table {
    font-size: 13px;
    table-layout: fixed;
    width: 100%;
}
.modal-scroll th,
.modal-scroll td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-left: 8px;
    padding-right: 8px;
}
#callModalTable th:nth-child(1), #callModalTable td:nth-child(1) { width: 9%; }  /* Date */
#callModalTable th:nth-child(2), #callModalTable td:nth-child(2) { width: 8%; }  /* Time */
#callModalTable th:nth-child(3), #callModalTable td:nth-child(3) { width: 13%; } /* Caller */
#callModalTable th:nth-child(4), #callModalTable td:nth-child(4) { width: 13%; } /* Customer */
#callModalTable th:nth-child(5), #callModalTable td:nth-child(5) { width: 13%; } /* Called Number */
#callModalTable th:nth-child(6), #callModalTable td:nth-child(6) { width: 9%; }  /* Answered */
#callModalTable th:nth-child(7), #callModalTable td:nth-child(7) { width: 9%; }  /* Extension */
#callModalTable th:nth-child(8), #callModalTable td:nth-child(8) { width: 8%; }  /* Wait */
#callModalTable th:nth-child(9), #callModalTable td:nth-child(9) { width: 8%; }  /* Talk */
#callModalTable th:nth-child(10), #callModalTable td:nth-child(10) { width: 10%; } /* Actions */

/* Outbound report's call modal (9 columns) - own widths, since its columns
   differ from the inbound table above. */
#outboundModalTable th:nth-child(1), #outboundModalTable td:nth-child(1) { width: 11%; } /* Date */
#outboundModalTable th:nth-child(2), #outboundModalTable td:nth-child(2) { width: 9%; }  /* Time */
#outboundModalTable th:nth-child(3), #outboundModalTable td:nth-child(3) { width: 10%; } /* Extension */
#outboundModalTable th:nth-child(4), #outboundModalTable td:nth-child(4) { width: 15%; } /* Customer Number */
#outboundModalTable th:nth-child(5), #outboundModalTable td:nth-child(5) { width: 17%; } /* Number Called */
#outboundModalTable th:nth-child(6), #outboundModalTable td:nth-child(6) { width: 10%; } /* Answered */
#outboundModalTable th:nth-child(7), #outboundModalTable td:nth-child(7) { width: 10%; } /* Talk */
#outboundModalTable th:nth-child(8), #outboundModalTable td:nth-child(8) { width: 10%; } /* Total */
#outboundModalTable th:nth-child(9), #outboundModalTable td:nth-child(9) { width: 8%; }  /* Actions */
.modal-scroll thead th {
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 1;
}
.call-audio-cell {
    display: flex;
    gap: 4px;
    align-items: center;
}
.icon-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 13px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.icon-btn .spinner {
    margin: 0;
}
