/* ============================================================
   Lynkr CRM — application UI
   Palette + font carried over from the original project.
   Dark by default; [data-theme="light"] overrides.
   ============================================================ */
:root {
    --bg: #040F16;
    --surface: #071822;
    --surface-2: #0a2330;
    --surface-3: #0d3347;
    --surface-hover: #0b2a3b;
    --border: rgba(143, 199, 230, 0.16);
    --border-strong: rgba(143, 199, 230, 0.26);
    --text: #FFF9EC;
    --title: #FAFAFA;
    --muted: rgba(255, 249, 236, 0.55);
    --primary: #135075;
    --primary-hover: #196a9c;
    --primary-ink: #FFF9EC;
    --link: #2f86bd;
    --link-hover: #4aa3d6;
    --danger: #ff9b86;
    --shadow: 0 18px 50px rgba(0, 0, 0, .28), 0 1px 0 rgba(255, 255, 255, .03) inset;
    --radius: 8px;
    --font: "Urbanist", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
[data-theme="light"] {
    --bg: #f7f9fb;
    --surface: #ffffff;
    --surface-2: #f1f5f8;
    --surface-3: #e6eef3;
    --surface-hover: #edf4f8;
    --border: rgba(19, 80, 117, 0.14);
    --border-strong: rgba(19, 80, 117, 0.24);
    --text: #0d2630;
    --title: #04141d;
    --muted: #5a6b75;
    --primary: #135075;
    --primary-hover: #196a9c;
    --primary-ink: #ffffff;
    --link: #135075;
    --link-hover: #196a9c;
    --danger: #b4452f;
    --shadow: 0 18px 45px rgba(9, 39, 57, .08), 0 1px 0 rgba(255, 255, 255, .9) inset;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
    background:
        linear-gradient(180deg, rgba(19, 80, 117, .16) 0, rgba(19, 80, 117, 0) 260px),
        var(--bg);
    background-repeat: no-repeat;
    background-size: 100% 100vh;
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    margin: 0;
    min-height: 100vh;
    min-width: 320px;
}
h1, h2, h3, h4 { font-family: var(--font); color: var(--title); font-weight: 700; line-height: 1.18; letter-spacing: 0; }
h1 { font-size: 1.8rem; margin: 0 0 .45rem; }
h3 { font-size: 1.05rem; }
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; gap: .4rem;
    min-height: 36px;
    padding: .55rem .9rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,0)), var(--surface-2);
    color: var(--text);
    font: inherit; font-size: .92rem; font-weight: 650;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}
.btn:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text); transform: translateY(-1px); }
.btn--primary { background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,0)), var(--primary); border-color: rgba(74, 163, 214, .35); color: var(--primary-ink); }
.btn--primary:hover { background: linear-gradient(180deg, rgba(255,255,255,.1), rgba(255,255,255,0)), var(--primary-hover); border-color: rgba(74, 163, 214, .55); color: #fff; }
.btn--ghost { background: transparent; }
.btn--ghost:hover { background: var(--surface-hover); }
.btn--block { width: 100%; justify-content: center; }
.btn--sm { min-height: 30px; padding: .35rem .65rem; font-size: .82rem; }
.btn--danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn--danger:hover { background: rgba(255, 155, 134, .12); color: var(--danger); }
.icon-btn { background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: var(--radius); width: 36px; height: 36px; cursor: pointer; }
.icon-btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.inline-form { display: inline; margin: 0; }

/* ---- Inputs ---- */
input, select, textarea { font: inherit; }
input:not([type]), input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="tel"], input[type="date"], select, textarea {
    width: 100%;
    min-height: 38px;
    padding: .55rem .7rem;
    background: color-mix(in srgb, var(--surface-2) 86%, var(--bg));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
textarea { resize: none; overflow: hidden; }
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus { outline: none; background: var(--surface); border-color: rgba(74, 163, 214, .7); box-shadow: 0 0 0 3px rgba(25, 106, 156, .22); }
::placeholder { color: var(--muted); }

/* ---- Auth screens ---- */
.auth-shell { min-height: 85vh; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.auth-card { background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.25rem; width: 100%; max-width: 420px; box-shadow: var(--shadow); backdrop-filter: blur(16px); }
.auth-card--wide { max-width: 560px; }
.auth-card h1 { margin: 0 0 .5rem; }
.auth-card label { display: block; margin: 1.1rem 0 .25rem; font-size: .9rem; color: var(--muted); }
.auth-card .btn { margin-top: 1.25rem; }
.auth-actions { display: flex; gap: .75rem; margin-top: 1.5rem; }

/* ---- Generic form layout ---- */
label { display: block; margin: .8rem 0 .3rem; font-size: .82rem; font-weight: 650; color: var(--muted); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem; }
.form-error { background: rgba(255,155,134,.12); color: var(--danger); border: 1px solid rgba(255,155,134,.35); padding: .7rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; }
.form-notice { background: rgba(82, 196, 140, .12); color: #7fe6b0; border: 1px solid rgba(82,196,140,.35); padding: .7rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; }

/* ---- App shell (full width) ---- */
.app-nav { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1.25rem; padding: .65rem 2rem; background: color-mix(in srgb, var(--surface) 90%, transparent); border-bottom: 1px solid var(--border); backdrop-filter: blur(18px); }
.app-nav__brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.05rem; color: var(--title); }
.app-nav__brand img { height: 28px; }
.app-nav__links { display: flex; gap: .25rem; align-items: center; }
.app-nav__links a { color: var(--muted); font-size: .9rem; font-weight: 650; padding: .42rem .65rem; border-radius: var(--radius); }
.app-nav__links a:hover { color: var(--text); background: var(--surface-hover); }
.app-nav__right { margin-left: auto; display: flex; align-items: center; gap: .7rem; }
.app-nav__user { display: flex; flex-direction: column; line-height: 1.15; font-size: .9rem; text-align: right; }
.app-nav__user small { color: var(--muted); font-size: .75rem; }

.app-main { width: 100%; margin: 0; padding: 1.6rem 2rem 2.5rem; }
.app-main--narrow { max-width: 1040px; margin-left: auto; margin-right: auto; }
.app-main--form { max-width: 640px; margin-left: auto; margin-right: auto; }

.card { background: color-mix(in srgb, var(--surface) 94%, var(--bg)); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.15rem; box-shadow: 0 1px 0 rgba(255,255,255,.025) inset; }
.card h3 { margin: 0 0 1rem; }
.card .btn { margin-top: 1rem; }
.card textarea, .app-main textarea { width: 100%; padding: .55rem .7rem; background: color-mix(in srgb, var(--surface-2) 86%, var(--bg)); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); }
.soon { display: inline-block; margin-top: .5rem; font-size: .75rem; color: var(--muted); border: 1px dashed var(--border); padding: .15rem .55rem; border-radius: 8px; }

/* ---- Section header ---- */
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.15rem; }
.section-head h1, .section-head h3 { margin: 0; }

/* ---- Pills / banners ---- */
.pill { display: inline-flex; align-items: center; min-height: 22px; padding: .08rem .5rem; border-radius: 999px; font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 800; background: var(--surface-2); border: 1px solid var(--border-strong); }
.pill--status { color: #8fc7e6; }
.pill--trialing { color: #8fd0ff; }
.pill--active { color: #7fe6b0; }
.pill--past_due, .pill--suspended { color: var(--danger); }
.pill--cancelled, .pill--invited { color: var(--muted); }
.banner { padding: .7rem 2rem; font-size: .9rem; }
.banner--warn { background: #3a2a12; color: #ffd9a0; }

/* ---- Dashboard stats ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; }
.stat { display: flex; flex-direction: column; gap: .25rem; padding: 1rem 1.05rem; background: color-mix(in srgb, var(--surface) 94%, var(--bg)); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); transition: background .15s ease, border-color .15s ease, transform .15s ease; }
.stat:hover { background: var(--surface-hover); border-color: rgba(74, 163, 214, .42); color: var(--text); transform: translateY(-1px); }
.stat__num { font-size: 1.85rem; font-weight: 800; color: var(--title); line-height: 1; }
.stat__label { color: var(--muted); font-size: .85rem; }
.stat--accent .stat__num { color: var(--link-hover); }

/* ---- Tables ---- */
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; background: color-mix(in srgb, var(--surface) 94%, var(--bg)); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.data-table th, .data-table td { text-align: left; padding: .68rem .85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table thead th { background: color-mix(in srgb, var(--surface-2) 90%, var(--bg)); font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 800; }
.data-table thead th a { color: var(--muted); }
.data-table thead th a:hover { color: var(--text); }
.data-table tr:last-child td { border-bottom: none; }
.data-table select { padding: .35rem .5rem; }
/* Lay actions out horizontally WITHOUT making the <td> a flex container —
   display:flex on a table cell breaks row height/vertical-align and throws the
   border lines out. Keep the cell a normal cell; align the controls inside it. */
.row-actions { white-space: nowrap; }
.row-actions > * { vertical-align: middle; }
.row-actions > * + * { margin-left: .4rem; }
.row-actions .inline-form { display: inline-flex; align-items: center; }

/* Dashboard: two equal columns side by side; stacks on narrow screens. */
.dash-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 1.5rem; align-items: start; }
@media (max-width: 820px) { .dash-cols { grid-template-columns: 1fr; } }

/* Dashboard to-do rows with inline complete / reschedule / delete. */
.todo-item { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.todo-item:last-child { border-bottom: 0; }
.todo-item__desc { flex: 1; min-width: 140px; }
.todo-item__date { display: inline-flex; align-items: center; gap: .35rem; }
.todo-item__date input[type="date"] { padding: .3rem .5rem; }
.row-link { cursor: pointer; }
.row-link td a { color: var(--text); font-weight: 600; }
.row-link:hover { background: var(--surface-hover); }
.row-link td a:hover { color: var(--link-hover); }

/* ---- Section header actions ---- */
.section-head__actions { display: flex; gap: .6rem; align-items: center; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 1.25rem; height: 1.25rem; padding: 0 .35rem; border-radius: 999px; background: var(--primary); color: #fff; font-size: .72rem; font-weight: 700; }

/* ---- Filter panel (toggleable) ---- */
.filter-panel { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1rem; }
.filter-panel[hidden] { display: none; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .8rem; }
.fg { display: flex; flex-direction: column; gap: .35rem; }
.fg > label { margin: 0; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.fg--wide { grid-column: span 2; }
.fg--full { width: 100%; }
@media (max-width: 560px) { .fg--wide { grid-column: span 1; } }
.date-range { display: flex; align-items: center; gap: .5rem; }
.date-range span { color: var(--muted); font-size: .8rem; }
.filter-actions { display: flex; gap: .6rem; }
.filter-statuses, .owner-checks { display: flex; flex-wrap: wrap; gap: .5rem; }
.inline-check { display: flex; align-items: center; gap: .4rem; margin: 0; }
.chip { display: inline-flex; align-items: center; gap: .4rem; min-height: 30px; padding: .32rem .72rem; border: 1px solid var(--border); border-radius: 999px; background: color-mix(in srgb, var(--surface-2) 88%, var(--bg)); cursor: pointer; font-size: .82rem; margin: 0; color: var(--text); user-select: none; transition: background .15s ease, border-color .15s ease, color .15s ease; }
/* Hide the native checkbox square — the pill itself shows selected state. */
.chip input { position: absolute; opacity: 0; width: 0; height: 0; margin: 0; }
.chip:hover { border-color: rgba(74, 163, 214, .45); }
.chip:has(input:checked) { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---- Invite form ---- */
.invite-form { display: flex; gap: .7rem; flex-wrap: wrap; align-items: center; }
.invite-form input[type="email"], .invite-form select { width: auto; }
.invite-form input[type="email"] { flex: 1; min-width: 240px; }

/* ---- Pagination ---- */
.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 1.25rem; }
.pagination__btns { display: flex; align-items: center; gap: 1rem; }

/* ---- Contact detail: two-column app layout ---- */
.detail-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 1rem; align-items: start; }
.detail-layout .col-main, .detail-layout .col-side { display: flex; flex-direction: column; gap: 1rem; }
@media (max-width: 980px) { .detail-layout { grid-template-columns: 1fr; } }
/* legacy alias */
.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 980px) { .detail-grid { grid-template-columns: 1fr; } }

/* ---- Notes ---- */
.note-add textarea { width: 100%; }
.note-list { list-style: none; padding: 0; margin: 1.25rem 0 0; }
.note-list li { border-top: 1px solid var(--border); padding: .85rem 0; }
.note-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; }
.note-body { white-space: pre-wrap; margin: .35rem 0; }
.note-edit summary { cursor: pointer; color: var(--link); font-size: .85rem; }

a.app-nav__user { text-decoration: none; color: var(--text); }
a.app-nav__user:hover { opacity: .85; }

@media (max-width: 860px) {
    .app-nav { align-items: flex-start; flex-wrap: wrap; padding: .75rem 1rem; }
    .app-nav__links { order: 3; width: 100%; overflow-x: auto; padding-bottom: .1rem; scrollbar-width: none; }
    .app-nav__links::-webkit-scrollbar { display: none; }
    .app-nav__right { margin-left: auto; }
    .app-main { padding: 1.15rem 1rem 2rem; }
    .section-head { flex-direction: column; }
    .section-head__actions { width: 100%; flex-wrap: wrap; }
    .section-head__actions .btn { flex: 1; justify-content: center; }
    .data-table { display: block; overflow-x: auto; }
    .pagination { align-items: flex-start; flex-direction: column; gap: .8rem; }
}

/* Suburb autocomplete suggestions (G.5) */
.suburb-suggestions {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
    max-height: 220px;
    overflow-y: auto;
}
.suburb-suggestion {
    text-align: left;
    padding: .5rem .75rem;
    background: transparent;
    border: 0;
    color: var(--text);
    cursor: pointer;
    font: inherit;
}
.suburb-suggestion:hover {
    background: var(--primary);
    color: #fff;
}
