/* Ucanly Sales CRM — single stylesheet, no external dependencies. */

:root {
    --bg:        #f4f6fa;
    --surface:   #ffffff;
    --border:    #e2e6ee;
    --text:      #1a2233;
    --muted:     #667085;
    --brand:     #0b57d0;
    --brand-dark:#0842a0;
    --success:   #1a7f37;
    --success-bg:#e8f5ec;
    --danger:    #b42318;
    --danger-bg: #fdecea;
    --warning:   #8a5a00;
    --warning-bg:#fdf3e2;
    --info:      #0b57d0;
    --info-bg:   #e8f0fd;
    --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, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

body.centered {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

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

h1, h2, h3 { margin: 0 0 .5em; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

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

.sidebar {
    width: 232px;
    flex: 0 0 232px;
    background: #10192b;
    color: #c9d2e3;
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.brand-mark {
    width: 30px; height: 30px; border-radius: 8px;
    background: var(--brand); color: #fff;
    display: grid; place-items: center; font-weight: 700;
}
.brand-text { font-weight: 600; color: #fff; letter-spacing: .2px; }

.nav-group-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
    color: #6b7a94; padding: 16px 10px 6px;
}

.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list a {
    display: block; padding: 8px 10px; border-radius: 7px;
    color: #c9d2e3; font-size: 13.5px;
}
.nav-list a:hover { background: #1b2740; color: #fff; text-decoration: none; }
.nav-list a.active { background: var(--brand); color: #fff; font-weight: 500; }

.nav-footer { margin-top: auto; border-top: 1px solid #223050; padding-top: 14px; }
.nav-footer .who { display: block; color: #fff; font-size: 13px; margin-bottom: 8px; }
.nav-footer .who:hover { text-decoration: none; opacity: .85; }

.role-chip {
    display: inline-block; margin-top: 4px;
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px;
    padding: 2px 7px; border-radius: 20px; background: #223050; color: #9fb2d4;
}
.role-superadmin { background: #4a2b6b; color: #d9c2f0; }
.role-manager    { background: #14456b; color: #b6ddff; }

.main { flex: 1; padding: 26px 30px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    margin-bottom: 18px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.auth-card   { width: 100%; max-width: 380px; margin: 0; }
.intake-card { width: 100%; max-width: 620px; margin: 0; }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 4px; letter-spacing: -.5px; }
.stat .sub   { font-size: 12px; color: var(--muted); margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: #fafbfe; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Forms ---------- */
label { display: block; font-size: 12.5px; font-weight: 600; color: #3a465c; margin-bottom: 4px; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 3px; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=url], input[type=date], input[type=search], input[type=tel],
select, textarea {
    width: 100%;
    padding: 8px 10px;
    font: inherit;
    color: var(--text);
    background: #fff;
    border: 1px solid #cdd5e2;
    border-radius: 7px;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(11, 87, 208, .12);
}
textarea { min-height: 120px; resize: vertical; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; min-height: 340px; }

.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 13.5px; margin-bottom: 8px; }
.checkline input { width: auto; }
.checkline label { margin: 0; font-weight: 400; }

fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 0 0 14px; }
legend { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; padding: 0 6px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    padding: 8px 14px;
    font: inherit; font-weight: 500;
    color: var(--text); background: #fff;
    border: 1px solid #cdd5e2; border-radius: 7px;
    cursor: pointer; text-decoration: none;
}
.btn:hover { background: #f5f7fb; text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { background: #fff; border-color: #e6b4ae; color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-ghost { background: transparent; border-color: #3a4a68; color: #c9d2e3; }
.btn-ghost:hover { background: #1b2740; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions-end { justify-content: flex-end; }

/* ---------- Filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 160px; }

/* ---------- Flash messages ---------- */
.flashes { margin-bottom: 16px; display: grid; gap: 8px; }
.flash { padding: 10px 14px; border-radius: 8px; border: 1px solid transparent; font-size: 13.5px; }
.flash-success { background: var(--success-bg); border-color: #bfe3cc; color: var(--success); }
.flash-error   { background: var(--danger-bg);  border-color: #f3c2bd; color: var(--danger); }
.flash-warning { background: var(--warning-bg); border-color: #f0dcb4; color: var(--warning); }
.flash-info    { background: var(--info-bg);    border-color: #c3d8fa; color: var(--info); }

/* ---------- Badges ---------- */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11.5px; font-weight: 600; white-space: nowrap;
    background: #eef1f6; color: #4a5670;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info    { background: var(--info-bg);    color: var(--info); }

/* ---------- Misc ---------- */
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono  { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.right { text-align: right; }
.mt    { margin-top: 16px; }
.mb    { margin-bottom: 16px; }
.pre   { white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; background: #f7f9fc; border: 1px solid var(--border); border-radius: 8px; padding: 14px; overflow-x: auto; }

.callout { border-left: 3px solid var(--brand); background: var(--info-bg); padding: 10px 14px; border-radius: 0 8px 8px 0; font-size: 13px; margin-bottom: 14px; }
.callout-warn { border-left-color: var(--warning); background: var(--warning-bg); color: var(--warning); }
.callout-danger { border-left-color: var(--danger); background: var(--danger-bg); color: var(--danger); }

.pagination { display: flex; align-items: center; gap: 12px; margin-top: 14px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 2px solid var(--border); padding: 0 0 14px 14px; position: relative; }
.timeline li::before {
    content: ''; position: absolute; left: -5px; top: 5px;
    width: 8px; height: 8px; border-radius: 50%; background: var(--brand);
}
.timeline .meta { font-size: 12px; color: var(--muted); }

.dl { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; font-size: 13.5px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }

.preview-frame { border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 8px; }
.preview-frame iframe { width: 100%; min-height: 520px; border: 0; display: block; }

.chart-box { position: relative; height: 260px; }

/* =====================================================================
   The sheet
   ===================================================================== */

.card.compact { padding: 12px 14px; }

.toolbar {
    display: flex; flex-wrap: wrap; gap: 12px;
    align-items: center; justify-content: space-between;
    margin-bottom: 10px;
}

.sheet-wrap {
    overflow: auto;
    max-height: calc(100vh - 260px);
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

table.sheet {
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12.5px;
    width: max-content;
    min-width: 100%;
}

table.sheet th,
table.sheet td {
    border-right: 1px solid #eceff5;
    border-bottom: 1px solid #eceff5;
    padding: 0;
    vertical-align: middle;
    background: #fff;
}

table.sheet thead th {
    position: sticky; top: 0; z-index: 3;
    background: #f0f3f9;
    color: #3a465c;
    font-size: 11px;
    text-transform: none;
    letter-spacing: .2px;
    font-weight: 600;
    white-space: nowrap;
    padding: 7px 8px;
    border-bottom: 2px solid #d7dee9;
}

table.sheet tbody tr:hover td { background: #fbfcfe; }
table.sheet tbody tr:hover .ro { background: #fbfcfe; }

/* Frozen left columns. Header cells need the higher z-index so they stay
   above the frozen body cells when both are sticky. */
.sticky-1, .sticky-2, .sticky-3 { position: sticky; z-index: 2; }
thead .sticky-1, thead .sticky-2, thead .sticky-3 { z-index: 4; }
.sticky-1 { left: 0; }
.sticky-2 { left: 34px; }
.sticky-3 { left: 174px; }

table.sheet .sticky-1,
table.sheet .sticky-2,
table.sheet .sticky-3 { box-shadow: 1px 0 0 #e2e6ee; }

.col-check   { width: 34px; text-align: center; }
.col-check input { margin: 0; }
.col-ref     { width: 140px; }
.col-name    { width: 170px; }
.col-status  { min-width: 132px; }
.col-comment { min-width: 150px; }
.col-send    { width: 90px; text-align: center; }

/* Cells: inputs and selects sit flush, so the table reads as a grid
   rather than as a form. */
table.sheet .cell {
    width: 100%;
    min-width: 90px;
    border: 1px solid transparent;
    border-radius: 0;
    background: transparent;
    padding: 6px 8px;
    font: inherit;
    color: var(--text);
    box-shadow: none;
}
table.sheet .cell:hover { background: #f4f7fd; }
table.sheet .cell:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: inset 0 0 0 1px var(--brand);
    background: #fff;
    position: relative; z-index: 1;
}

table.sheet .ro {
    display: block;
    padding: 6px 8px;
    color: #475467;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 240px;
}

table.sheet .w-wide    { min-width: 170px; }
table.sheet .w-email   { min-width: 180px; }
table.sheet .w-phone   { min-width: 120px; }
table.sheet .w-date    { min-width: 100px; }
table.sheet .w-comment { min-width: 150px; }

/* The next empty status slot, so it is obvious where today's call goes. */
td.next-slot { background: #fcfdff; box-shadow: inset 0 0 0 1px #dbe6fb; }

/* --- Status chips, matching the colours used in the sheet ------------ */
select.chip {
    appearance: none;
    -webkit-appearance: none;
    border-radius: 4px !important;
    font-weight: 600;
    font-size: 12px;
    text-align: left;
    padding: 5px 8px !important;
    margin: 3px;
    width: calc(100% - 6px) !important;
    cursor: pointer;
}
select.chip option { font-weight: 400; color: var(--text); background: #fff; }

.status-blank         { background: #f2f4f8; color: #98a2b3; }
.status-enrolled      { background: #c6efce; color: #14532d; }
.status-followup      { background: #1a73e8; color: #ffffff; }
.status-callback      { background: #cfe4fb; color: #0b3f7a; }
.status-dnp           { background: #ffe6a7; color: #7a4c00; }
.status-notinterested { background: #e8443a; color: #ffffff; }
.status-switchoff     { background: #7b4a2d; color: #ffffff; }
.status-decline       { background: #f9c8c4; color: #8a1c14; }
.status-junk          { background: #4a5568; color: #ffffff; }

.chip-gen  { background: #14a44d; color: #fff; }
.chip-send { background: #eef1f6; color: #3a465c; }

/* --- Row save indicator ---------------------------------------------- */
.row-state {
    display: inline-block;
    font-size: 10.5px;
    min-width: 52px;
    text-align: right;
    color: var(--muted);
}
.row-state-saving { color: var(--muted); }
.row-state-saved  { color: var(--success); }
.row-state-failed { color: var(--danger); font-weight: 600; }

.icon-btn {
    border: 1px solid #cdd5e2;
    background: #fff;
    border-radius: 5px;
    width: 22px; height: 22px;
    font-size: 11px; font-weight: 700;
    line-height: 1;
    color: #475467;
    cursor: pointer;
    padding: 0;
}
.icon-btn:hover { background: var(--brand); border-color: var(--brand); color: #fff; }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

/* --- History drawer --------------------------------------------------- */
.drawer {
    position: fixed; right: 0; top: 0; bottom: 0;
    width: min(380px, 92vw);
    background: #fff;
    border-left: 1px solid var(--border);
    box-shadow: -6px 0 24px rgba(16, 24, 40, .12);
    z-index: 50;
    display: flex; flex-direction: column;
}
.drawer-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.drawer-body { padding: 16px; overflow-y: auto; font-size: 13px; }

@media (max-width: 860px) {
    .shell { flex-direction: column; }
    .sidebar { width: 100%; flex: none; }
    .nav-list { display: flex; flex-wrap: wrap; gap: 4px; }
    .nav-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
    .main { padding: 18px 16px 40px; }
    .dl { grid-template-columns: 1fr; }
}
