/* ============================================================
   Mini CRM — stylesheet
   Clean, modern, responsive. System fonts, no dependencies.
   ============================================================ */

:root {
    --bg:          #f4f5fb;
    --surface:     #ffffff;
    --border:      #e4e6f0;
    --ink:         #1c2030;
    --ink-soft:    #5b6178;
    --ink-faint:   #9298ad;
    --accent:      #4f46e5;
    --accent-soft: #eef0fe;
    --accent-ink:  #3730a3;
    --green:       #16a34a;
    --green-soft:  #ecfdf3;
    --red:         #dc2626;
    --red-soft:    #fef2f2;
    --amber-soft:  #fffbeb;
    --amber-ink:   #92400e;
    --radius:      12px;
    --shadow:      0 1px 2px rgb(28 32 48 / 4%), 0 4px 16px rgb(28 32 48 / 6%);
    --shadow-lift: 0 2px 4px rgb(28 32 48 / 6%), 0 10px 28px rgb(28 32 48 / 10%);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 15.5px;
    line-height: 1.55;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }

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

/* ---------- Top bar ---------- */

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-inner {
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 20px;
    height: 60px;
    display: flex;
    align-items: center;
    gap: 24px;
}

.brand {
    font-weight: 700;
    font-size: 17px;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); font-size: 14px; }

.nav { display: flex; gap: 4px; margin-left: 8px; }

.nav a {
    color: var(--ink-soft);
    font-weight: 500;
    font-size: 14.5px;
    padding: 7px 13px;
    border-radius: 8px;
    transition: background .15s ease, color .15s ease;
}
.nav a:hover { color: var(--ink); background: var(--accent-soft); text-decoration: none; }
.nav a.active { color: var(--accent-ink); background: var(--accent-soft); font-weight: 600; }

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logged-in-as {
    color: var(--ink-faint);
    font-size: 13.5px;
    white-space: nowrap;
}

.nav-toggle {
    display: none;
    margin-left: auto;
    font-size: 20px;
    background: none;
    border: none;
    color: var(--ink-soft);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
}
.nav-toggle:hover { background: var(--accent-soft); }

/* ---------- Page scaffolding ---------- */

.page {
    max-width: 1080px;
    width: 100%;
    margin: 0 auto;
    padding: 28px 20px 48px;
    flex: 1;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

.page-head h1 { font-size: 24px; }
.page-head .sub { color: var(--ink-soft); font-size: 14px; margin-top: 3px; }

.footer {
    text-align: center;
    color: var(--ink-faint);
    font-size: 12.5px;
    padding: 18px 20px 26px;
}

/* ---------- Cards & panels ---------- */

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

.panel { padding: 24px; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 22px;
    transition: transform .15s ease, box-shadow .15s ease;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }

.stat .stat-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-faint);
    text-transform: uppercase;
    letter-spacing: .05em;
}
.stat .stat-value {
    font-size: 30px;
    font-weight: 700;
    margin-top: 6px;
    letter-spacing: -0.02em;
}
.stat .stat-hint { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.stat-accent .stat-value { color: var(--accent); }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font: inherit;
    font-size: 14.5px;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: 1px solid transparent;
    border-radius: 9px;
    padding: 9px 16px;
    cursor: pointer;
    transition: background .15s ease, transform .05s ease, box-shadow .15s ease;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { background: #4338ca; text-decoration: none; box-shadow: var(--shadow-lift); }
.btn:active { transform: translateY(1px); }

.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

.btn-ghost {
    background: transparent;
    color: var(--ink-soft);
    border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--ink); box-shadow: none; }

.btn-danger {
    background: var(--red);
    color: #fff;
}
.btn-danger:hover { background: #b91c1c; }

.btn-outline-danger {
    background: var(--red-soft);
    color: var(--red);
    border-color: #fecaca;
}
.btn-outline-danger:hover { background: var(--red); color: #fff; border-color: var(--red); box-shadow: none; }

.btn-block { width: 100%; }

/* ---------- Forms ---------- */

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px 20px;
}
.form-grid .full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--ink-soft);
}
.field .required { color: var(--red); }

.field input,
.field textarea {
    font: inherit;
    color: var(--ink);
    background: #fcfcfe;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 10px 12px;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
    width: 100%;
}
.field textarea { resize: vertical; min-height: 110px; }

.field input:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
    box-shadow: 0 0 0 3px rgb(79 70 229 / 12%);
}

.field.invalid input,
.field.invalid textarea { border-color: var(--red); }

.field-error {
    color: var(--red);
    font-size: 13px;
    font-weight: 500;
}
.field-hint { color: var(--ink-faint); font-size: 12.5px; }

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

/* ---------- Search / toolbar ---------- */

.toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.toolbar .search-box {
    position: relative;
    flex: 1;
    min-width: 240px;
    max-width: 420px;
}
.toolbar .search-box input {
    font: inherit;
    width: 100%;
    padding: 9px 14px 9px 38px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--ink);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.toolbar .search-box input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgb(79 70 229 / 12%);
}
.toolbar .search-box::before {
    content: "⌕";
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-52%);
    color: var(--ink-faint);
    font-size: 17px;
    pointer-events: none;
}

.toolbar .count { color: var(--ink-soft); font-size: 13.5px; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; border-radius: var(--radius); }

table.data { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 14px; }

table.data th, table.data td {
    text-align: left;
    padding: 12px 13px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.data td.wrapped { white-space: normal; min-width: 220px; }

table.data thead th {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-faint);
    text-transform: uppercase;
    letter-spacing: .05em;
    background: #fafafe;
}

table.data tbody tr { transition: background .12s ease; }
table.data tbody tr:hover { background: #f8f8fe; }
table.data tbody tr:last-child td { border-bottom: none; }

table.data .cell-name { font-weight: 600; color: var(--ink); }
table.data .cell-muted { color: var(--ink-faint); }
table.data .cell-actions { text-align: right; }
table.data .cell-actions .btn { margin-left: 6px; }

table.data .cell-trunc {
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-ink);
}

/* On narrow screens drop the least-critical table columns so Actions stay reachable */
@media (max-width: 1080px) {
    table.data .col-added { display: none; }
}
@media (max-width: 980px) {
    table.data .col-phone { display: none; }
}

/* ---------- Empty state ---------- */

.empty-state {
    text-align: center;
    padding: 56px 24px;
    color: var(--ink-soft);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 10px; opacity: .55; }
.empty-state h3 { color: var(--ink); margin-bottom: 6px; }
.empty-state p { margin-bottom: 16px; }

/* ---------- Flash messages ---------- */

.flash {
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 14.5px;
    font-weight: 500;
    margin-bottom: 20px;
    border: 1px solid transparent;
    animation: slide-down .25s ease;
}
.flash-success { background: var(--green-soft); color: var(--green); border-color: #bbf7d0; }
.flash-error   { background: var(--red-soft);   color: var(--red);  border-color: #fecaca; }
.flash-info    { background: var(--amber-soft); color: var(--amber-ink); border-color: #fde68a; }

@keyframes slide-down {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Pagination ---------- */

.pagination {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: 18px;
    flex-wrap: wrap;
}
.pagination a, .pagination span {
    font-size: 13.5px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    color: var(--ink-soft);
    background: var(--surface);
}
.pagination a:hover { background: var(--accent-soft); color: var(--accent-ink); text-decoration: none; }
.pagination .current { background: var(--accent); border-color: var(--accent); color: #fff; }
.pagination .disabled { opacity: .45; pointer-events: none; }

/* ---------- Auth pages (login / setup) ---------- */

.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 20px;
    background:
        radial-gradient(700px 380px at 15% 0%, rgb(79 70 229 / 9%), transparent 60%),
        radial-gradient(700px 380px at 90% 100%, rgb(79 70 229 / 7%), transparent 60%),
        var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-lift);
    padding: 34px 30px;
}

.auth-card .auth-brand {
    text-align: center;
    font-weight: 700;
    font-size: 21px;
    margin-bottom: 4px;
}
.auth-card .auth-brand .brand-mark { font-size: 13px; margin-right: 6px; }
.auth-card .auth-sub {
    text-align: center;
    color: var(--ink-soft);
    font-size: 14px;
    margin-bottom: 24px;
}
.auth-card .auth-links {
    text-align: center;
    font-size: 13.5px;
    color: var(--ink-faint);
    margin-top: 18px;
}
.auth-card .auth-card-warn {
    background: var(--amber-soft);
    border: 1px solid #fde68a;
    color: var(--amber-ink);
    border-radius: 9px;
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 18px;
}

/* ---------- Detail page ---------- */

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.detail-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.detail-item .detail-label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-faint);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 4px;
}
.detail-item .detail-value { font-size: 15.5px; word-break: break-word; }
.detail-item .detail-value.na { color: var(--ink-faint); }

.notes-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
    .topbar-inner { padding: 0 14px; gap: 10px; }

    .nav {
        display: none;
        position: absolute;
        top: 60px;
        left: 0;
        right: 0;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        flex-direction: column;
        padding: 10px 14px;
        gap: 4px;
        box-shadow: var(--shadow-lift);
    }
    .nav.open { display: flex; }
    .nav a { padding: 11px 14px; border-radius: 8px; }

    .nav-toggle { display: block; }
    .logged-in-as { display: none; }

    .page { padding: 22px 14px 40px; }

    .form-grid { grid-template-columns: 1fr; }

    table.data th, table.data td { padding: 10px 12px; }
    table.data .cell-actions .btn { margin: 3px 0 3px 6px; }
}
