/* Query Tracker — design tokens
   Palette: teal (brand/likelihood), green (offered/won), amber (open),
   red (lost — reserved only for that), slate (neutral/not offered) */

:root {
    --bg: #F6F7F9;
    --surface: #FFFFFF;
    --border: #E3E7EC;
    --text: #17212B;
    --text-muted: #64748B;

    --teal: #0F766E;
    --teal-dark: #0B5A54;
    --teal-light: #CFF3EF;

    --green: #15803D;
    --green-bg: #E4F6EA;

    --amber: #B45309;
    --amber-bg: #FDF1DF;

    --red: #B91C1C;
    --red-bg: #FBE7E7;

    --slate: #475569;
    --slate-bg: #EEF1F4;

    --blue: #1D4ED8;
    --blue-dark: #1739A6;
    --blue-bg: #E4EBFB;

    --purple: #6D28D9;
    --purple-dark: #5B21B6;
    --purple-bg: #EDE6FB;

    --radius: 10px;
    --shadow: 0 1px 2px rgba(23, 33, 43, 0.06), 0 1px 1px rgba(23, 33, 43, 0.04);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, Segoe UI, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

h1, h2 { font-family: 'Space Grotesk', 'Inter', sans-serif; margin: 0; }
h2 { font-size: 1.05rem; font-weight: 700; margin-bottom: 16px; color: var(--text); }

.queries-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.queries-header h2 { margin-bottom: 0; }

.search-form {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.search-form input[type="text"] {
    flex: 1;
    min-width: 220px;
    margin: 2px 0;
}
.search-result-note {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0 0 14px;
}
.live-indicator {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.78rem; color: var(--text-muted);
    border: 1px solid var(--border); border-radius: 999px;
    padding: 4px 10px;
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); display: inline-block; }
.live-indicator.live-pulse { border-color: var(--teal); color: var(--teal-dark); }
.live-indicator.live-paused .live-dot { background: var(--text-muted); }

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 0.5px solid var(--border);
}
.pagination-status { font-size: 0.85rem; color: var(--text-muted); }

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

/* ---- Top bar ---- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--teal);
    color: #fff;
    padding: 14px 28px;
    position: relative;
}
.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1.15rem;
}
.topbar-mark {
    width: 12px; height: 12px;
    border-radius: 3px;
    background: #fff;
    display: inline-block;
    box-shadow: 3px 3px 0 rgba(255,255,255,0.35);
}
.topbar-nav { display: flex; align-items: center; gap: 20px; font-size: 0.9rem; }
.topbar-nav a { color: #EAFBF8; }
.topbar-user { color: #EAFBF8; }
.topbar-user strong { color: #fff; }

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
}

/* ---- Layout ---- */
.page {
    max-width: 1440px;
    margin: 0 auto;
    padding: 28px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

/* ---- Stats bar ---- */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr) 1.2fr 1.2fr;
    gap: 16px;
    margin-bottom: 24px;
}
.stats-bar-secondary {
    grid-template-columns: repeat(5, 1fr);
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.stat-value { font-family: 'Space Grotesk', sans-serif; font-size: 1.9rem; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: 0.82rem; }
.stat-highlight { border-color: var(--teal); border-width: 2px; }
.stat-highlight .stat-value { color: var(--teal-dark); }
.stat-existing {
    background: var(--blue-bg);
    border-color: var(--blue);
    border-left-width: 4px;
}
.stat-existing .stat-value { color: var(--blue-dark); }
.stat-attention {
    background: var(--purple-bg);
    border-color: var(--purple);
    border-left-width: 4px;
}
.stat-attention .stat-value { color: var(--purple-dark); }

/* ---- Forms ---- */
.form-row { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 4px; }
.form-group { flex: 1; min-width: 180px; margin-bottom: 16px; }
.form-group-checkbox { display: flex; align-items: flex-end; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.form-group-checkbox label { display: flex; align-items: center; gap: 6px; font-weight: 500; }

input[type="text"], input[type="password"], input[type="email"], textarea, select {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    background: #fff;
    color: var(--text);
}
input:focus, textarea:focus, select:focus {
    outline: 2px solid var(--teal);
    outline-offset: 1px;
    border-color: var(--teal);
}
textarea { resize: vertical; }

.radio-group { display: flex; gap: 10px; }
.radio-pill {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}
.radio-pill input { width: auto; }

.btn {
    display: inline-block;
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-existing { background: var(--blue); color: #fff; }
.btn-existing:hover { background: var(--blue-dark); }
.btn-lead { background: var(--purple); color: #fff; }
.btn-lead:hover { background: var(--purple-dark); }
.btn-block { width: 100%; padding: 12px; }
.btn-small { padding: 6px 12px; font-size: 0.82rem; }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--teal); color: var(--teal-dark); }
.update-toggle-btn { display: inline-flex; align-items: center; gap: 3px; padding: 6px 10px; }
.update-toggle-btn .chevron { display: inline-block; font-size: 0.85em; transition: transform 0.15s ease; }
.update-toggle-btn.btn-open { background: var(--teal-light); border-color: var(--teal); color: var(--teal-dark); }
.update-toggle-btn.btn-open .chevron { transform: rotate(180deg); }
.btn-outline-danger { background: #fff; border: 1px solid var(--red); color: var(--red); }
.btn-outline-danger:hover { background: var(--red-bg); }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 0.9rem; margin-bottom: 14px; }
.alert-danger { background: var(--red-bg); color: var(--red); }
.alert-success { background: var(--green-bg); color: var(--green); }

/* ---- Query table ---- */
.table-wrap { overflow-x: auto; }
.query-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 0.88rem; }
.query-table th {
    text-align: left;
    padding: 10px 12px;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.query-table td {
    padding: 10px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.query-cell { max-width: 320px; }

/* Fixed column proportions for the queries table (prevents the "Update"
   panel's wider content from reflowing every other column when expanded).
   Every column uses a fixed pixel width rather than a percentage - a
   percentage still recalculates (and visually "squeezes") as the viewport
   narrows before its min-width floor is hit. Fixed pixels mean the table's
   total width never changes at all; .table-wrap's scrollbar simply appears
   the moment the viewport is narrower than that fixed total. */
#queries-table { width: 1300px; }
#queries-table th:nth-child(1)  { width: 105px; } /* Date */
#queries-table th:nth-child(2)  { width: 80px; }  /* Kind */
#queries-table th:nth-child(3)  { width: 80px; }  /* Type */
#queries-table th:nth-child(4)  { width: 80px; }  /* Phone */
#queries-table th:nth-child(5)  { width: 250px; } /* Query */
#queries-table th:nth-child(6)  { width: 115px; } /* We do it? */
#queries-table th:nth-child(7)  { width: 90px; }  /* Likelihood */
#queries-table th:nth-child(8)  { width: 115px; } /* Expected */
#queries-table th:nth-child(9)  { width: 90px; }  /* Ticket # */
#queries-table th:nth-child(10) { width: 90px; }  /* Status */
#queries-table th:nth-child(11) { width: 105px; } /* Logged by */
#queries-table th:nth-child(12) { width: 100px; } /* Update button */

#queries-table td:nth-child(4), #queries-table th:nth-child(4) { padding-right: 20px; }  /* extra gap before Query */
#queries-table td:nth-child(7), #queries-table th:nth-child(7) { padding-right: 20px; }  /* extra gap before Expected */

/* Fixed column widths for the leads table - matches the queries table's
   total width (1300px) since both appear on the same page */
#leads-table { width: 1300px; }
#leads-table th:nth-child(1) { width: 100px; } /* Date */
#leads-table th:nth-child(2) { width: 80px; }  /* Type */
#leads-table th:nth-child(3) { width: 230px; } /* Customer name */
#leads-table th:nth-child(4) { width: 155px; } /* Home/Business */
#leads-table th:nth-child(5) { width: 455px; } /* Query */
#leads-table th:nth-child(6) { width: 90px; }  /* Ticket # */
#leads-table th:nth-child(7) { width: 90px; }  /* Status */
#leads-table th:nth-child(8) { width: 100px; } /* Update button */

/* Fixed column widths for the staff accounts table */
#staff-table { width: 850px; }
#staff-table th:nth-child(1) { width: 220px; } /* Username (+ last login meta) */
#staff-table th:nth-child(2) { width: 85px; }  /* Role */
#staff-table th:nth-child(3) { width: 85px; }  /* 2FA */
#staff-table th:nth-child(4) { width: 100px; } /* Created */
#staff-table th:nth-child(5) { width: 360px; } /* Actions */
.nowrap { white-space: nowrap; }

/* Row accent: left border stripe by whether we offer the service,
   or blue for queries about an already-booked-in job */
.row-offer-yes { border-left: 4px solid var(--green); }
.row-offer-no { border-left: 4px solid var(--slate); }
.row-offer-unknown { border-left: 4px solid var(--amber); }
.row-kind-existing { border-left: 4px solid var(--blue); }
.row-offer-yes td:first-child, .row-offer-no td:first-child, .row-offer-unknown td:first-child, .row-kind-existing td:first-child { padding-left: 10px; }

.kind-badge {
    display: inline-block;
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 0.78rem;
    font-weight: 600;
}
.kind-new { background: var(--slate-bg); color: var(--slate); }
.kind-existing { background: var(--blue-bg); color: var(--blue-dark); }
.kind-chasing-up { background: var(--amber-bg); color: var(--amber); }
.kind-complaint { background: var(--red-bg); color: var(--red); }
.kind-other { background: var(--blue-bg); color: var(--blue-dark); }

.type-badge {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    display: inline-block;
}

.offer-pill {
    display: inline-block;
    border-radius: 999px;
    padding: 3px 12px;
    font-size: 0.8rem;
    font-weight: 600;
}
.offer-pill.row-offer-yes { background: var(--green-bg); color: var(--green); }
.offer-pill.row-offer-no { background: var(--slate-bg); color: var(--slate); }
.offer-pill.row-offer-unknown { background: var(--amber-bg); color: var(--amber); }

.status-pill {
    display: inline-block;
    border-radius: 999px;
    padding: 3px 12px;
    font-size: 0.8rem;
    font-weight: 600;
}
.status-open { background: var(--amber-bg); color: var(--amber); }
.status-won { background: var(--green-bg); color: var(--green); }
.status-lost { background: var(--red-bg); color: var(--red); }
.status-na { background: var(--slate-bg); color: var(--slate); }

.lead-status-open { background: var(--amber-bg); color: var(--amber); }
.lead-status-contacted { background: var(--blue-bg); color: var(--blue-dark); }
.lead-status-quoted { background: var(--teal-light); color: var(--teal-dark); }
.lead-status-follow_up { background: var(--purple-bg); color: var(--purple-dark); }
.lead-status-no_response { background: var(--slate-bg); color: var(--slate); }
.lead-status-won { background: var(--green-bg); color: var(--green); }
.lead-status-lost { background: var(--red-bg); color: var(--red); }

.user-type-badge {
    display: inline-block;
    border-radius: 999px;
    padding: 3px 12px;
    font-size: 0.8rem;
    font-weight: 600;
}
.user-type-home { background: var(--teal-light); color: var(--teal-dark); }
.user-type-business { background: var(--purple-bg); color: var(--purple-dark); }

.truncated-text {
    cursor: help;
    border-bottom: 1px dotted var(--text-muted);
}

/* Likelihood dots — teal intensity, deliberately separate hue from
   the offer/status colours so the two kinds of meaning never blur */
.dots { display: inline-flex; gap: 3px; align-items: center; }
.dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--border);
    display: inline-block;
}
.dot-filled { background: var(--teal); }

.empty-state { color: var(--text-muted); font-size: 0.92rem; }

/* Inline update row */
.edit-row { display: none; background: var(--slate-bg); }
.edit-row.open { display: table-row; }
.inline-update-form { display: flex; gap: 20px; align-items: flex-end; flex-wrap: wrap; padding: 6px 0; }
.inline-update-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
.inline-update-form .field-group { display: flex; flex-direction: column; gap: 4px; }
.inline-update-form .field-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
.inline-update-form input, .inline-update-form select { min-width: 160px; }
.inline-update-form.full-edit { align-items: flex-start; padding: 12px 0; }
.inline-update-form.full-edit .full-width { flex: 1 1 100%; }
.inline-update-form.full-edit textarea { min-width: 240px; width: 100%; }
.inline-update-form .radio-group { flex-direction: row; }
.full-edit-actions { justify-content: flex-end; }
.inline-delete-form { margin-top: 10px; padding-top: 10px; border-top: 0.5px solid var(--border); }

/* ---- Login / setup pages ---- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(160deg, var(--teal-dark), var(--teal) 60%, #14867D);
}
.login-card {
    background: var(--surface);
    border-radius: 14px;
    box-shadow: 0 20px 50px rgba(11, 90, 84, 0.35);
    padding: 36px 34px;
    width: 100%;
    max-width: 380px;
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.login-brand-mark { width: 14px; height: 14px; border-radius: 4px; background: var(--teal); }
.login-brand h1 { font-size: 1.3rem; }
.login-sub { color: var(--text-muted); font-size: 0.9rem; margin: 0 0 20px; }
.login-form { display: flex; flex-direction: column; gap: 4px; }
.login-form label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-top: 10px; }
.login-form button { margin-top: 18px; }

.password-hint { font-size: 0.78rem; color: var(--text-muted); margin: 4px 0 0; }
.password-hint.full-width { flex: 1 1 100%; }
.checkbox-label { display: flex !important; flex-direction: row !important; align-items: center; gap: 8px; margin-top: 14px !important; font-weight: 500 !important; color: var(--text) !important; }
.checkbox-label input { width: auto; }

.qr-wrap { display: flex; justify-content: center; margin: 18px 0; }
.setup-2fa-intro { color: var(--text-muted); font-size: 0.92rem; }
.setup-2fa-manual { text-align: center; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 18px; }
.setup-2fa-manual code {
    background: var(--slate-bg);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.9rem;
    letter-spacing: 0.03em;
    display: inline-block;
    margin-top: 6px;
}

.account-section { border-top: 0.5px solid var(--border); padding-top: 18px; margin-top: 18px; }
.account-section h3 { font-size: 0.95rem; margin: 0 0 10px; }
.account-help-text { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 12px; }

.account-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 3px; }

.backup-notes { margin: 0 0 20px; padding-left: 20px; font-size: 0.85rem; color: var(--text-muted); }
.backup-notes li { margin-bottom: 8px; }
.backup-notes code { background: var(--slate-bg); padding: 2px 6px; border-radius: 4px; }

.audit-details summary {
    cursor: pointer;
    color: var(--teal-dark);
    font-size: 0.85rem;
    font-weight: 600;
}
.audit-details dl {
    margin: 10px 0 0;
    font-size: 0.85rem;
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 4px 10px;
}
.audit-details dt { color: var(--text-muted); font-weight: 600; }
.audit-details dd { margin: 0; word-break: break-word; }

.reset-password-details summary { list-style: none; }
.reset-password-details summary::-webkit-details-marker { display: none; }
.reset-password-details summary::marker { display: none; content: ''; }
.reset-password-details[open] summary { margin-bottom: 4px; }

/* ---- Responsive ---- */
@media (max-width: 720px) {
    .stats-bar { grid-template-columns: repeat(2, 1fr); }
    .stat-existing, .stat-attention { grid-column: span 2; }
    .page { padding: 16px; }

    .menu-toggle { display: block; }
    .topbar-nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
        background: var(--teal-dark);
        padding: 18px 28px;
        z-index: 20;
        box-shadow: 0 8px 16px rgba(0,0,0,0.15);
    }
    .topbar-nav.open { display: flex; }
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
