:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --text: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --bg: #f9fafb;
    --white: #ffffff;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 4px 14px rgba(0, 0, 0, .05);
}

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

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 1.25rem;
}

/* full-width variant (dashboard) */
.container-fluid {
    max-width: none;
    width: 100%;
    padding: 0 clamp(.75rem, 2vw, 2rem);
}

/* ---------- navigation ---------- */
.nav {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}

.brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text);
    text-decoration: none;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--primary);
    color: var(--white);
    font-weight: 700;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logout-form { display: inline; margin: 0; }

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: .95rem;
}

.nav-links a:hover { color: var(--text); }

.nav-login { color: var(--text) !important; }

/* ---------- hero (landing) ---------- */
.hero {
    text-align: center;
    padding: 5rem 1.25rem 4rem;
}

.hero h1 {
    font-size: clamp(2rem, 5vw, 3.2rem);
    font-weight: 800;
    letter-spacing: -.02em;
    line-height: 1.15;
    max-width: 44rem;
    margin: 0 auto 1.25rem;
}

.hero h1 span { color: var(--primary); }

.hero p.lead {
    font-size: clamp(1rem, 2vw, 1.2rem);
    color: var(--text-muted);
    max-width: 38rem;
    margin: 0 auto 2.25rem;
}

.hero-cta {
    display: flex;
    gap: .75rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ---------- features ---------- */
.features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
    padding-bottom: 4rem;
}

.feature {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.feature .icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    margin-bottom: .9rem;
}

.feature h3 {
    font-size: 1.05rem;
    margin-bottom: .35rem;
}

.feature p {
    color: var(--text-muted);
    font-size: .92rem;
}

/* ---------- auth pages ---------- */
.auth-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2.5rem 1.25rem;
}

.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2.25rem 2rem;
    width: 100%;
    max-width: 420px;
}

.card h2 {
    font-size: 1.5rem;
    text-align: center;
    margin-bottom: .35rem;
}

.card .sub {
    text-align: center;
    color: var(--text-muted);
    font-size: .95rem;
    margin-bottom: 1.75rem;
}

/* ---------- forms ---------- */
.form-field { margin-bottom: 1.1rem; }

.form-field label {
    display: block;
    font-size: .88rem;
    font-weight: 600;
    margin-bottom: .35rem;
}

.form-field input {
    width: 100%;
    padding: .65rem .8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--white);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}

.form-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

.form-hint {
    font-size: .8rem;
    color: var(--text-muted);
    margin-top: .3rem;
}

.form-actions { margin-top: 1.5rem; }

.form-actions .btn { width: 100%; }

.form-footer {
    margin-top: 1.5rem;
    text-align: center;
    font-size: .92rem;
    color: var(--text-muted);
}

.form-footer a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.form-footer a:hover { text-decoration: underline; }

.flash {
    padding: .75rem 1rem;
    border-radius: 8px;
    font-size: .92rem;
    margin-bottom: 1.25rem;
}

.flash-error {
    background: var(--error-bg);
    color: var(--error-text);
}

.flash-success {
    background: var(--success-bg);
    color: var(--success-text);
}

/* ---------- buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .6rem 1.2rem;
    border-radius: 8px;
    font-size: .95rem;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-outline {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}

.btn-outline:hover { background: var(--bg); }

.btn-lg {
    padding: .8rem 1.6rem;
    font-size: 1.02rem;
}

.btn-sm {
    padding: .35rem .85rem;
    font-size: .88rem;
}

/* ---------- dashboard ---------- */
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    padding: 2.25rem 0 1.75rem;
}

.page-head h2 {
    font-size: 1.7rem;
    letter-spacing: -.01em;
}

.page-head .muted {
    color: var(--text-muted);
    font-size: .95rem;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem 1.4rem;
}

.stat .stat-label {
    font-size: .85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stat .stat-value {
    font-size: 1.9rem;
    font-weight: 750;
    letter-spacing: -.02em;
    margin-top: .15rem;
}

.panel {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
    overflow: hidden;
}

.panel-head {
    padding: 1.1rem 1.4rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-head h3 { font-size: 1.05rem; }

.panel-body { padding: 1.4rem; }

.panel-body.info-list p { margin-bottom: .4rem; }

.panel-empty {
    padding: 2.5rem 1.25rem;
    text-align: center;
    color: var(--text-muted);
}

/* ---------- dashboard tables ---------- */
.count-pill {
    display: inline-block;
    min-width: 1.6em;
    padding: 0 .5em;
    margin-left: .35rem;
    border-radius: 999px;
    background: var(--primary-light);
    color: var(--primary);
    font-size: .82rem;
    font-weight: 700;
    text-align: center;
    vertical-align: 2px;
}

/* ---------- dashboard tables (compact, zebra) ---------- */
.count-pill {
    display: inline-block;
    min-width: 1.4em;
    padding: 0 .45em;
    margin-left: .35rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    background: var(--primary-light);
    color: var(--primary);
    text-align: center;
    vertical-align: 2px;
}

.panel-head .muted { font-size: .85rem; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .78rem;
    min-width: 620px;
}

.data-table th {
    text-align: left;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    font-weight: 600;
    padding: .35rem .6rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    white-space: nowrap;
}

.data-table td {
    padding: .3rem .6rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    line-height: 1.35;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr:nth-child(even) { background: #f3f4f6; }

.data-table tbody tr:hover { background: var(--primary-light); }

.row-link {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.row-link:hover { text-decoration: underline; }

.badge {
    display: inline-block;
    padding: 0 .45rem;
    border-radius: 999px;
    font-size: .66rem;
    font-weight: 600;
    line-height: 1.5;
    background: var(--primary-light);
    color: var(--primary);
    margin-left: .35rem;
    white-space: nowrap;
}

.badge-ho { background: #ecfdf5; color: #047857; }

.ch-website { background: #e0f2fe; color: #075985; }
.ch-email   { background: #fef3c7; color: #92400e; }
.ch-post    { background: #f3e8ff; color: #6b21a8; }
.badge + .badge { margin-left: .25rem; }

.ref-cell {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .96em;
    white-space: nowrap;
    color: var(--text-muted);
}

/* never wrap; ellipsis when too long */
.data-table th, .data-table td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* first two columns (reference, date): always fit to content */
.data-table th:nth-child(1), .data-table td:nth-child(1),
.data-table th:nth-child(2), .data-table td:nth-child(2) {
    width: 0;
    max-width: none;
    overflow: visible;
}

/* middle columns truncate at a cap */
.data-table td:not(:last-child):not(:nth-child(1)):not(:nth-child(2)),
.data-table th:not(:last-child):not(:nth-child(1)):not(:nth-child(2)) {
    max-width: 200px;
}

/* last column: flexible, still ellipsis-truncated, absorbs remaining space */
.data-table th:last-child, .data-table td:last-child {
    width: auto;
    max-width: 420px;
}

.kv {
    padding: .55rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.kv:last-child { border-bottom: none; }

.kv .k { color: var(--text-muted); }

/* ---------- footer ---------- */
.footer {
    border-top: 1px solid var(--border);
    padding: 1.5rem 0;
    color: var(--text-muted);
    font-size: .88rem;
    background: var(--white);
}

/* ---------- responsive ---------- */
@media (max-width: 820px) {
    .features { grid-template-columns: 1fr; }
    .stats { grid-template-columns: 1fr; }
    .hero { padding: 3.5rem 1.25rem 3rem; }
    .page-head { padding: 1.5rem 0 1.25rem; }
    .page-head h2 { font-size: 1.35rem; }
    .stats { gap: .75rem; margin-bottom: 1.25rem; }
    .stat { padding: .9rem 1.1rem; }
    .stat .stat-value { font-size: 1.5rem; }
    .panel { margin-bottom: 1.25rem; }
    .panel-head { flex-direction: column; align-items: flex-start; gap: .2rem; padding: .8rem 1rem; }
    .data-table { font-size: .74rem; }
    .data-table th { font-size: .62rem; padding: .3rem .45rem; }
    .data-table td { padding: .28rem .45rem; }
}

@media (max-width: 480px) {
    .card { padding: 1.75rem 1.25rem; }
    .hero-cta .btn { width: 100%; }
    .nav-links { gap: .65rem; }
    .container-fluid { padding: 0 .6rem; }
    .data-table { font-size: .7rem; min-width: 540px; }
    .data-table th, .data-table td { padding: .25rem .35rem; }
}

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