/* ============================================================================
   PlexCrm — design system
   Light theme: white surfaces + blue accent.  Dark theme: black + red accent.
   ============================================================================ */

:root,
[data-theme="light"] {
    --bg: #f4f7fc;
    --surface: #ffffff;
    --surface-2: #eef2f9;
    --surface-3: #e6ecf6;
    --text: #0f172a;
    --text-2: #334155;
    --muted: #64748b;
    --border: #e2e8f0;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-weak: #dbeafe;
    --accent-contrast: #ffffff;
    --danger: #dc2626;
    --danger-weak: #fee2e2;
    --success: #16a34a;
    --success-weak: #dcfce7;
    --warning: #f59e0b;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 6px 20px rgba(15, 23, 42, .08);
    --shadow-lg: 0 18px 50px rgba(15, 23, 42, .18);
    --radius: 14px;
    --radius-sm: 9px;
}

[data-theme="dark"] {
    --bg: #08080a;
    --surface: #131316;
    --surface-2: #1b1b1f;
    --surface-3: #232328;
    --text: #f5f5f7;
    --text-2: #d4d4d8;
    --muted: #9b9ba3;
    --border: #2a2a30;
    --accent: #ef4444;
    --accent-hover: #dc2626;
    --accent-weak: #3a1517;
    --accent-contrast: #ffffff;
    --danger: #f87171;
    --danger-weak: #3a1517;
    --success: #4ade80;
    --success-weak: #14321f;
    --warning: #fbbf24;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 8px 24px rgba(0, 0, 0, .5);
    --shadow-lg: 0 20px 55px rgba(0, 0, 0, .65);
    --radius: 14px;
    --radius-sm: 9px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.6rem; margin: 0 0 .15rem; letter-spacing: -.02em; }
h2 { font-size: 1.15rem; margin: 0; letter-spacing: -.01em; }
h3 { font-size: 1rem; margin: 0 0 .6rem; }
h4 { font-size: .9rem; margin: 0 0 .4rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8em; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.strike { text-decoration: line-through; color: var(--muted); }

/* ---- layout ------------------------------------------------------------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.app-main { flex: 1; }
.app-container { max-width: 1180px; margin: 0 auto; padding: 1.4rem 1rem 4rem; }

.page-head {
    display: flex; flex-wrap: wrap; gap: 1rem;
    align-items: flex-end; justify-content: space-between;
    margin-bottom: 1.25rem;
}
.page-head-actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

/* ---- top navigation ----------------------------------------------------- */
.topnav {
    position: sticky; top: 0; z-index: 50;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.topnav-inner {
    max-width: 1180px; margin: 0 auto;
    display: flex; align-items: center; gap: 1rem;
    padding: .55rem 1rem;
}
.brand { display: inline-flex; align-items: center; gap: .5rem; font-size: 1.15rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); font-size: 1.2rem; }
.brand-name strong { color: var(--accent); }
.brand-lg { font-size: 1.8rem; }

.nav-toggle {
    margin-left: auto; display: inline-flex; flex-direction: column; gap: 4px;
    background: none; border: 0; cursor: pointer; padding: .4rem;
}
.nav-toggle span { width: 22px; height: 2px; background: var(--text); border-radius: 2px; }

.nav-links { display: none; flex-direction: column; gap: .2rem; }
.nav-links.open {
    display: flex; position: absolute; top: 100%; left: 0; right: 0;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: .6rem 1rem; box-shadow: var(--shadow);
}
.nav-link {
    color: var(--text-2); padding: .55rem .7rem; border-radius: var(--radius-sm);
    font-weight: 500; font-size: .92rem;
}
.nav-link:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav-link.active { background: var(--accent-weak); color: var(--accent); }
.nav-link-admin { color: var(--accent); }

.nav-actions { display: flex; align-items: center; gap: .5rem; margin-left: auto; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
    border: 1px solid transparent; background: transparent; color: var(--text-2);
    font-size: .95rem; line-height: 1; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.icon-btn.danger:hover { background: var(--danger-weak); color: var(--danger); }
.theme-toggle { border-color: var(--border); }

.user-menu { position: relative; }
.user-chip {
    display: inline-flex; align-items: center; gap: .5rem; cursor: pointer;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 999px; padding: .25rem .65rem .25rem .3rem; color: var(--text);
}
.user-name { font-size: .85rem; font-weight: 500; }
.user-dropdown {
    position: absolute; right: 0; top: calc(100% + .4rem); min-width: 180px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: .4rem; z-index: 60;
}
.user-dropdown-head { padding: .4rem .6rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem; }
.dropdown-item {
    width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
    padding: .5rem .6rem; border-radius: 7px; color: var(--text); font-size: .9rem;
}
.dropdown-item:hover { background: var(--surface-2); }
.logout-form { margin: 0; }

@media (min-width: 880px) {
    .nav-toggle { display: none; }
    .nav-links { display: flex; flex-direction: row; align-items: center; gap: .15rem; position: static; }
    .nav-actions { margin-left: 0; }
    .brand { margin-right: .5rem; }
}

/* ---- avatars ------------------------------------------------------------ */
.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--accent); color: var(--accent-contrast);
    font-weight: 600; font-size: .85rem; flex: none;
}
.avatar-sm { width: 28px; height: 28px; font-size: .72rem; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.4rem; }

/* ---- buttons ------------------------------------------------------------ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    padding: .55rem .95rem; border-radius: var(--radius-sm); font-size: .9rem;
    font-weight: 600; cursor: pointer; transition: .12s ease; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost.danger { color: var(--danger); }
.btn-sm { padding: .35rem .6rem; font-size: .8rem; }
.btn-block { width: 100%; margin-top: .4rem; }

/* ---- forms -------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .8rem; }
.field.grow { flex: 1; }
.field label, .field > label { font-size: .82rem; font-weight: 600; color: var(--text-2); }
.form-row { display: flex; gap: .8rem; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 150px; }
.field-btn { justify-content: flex-end; }

.input, select.input, textarea.input {
    width: 100%; background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: .55rem .7rem; font-size: .9rem; font-family: inherit; transition: .12s ease;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
textarea.input { resize: vertical; }
.input-sm { padding: .3rem .5rem; font-size: .8rem; }
.input-color { height: 42px; padding: .2rem; cursor: pointer; }

.checkbox { display: inline-flex; align-items: center; gap: .45rem; font-size: .88rem; cursor: pointer; color: var(--text-2); }
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); }

.validation-message { color: var(--danger); font-size: .8rem; }

/* ---- cards & sections --------------------------------------------------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow-sm);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .8rem; }
.section-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 820px) { .section-grid { grid-template-columns: 340px 1fr; align-items: start; } }
.add-card { position: sticky; top: 70px; }

/* ---- stats & dashboard -------------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .8rem; margin-bottom: 1.2rem; }
@media (min-width: 720px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem; display: flex; flex-direction: column; gap: .2rem; box-shadow: var(--shadow-sm);
}
.stat-value { font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; }
.stat-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.dash-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 900px) { .dash-grid { grid-template-columns: repeat(3, 1fr); } }

.lined-list { list-style: none; margin: 0; padding: 0; }
.lined-list li {
    display: flex; align-items: center; justify-content: space-between; gap: .6rem;
    padding: .6rem 0; border-bottom: 1px solid var(--border);
}
.lined-list li:last-child { border-bottom: 0; }
.empty { padding: .6rem 0; }

.pill {
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
    border-radius: 999px; padding: .15rem .6rem; font-size: .76rem; font-weight: 600; white-space: nowrap;
}
.pill-danger { background: var(--danger-weak); color: var(--danger); border-color: transparent; }

/* ---- tables ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; padding: 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.data-table thead th {
    text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted); padding: .75rem .9rem; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table tbody td { padding: .7rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: var(--surface-2); }
.cell-name { display: flex; align-items: center; gap: .55rem; font-weight: 600; }
.col-actions { text-align: right; white-space: nowrap; }
.row-actions { display: inline-flex; gap: .3rem; }

/* ---- badges / categories ------------------------------------------------ */
.badge {
    display: inline-block; padding: .15rem .55rem; border-radius: 999px;
    font-size: .74rem; font-weight: 600; background: var(--surface-2); color: var(--text-2);
}
.cat-family { background: #fce7f3; color: #be185d; }
.cat-friend { background: #dbeafe; color: #1d4ed8; }
.cat-work { background: #e0e7ff; color: #4338ca; }
.cat-neighbor { background: #dcfce7; color: #15803d; }
.cat-online { background: #fae8ff; color: #a21caf; }
.cat-other { background: var(--surface-2); color: var(--text-2); }
.status-active { background: var(--success-weak); color: var(--success); }
.status-onhold { background: #fef3c7; color: #b45309; }
.status-completed { background: var(--accent-weak); color: var(--accent); }
.status-archived { background: var(--surface-2); color: var(--muted); }
.status-todo { background: var(--surface-2); color: var(--text-2); }
.status-inprogress { background: var(--accent-weak); color: var(--accent); }
.status-blocked { background: var(--danger-weak); color: var(--danger); }
.status-done { background: var(--success-weak); color: var(--success); }
[data-theme="dark"] .cat-family,[data-theme="dark"] .cat-friend,[data-theme="dark"] .cat-work,
[data-theme="dark"] .cat-neighbor,[data-theme="dark"] .cat-online,[data-theme="dark"] .status-onhold {
    background: var(--surface-3); color: var(--text-2);
}

/* ---- chips -------------------------------------------------------------- */
.chip {
    --chip: var(--accent);
    display: inline-flex; align-items: center; gap: .3rem;
    background: color-mix(in srgb, var(--chip) 16%, transparent);
    color: var(--chip); border: 1px solid color-mix(in srgb, var(--chip) 35%, transparent);
    border-radius: 999px; padding: .12rem .55rem; font-size: .76rem; font-weight: 600; margin: 0 .25rem .25rem 0;
}
.chip-x { background: none; border: 0; color: inherit; cursor: pointer; font-size: .9rem; line-height: 1; padding: 0; }
.chip-row { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .8rem; }

/* ---- contact detail ----------------------------------------------------- */
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.detail-head-main { display: flex; align-items: center; gap: 1rem; }
.detail-sub { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .3rem; }
.detail-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .8rem; margin-bottom: .8rem; }
.detail-meta > div { display: flex; flex-direction: column; }
.meta-k { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.meta-v { font-weight: 500; }
.detail-summary { background: var(--surface-2); border-radius: var(--radius-sm); padding: .8rem 1rem; margin: 0 0 1rem; }

.tabs { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tab {
    background: none; border: 0; border-bottom: 2px solid transparent; cursor: pointer;
    padding: .55rem .8rem; font-weight: 600; font-size: .88rem; color: var(--muted);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: .7rem; padding: .2rem 0; position: relative; }
.timeline-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-top: .45rem; flex: none; }
.timeline-content { flex: 1; border-bottom: 1px solid var(--border); padding-bottom: .7rem; margin-bottom: .3rem; }
.timeline-row { display: flex; justify-content: space-between; gap: .5rem; }
.note-list { list-style: none; margin: 0; padding: 0; }
.note-list li { border-bottom: 1px solid var(--border); padding: .6rem 0; position: relative; }
.note-meta { margin-bottom: .2rem; }
.note-list .icon-btn, .timeline .icon-btn { position: absolute; right: 0; top: .4rem; }
.custom-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem; margin-bottom: .8rem; }
.add-tag { align-items: flex-end; }

/* ---- projects ----------------------------------------------------------- */
.project-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 700px) { .project-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .project-grid { grid-template-columns: repeat(3, 1fr); } }
.project-card { cursor: pointer; transition: .12s ease; }
.project-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.project-card-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.project-card-head h3 { margin: 0; flex: 1; }
.project-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--dot, var(--accent)); flex: none; }
.project-stats { display: flex; justify-content: space-between; font-size: .82rem; color: var(--muted); margin-top: .5rem; }
.progress { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress-lg { height: 12px; margin-bottom: 1.2rem; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s ease; }
.tasks-table tr.running { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.tracked-live { color: var(--accent); font-weight: 700; }
.add-task .form-row { align-items: flex-end; }

/* ---- admin -------------------------------------------------------------- */
.admin-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 640px) { .admin-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .admin-grid { grid-template-columns: repeat(4, 1fr); } }
.admin-tile { text-align: center; color: var(--text); transition: .12s ease; }
.admin-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); text-decoration: none; }
.admin-tile-icon { font-size: 1.8rem; display: block; margin-bottom: .4rem; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .5rem; }
.claim-group { border-top: 1px solid var(--border); padding: .7rem 0; }
.claim-group:first-child { border-top: 0; }
.claim-row { align-items: flex-start; margin-bottom: .4rem; }
.claim-code { display: inline-block; background: var(--surface-2); border-radius: 5px; padding: 0 .35rem; margin-left: .35rem; color: var(--muted); }
.kv { font-size: .82rem; }
.toggle {
    border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
    border-radius: 999px; padding: .15rem .6rem; font-size: .76rem; font-weight: 600; cursor: pointer;
}
.toggle.on { background: var(--success-weak); color: var(--success); border-color: transparent; }

/* ---- modal -------------------------------------------------------------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(8, 8, 12, .55);
    display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 100;
}
.modal-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); width: 100%; max-height: 90vh; overflow: auto;
}
.modal-sm { max-width: 420px; }
.modal-md { max-width: 560px; }
.modal-lg { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 1.05rem; }
.modal-body { padding: 1.2rem; }
.modal-foot, .modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: .6rem; }

/* ---- alerts / states ---------------------------------------------------- */
.alert { padding: .7rem .9rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .88rem; }
.alert-danger { background: var(--danger-weak); color: var(--danger); }
.alert-success { background: var(--success-weak); color: var(--success); }

.state-panel { text-align: center; padding: 4rem 1rem; color: var(--muted); }
.state-panel h1 { color: var(--text); }
.empty-state { text-align: center; padding: 3rem 1rem; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

.spinner {
    display: inline-block; width: 18px; height: 18px; vertical-align: -3px;
    border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- auth (login) ------------------------------------------------------- */
.auth-shell { min-height: 100vh; background: var(--bg); }
.auth-grid { min-height: 100vh; display: grid; grid-template-columns: 1fr; }
@media (min-width: 880px) { .auth-grid { grid-template-columns: 1.05fr .95fr; } }
.auth-aside {
    display: none; color: #fff;
    background: linear-gradient(150deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #000));
    padding: 3rem;
}
@media (min-width: 880px) { .auth-aside { display: flex; align-items: center; } }
.auth-aside-inner { max-width: 420px; }
.auth-aside .brand-name, .auth-aside .brand-name strong, .auth-aside .brand-mark { color: #fff; }
.auth-tagline { font-size: 1.8rem; line-height: 1.25; margin: 1.4rem 0 1.6rem; font-weight: 700; letter-spacing: -.02em; }
.auth-features { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .7rem; }
.auth-features li { display: flex; gap: .6rem; align-items: center; opacity: .95; }
.auth-features span { background: rgba(255, 255, 255, .25); border-radius: 50%; width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; font-size: .75rem; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 2rem 1.2rem; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { margin-bottom: .2rem; }
.auth-foot { margin-top: 1.2rem; text-align: center; }

/* ---- blazor error ui ---------------------------------------------------- */
#blazor-error-ui {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
    background: var(--warning); color: #1f2937; padding: .7rem 1.2rem; box-shadow: var(--shadow-lg);
}
#blazor-error-ui .reload { color: #1f2937; text-decoration: underline; margin-left: .4rem; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 1rem; top: .6rem; }
