/* ==========================================================================
   Contacts: design system
   One stylesheet for every page. Tokens first, then base, then components.
   Light and dark follow the visitor's system setting.
   ========================================================================== */

:root {
    color-scheme: light dark;

    /* surfaces */
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-2: #eef0f6;
    --line: #e1e4ed;
    --line-strong: #b9c0d0;

    /* text */
    --text: #141927;
    --muted: #566075;

    /* brand */
    --accent: #4338ca;            /* links, icons, focus */
    --accent-hover: #362ba8;
    --btn-bg: #4338ca;            /* filled buttons (white text: 7.9:1) */
    --btn-bg-hover: #362ba8;
    --btn-text: #ffffff;
    --accent-soft: #e7e8fc;       /* selected / active backgrounds */
    --on-accent-soft: #2a2390;

    /* status */
    --danger: #b3261e;
    --danger-soft: #fdeceb;
    --success: #0b6b43;
    --success-soft: #e5f5ec;
    --warning: #8f5400;
    --warning-soft: #fff3da;
    --star: #c98400;

    /* shape, depth, size */
    --r-s: 8px;
    --r-m: 12px;
    --r-l: 20px;
    --shadow-1: 0 1px 2px rgba(20, 25, 39, .08), 0 1px 1px rgba(20, 25, 39, .04);
    --shadow-2: 0 8px 28px rgba(20, 25, 39, .16), 0 2px 6px rgba(20, 25, 39, .08);
    --topbar-h: 64px;
    --sidebar-w: 268px;
    --tap: 44px;

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d111a;
        --surface: #161b27;
        --surface-2: #1f2535;
        --line: #2a3246;
        --line-strong: #46506a;
        --text: #e8ecf5;
        --muted: #a3adc2;
        --accent: #aab0ff;
        --accent-hover: #c5c9ff;
        --btn-bg: #5b5ff0;
        --btn-bg-hover: #6f73f5;
        --btn-text: #ffffff;
        --accent-soft: #282c58;
        --on-accent-soft: #dcdeff;
        --danger: #ff9b92;
        --danger-soft: #3a1d1f;
        --success: #7fdcae;
        --success-soft: #16332a;
        --warning: #ffcb6b;
        --warning-soft: #3a2c10;
        --star: #f2b32e;
        --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow-2: 0 8px 28px rgba(0, 0, 0, .55), 0 2px 6px rgba(0, 0, 0, .4);
    }
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 16px); }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, p, figure { margin: 0; }
img { max-width: 100%; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
table { border-collapse: collapse; }
svg { width: 24px; height: 24px; flex: none; }
.ic { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; left: 12px; top: -80px; z-index: 100; padding: 10px 16px; border-radius: var(--r-s); background: var(--btn-bg); color: var(--btn-text); text-decoration: none; font-weight: 600; }
.skip-link:focus { top: 12px; }
.muted { color: var(--muted); }

/* ---------- Buttons ---------- */
.btn-primary, .btn-text, .btn-outline, .btn-danger, .btn-auth, .tr-btn, .mg-btn-outline, .pop-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--tap); padding: 0 20px; border-radius: 999px; border: 1px solid transparent;
    font-weight: 600; font-size: 15px; text-decoration: none; white-space: nowrap; cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.btn-primary, .btn-auth { background: var(--btn-bg); color: var(--btn-text); }
.btn-primary:hover, .btn-auth:hover { background: var(--btn-bg-hover); color: var(--btn-text); }
.btn-primary:active, .btn-auth:active { box-shadow: inset 0 2px 4px rgba(0, 0, 0, .25); }
.btn-text { background: transparent; color: var(--accent); }
.btn-text:hover { background: var(--accent-soft); color: var(--on-accent-soft); }
.btn-outline, .tr-btn, .mg-btn-outline { background: var(--surface); color: var(--accent); border-color: var(--line-strong); }
.btn-outline:hover, .tr-btn:hover:not(:disabled), .mg-btn-outline:hover { background: var(--accent-soft); color: var(--on-accent-soft); }
.btn-text.btn-danger, .tr-btn.danger { color: var(--danger); }
.btn-text.btn-danger:hover, .tr-btn.danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
.tr-btn:disabled, .btn-primary:disabled, .btn-auth:disabled { opacity: .5; cursor: not-allowed; }
.btn-save { border: 0; }
.btn-auth { width: 100%; }
.btn-link { border: 0; background: transparent; min-height: var(--tap); padding: 0 12px; margin-left: -12px; border-radius: var(--r-s); color: var(--accent); font-weight: 600; }
.btn-link:hover { background: var(--accent-soft); }

.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); text-decoration: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn-sm { width: 36px; height: 36px; }
.icon-btn-sm svg { width: 20px; height: 20px; }
@media (pointer: coarse) {
    .icon-btn, .icon-btn-sm { width: var(--tap); height: var(--tap); }
}
.icon-btn.is-starred { color: var(--star); }
.icon-btn.is-starred .ic { fill: currentColor; }

/* ---------- Avatars, chips ---------- */
.avatar { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: #fff; font-weight: 600; border: 0; overflow: hidden; flex: none; text-shadow: 0 1px 1px rgba(0, 0, 0, .25); }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-sm { width: 36px; height: 36px; font-size: 15px; }
.avatar-xl { width: 96px; height: 96px; font-size: 40px; }
button.avatar { cursor: pointer; }

.chip { display: inline-flex; align-items: center; min-height: 28px; padding: 0 12px; margin: 2px 4px 2px 0; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); font-size: 13px; color: var(--text); text-decoration: none; }
a.chip:hover { background: var(--accent-soft); border-color: transparent; color: var(--on-accent-soft); }

/* ---------- App bar + shell ---------- */
.topbar { position: fixed; inset: 0 0 auto 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: calc(var(--sidebar-w) - 28px); }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 19px; letter-spacing: -.01em; }
.brand:hover { color: var(--text); }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--btn-bg); color: var(--btn-text); }
.brand-mark svg { width: 20px; height: 20px; }

.search { position: relative; flex: 1; max-width: 640px; }
.search input { width: 100%; height: 46px; padding: 0 48px; border: 1px solid transparent; border-radius: 999px; background: var(--surface-2); color: var(--text); font-size: 16px; }
.search input::placeholder { color: var(--muted); opacity: 1; }
.search input:focus { outline: none; background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-icon { position: absolute; left: 14px; top: 11px; width: 22px; height: 22px; color: var(--muted); pointer-events: none; }
.search-clear { position: absolute; right: 4px; top: 3px; }
.search-clear { z-index: 1; }
.search kbd { position: absolute; right: 14px; top: 11px; padding: 0 7px; border: 1px solid var(--line-strong); border-radius: 6px; font: 13px/22px var(--font); color: var(--muted); pointer-events: none; }
.search input:focus ~ kbd, .search kbd[hidden] { display: none; }

.dropdown { position: relative; }
.dropdown-menu { display: none; position: absolute; right: 0; top: calc(100% + 8px); min-width: 260px; padding: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); box-shadow: var(--shadow-2); }
.dropdown-menu.show { display: block; }
.dropdown-head { display: flex; align-items: center; gap: 12px; padding: 8px 8px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; min-width: 0; }
.dropdown-head div { min-width: 0; }
.dropdown-head strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown-head small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown-menu a { display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 0 12px; border-radius: var(--r-s); color: var(--text); text-decoration: none; }
.dropdown-menu a:hover { background: var(--surface-2); color: var(--text); }
.dropdown-menu a svg { width: 20px; height: 20px; color: var(--muted); }

.shell { display: flex; padding-top: var(--topbar-h); min-height: 100vh; }
.sidebar { position: fixed; top: var(--topbar-h); bottom: 0; z-index: 25; width: var(--sidebar-w); padding: 12px 12px 24px; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line); transition: transform .22s ease; }
.content { flex: 1; min-width: 0; margin-left: var(--sidebar-w); padding: 24px 32px 64px; transition: margin .22s ease; }
body.sidebar-collapsed .sidebar { transform: translateX(-100%); }
body.sidebar-collapsed .content { margin-left: 0; }

.create-btn { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; margin: 4px 0 16px; padding: 0 20px; border-radius: var(--r-l); background: var(--btn-bg); color: var(--btn-text); text-decoration: none; font-weight: 600; box-shadow: var(--shadow-1); }
.create-btn:hover { background: var(--btn-bg-hover); color: var(--btn-text); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 14px; min-height: var(--tap); padding: 0 14px; border-radius: var(--r-s); color: var(--text); text-decoration: none; font-size: 15px; }
.nav-item svg { width: 20px; height: 20px; color: var(--muted); }
.nav-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item small { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--on-accent-soft); font-weight: 600; }
.nav-item.active svg { color: var(--on-accent-soft); }
.nav-section { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 4px; padding: 0 6px 0 14px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.scrim { display: none; }

/* ---------- Page header + cards ---------- */
.content-head { margin-bottom: 20px; }
.content-head h1 { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.count { color: var(--muted); font-weight: 500; font-size: 18px; }
.content-head .muted { margin-top: 6px; }

.ie-wrap { max-width: 760px; }
.ie-card, .view-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow-1); }
.ie-card h2 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.ie-card .muted { margin: 0 0 8px; }
.ie-field { margin: 18px 0; }
.ie-field label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.ie-field input[type=text], .ie-field input[type=file], .ie-field select {
    width: 100%; min-height: var(--tap); padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-s); background: var(--surface); color: var(--text);
}
.ie-field input:focus, .ie-field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ie-hint { font-size: 13px; color: var(--muted); margin-top: 8px; }
.ie-notice { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-radius: var(--r-m); margin-bottom: 20px; font-size: 15px; border: 1px solid transparent; }
.ie-notice.success { background: var(--success-soft); color: var(--success); }
.ie-notice.warning { background: var(--warning-soft); color: var(--warning); }
.ie-notice.error { background: var(--danger-soft); color: var(--danger); }
.ie-notice a { color: inherit; font-weight: 600; }

/* ---------- Contacts list ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 0 16px; background: var(--surface); border: 1px solid var(--line); border-bottom: 0; border-radius: var(--r-m) var(--r-m) 0 0; }
.selected-info { color: var(--muted); font-size: 14px; }
.toolbar-actions { display: flex; align-items: center; gap: 4px; margin-left: 8px; }
.check input, .row-check { width: 20px; height: 20px; accent-color: var(--btn-bg); cursor: pointer; }
.check { display: inline-grid; place-items: center; width: 32px; height: 32px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 0 0 var(--r-m) var(--r-m); box-shadow: var(--shadow-1); }
.contacts { width: 100%; font-size: 15px; }
.contacts th { padding: 12px 16px; text-align: left; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.contacts td { padding: 0 16px; height: 64px; border-bottom: 1px solid var(--line); white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.contacts tbody tr:last-child td { border-bottom: 0; }
.contacts tbody tr:hover { background: var(--surface-2); }
.contacts tbody tr.selected { background: var(--accent-soft); }
.col-check { width: 72px; position: relative; }
.col-actions { width: 150px; text-align: right; }
.col-check .row-check { position: absolute; left: 22px; top: 22px; opacity: 0; }
.contacts tr:hover .row-check, .contacts tr.selected .row-check, .row-check:focus-visible { opacity: 1; }
.contacts tr:hover .row-avatar, .contacts tr.selected .row-avatar, .col-check:focus-within .row-avatar { opacity: 0; }
.name-link { color: var(--text); text-decoration: none; font-weight: 600; }
.name-link:hover { color: var(--accent); text-decoration: underline; }
.row-actions { display: inline-flex; opacity: 0; transition: opacity .12s ease; }
.contacts tr:hover .row-actions, .row-actions:focus-within { opacity: 1; }
@media (hover: none) {
    .row-actions { opacity: 1; }
    .col-check .row-check { opacity: 1; }
    .row-avatar { display: none; }
}

.empty { text-align: center; padding: 72px 16px; background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--r-m); }
.empty-art { width: 72px; height: 72px; margin: 0 auto 16px; color: var(--accent); opacity: .85; stroke-width: 1.2; }
.empty h2 { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.empty p { color: var(--muted); margin-bottom: 24px; }

/* ---------- Popover (labels) ---------- */
.pop-wrap { position: relative; display: inline-block; }
.label-pop { position: absolute; top: calc(100% + 8px); left: 0; z-index: 60; width: 290px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); box-shadow: var(--shadow-2); padding: 12px 0 10px; }
.label-pop h4 { padding: 0 16px 8px; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.pop-list { max-height: 220px; overflow-y: auto; }
.pop-item { display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 0 16px; font-size: 15px; cursor: pointer; }
.pop-item:hover { background: var(--surface-2); }
.pop-item input { width: 18px; height: 18px; accent-color: var(--btn-bg); }
.pop-empty { padding: 6px 16px 10px; font-size: 14px; color: var(--muted); }
.pop-new { display: flex; gap: 8px; padding: 10px 12px 4px; border-top: 1px solid var(--line); margin-top: 6px; }
.pop-new input { flex: 1; min-width: 0; min-height: 40px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--r-s); background: var(--surface); color: var(--text); }
.pop-new input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pop-btn { min-height: 40px; padding: 0 16px; font-size: 14px; background: var(--surface); color: var(--accent); border-color: var(--line-strong); }
.pop-btn:hover { background: var(--accent-soft); color: var(--on-accent-soft); }
.pop-btn.solid { background: var(--btn-bg); color: var(--btn-text); border-color: transparent; }
.pop-btn.solid:hover { background: var(--btn-bg-hover); }
.pop-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 12px 0; }

/* ---------- Snackbar ---------- */
.snackbar { position: fixed; left: 50%; bottom: 24px; z-index: 80; transform: translateX(-50%); max-width: min(92vw, 520px); padding: 14px 20px; border-radius: var(--r-m); background: #20263a; color: #fff; font-size: 15px; box-shadow: var(--shadow-2); transition: opacity .25s ease; }
.snackbar.hide { opacity: 0; pointer-events: none; }
@media (prefers-color-scheme: dark) { .snackbar { background: #e8ecf5; color: #141927; } }

/* ---------- Focused pages (add / edit / view): bar + body ---------- */
.topbar .form-title { font-size: 20px; font-weight: 700; margin: 0 0 0 4px; }
.form-page, .view-page { max-width: 780px; margin: 0 auto; padding: calc(var(--topbar-h) + 28px) 16px 96px; }

/* form */
.form-row { display: flex; gap: 16px; margin-bottom: 22px; }
.row-icon { width: 32px; padding-top: 13px; color: var(--muted); flex: none; }
.row-body { flex: 1; min-width: 0; }
.row-label { margin: 8px 0 10px; color: var(--muted); font-size: 14px; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.photo-block { margin-bottom: 20px; }
.photo-pick { display: inline-flex; align-items: center; gap: 16px; cursor: pointer; }
.photo-circle { display: grid; place-items: center; width: 96px; height: 96px; border-radius: 50%; background: var(--surface-2) center / cover no-repeat; border: 2px dashed var(--line-strong); color: var(--muted); }
.photo-circle svg { width: 32px; height: 32px; }
.photo-circle.has-photo { border-style: solid; border-color: var(--accent); }
.photo-circle.has-photo svg { display: none; }
.photo-text { color: var(--accent); font-weight: 600; }
.photo-pick:hover .photo-circle { border-color: var(--accent); }
.photo-block:focus-within .photo-circle { outline: 3px solid var(--accent); outline-offset: 2px; }
.remove-photo { display: inline-flex; align-items: center; gap: 8px; margin-top: 8px; min-height: var(--tap); font-size: 14px; color: var(--muted); cursor: pointer; }

/* floating-label fields */
.field { position: relative; }
.field input, .field textarea, .field select {
    width: 100%; min-height: 56px; padding: 22px 14px 8px; border: 1px solid var(--line-strong); border-radius: var(--r-s);
    background: var(--surface); color: var(--text); font-size: 16px; line-height: 1.3;
}
.field textarea { resize: vertical; min-height: 96px; }
.field label {
    position: absolute; left: 12px; top: 16px; padding: 0 4px; background: var(--surface);
    color: var(--muted); font-size: 16px; line-height: 1; pointer-events: none; transition: top .12s ease, font-size .12s ease, color .12s ease;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input:focus + label, .field textarea:focus + label,
.field input:not(:placeholder-shown) + label, .field textarea:not(:placeholder-shown) + label,
.field-date label { top: -7px; font-size: 12px; font-weight: 600; }
.field input:focus + label, .field textarea:focus + label { color: var(--accent); }
.field-date input { max-width: 260px; }
.field-error { margin: 6px 0 8px; color: var(--danger); font-size: 14px; }
.alert-error { margin: 0 0 24px; padding: 14px 16px; border-radius: var(--r-m); background: var(--danger-soft); color: var(--danger); font-weight: 500; }

.repeat-item { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.repeat-item .grow { flex: 1; }
.repeat-item select { height: 56px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--r-s); background: var(--surface); color: var(--text); min-width: 116px; }
.repeat-item select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.more { margin: 4px 0 22px; }
.more > summary { display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 18px; border-radius: 999px; color: var(--accent); font-weight: 600; cursor: pointer; list-style: none; border: 1px solid var(--line-strong); background: var(--surface); }
.more > summary::-webkit-details-marker { display: none; }
.more > summary:hover { background: var(--accent-soft); }
.more[open] > summary { display: none; }

.label-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.label-chip { position: relative; }
.label-chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.label-chip span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); font-size: 14px; }
.label-chip:hover span { background: var(--surface-2); }
.label-chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--on-accent-soft); font-weight: 600; }
.label-chip input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.label-picker .chip { min-height: 40px; padding: 0 16px; border-style: dashed; }

/* view page */
.view-head { display: flex; align-items: center; gap: 24px; margin-bottom: 24px; }
.view-head h1 { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; overflow-wrap: anywhere; }
.view-head .subtitle { color: var(--muted); margin: 4px 0 10px; }
.view-card { padding: 8px 24px; }
.view-row { display: flex; gap: 20px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.view-row:last-child { border-bottom: 0; }
.view-row .vi { color: var(--muted); margin-top: 2px; }
.view-label { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.view-value { overflow-wrap: anywhere; }
.view-value .type { margin-left: 8px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12px; }
.view-notes { white-space: normal; }
.view-empty { text-align: center; padding: 32px 0; color: var(--muted); }
.view-empty p { margin-bottom: 16px; }

/* ---------- Merge / trash / label pages ---------- */
.mg-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 24px; overflow-x: auto; }
.mg-tabs a { display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 16px; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; font-weight: 600; white-space: nowrap; }
.mg-tabs a:hover { color: var(--text); }
.mg-tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.mg-tabs small { background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 1px 9px; margin-left: 8px; font-size: 12px; }
.mg-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.mg-group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); margin-bottom: 16px; overflow: hidden; box-shadow: var(--shadow-1); }
.mg-group-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); gap: 12px; flex-wrap: wrap; }
.mg-reason { font-size: 14px; color: var(--muted); }
.mg-row { display: flex; align-items: center; gap: 14px; min-height: 64px; padding: 8px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.mg-row:last-child { border-bottom: 0; }
.mg-row:hover { background: var(--surface-2); }
.mg-row .mg-info { flex: 1; min-width: 0; }
.mg-row .mg-sub { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--btn-bg); }
.mg-form { margin: 0; }
.mg-list { margin: 12px 0 16px; padding: 0; list-style: none; font-size: 15px; }
.mg-list li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.mg-list li:last-child { border-bottom: 0; }
.mg-arrow { color: var(--muted); }
.mg-ok { color: var(--success); }

.tr-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); font-size: 15px; color: var(--muted); }
.tr-bar form { margin: 0; }
.tr-actions { display: flex; align-items: center; gap: 8px; }
.tr-row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.tr-muted { color: var(--muted); font-size: 14px; }
.tr-btn { padding: 0 16px; font-size: 14px; }

.la-wrap { max-width: 640px; }
.la-tools { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.la-tools input[type=search] { flex: 1; min-width: 0; min-height: var(--tap); padding: 0 14px; border: 1px solid var(--line-strong); border-radius: var(--r-s); background: var(--surface); color: var(--text); }
.la-tools input[type=search]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.la-list { border: 1px solid var(--line); border-radius: var(--r-m); max-height: 380px; overflow-y: auto; background: var(--surface); }
.la-item { display: flex; align-items: center; gap: 14px; min-height: 56px; padding: 6px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.la-item:last-child { border-bottom: 0; }
.la-item[hidden], .la-none[hidden] { display: none; }
.la-item:hover { background: var(--surface-2); }
.la-item input { width: 20px; height: 20px; accent-color: var(--btn-bg); flex: none; }
.la-item .txt { min-width: 0; }
.la-item small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.la-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.la-count { font-size: 14px; color: var(--muted); }
.la-actions { display: flex; gap: 8px; align-items: center; }
.la-cancel { display: inline-flex; align-items: center; min-height: var(--tap); color: var(--muted); text-decoration: none; padding: 0 14px; font-weight: 600; }
.la-none { padding: 20px; text-align: center; color: var(--muted); }

/* ---------- Sign in / sign up / verify ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background:
    radial-gradient(900px 400px at 10% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 440px; padding: 36px 32px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow-2); }
.auth-brand { display: flex; justify-content: center; margin-bottom: 20px; }
.auth-icon { display: grid; place-items: center; width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 16px; background: var(--accent-soft); color: var(--on-accent-soft); }
.auth-icon svg { width: 28px; height: 28px; }
.auth-card h1 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; text-align: center; }
.auth-sub { text-align: center; color: var(--muted); margin: 6px 0 24px; overflow-wrap: anywhere; }
.auth-sub strong { color: var(--text); }
.auth-form .form-group { margin-bottom: 18px; }
.auth-form label.form-label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; }
.input-wrap { position: relative; }
.input-wrap > svg { position: absolute; left: 14px; top: 13px; width: 20px; height: 20px; color: var(--muted); pointer-events: none; }
.form-control { width: 100%; min-height: 48px; padding: 0 14px 0 44px; border: 1px solid var(--line-strong); border-radius: var(--r-s); background: var(--surface); color: var(--text); font-size: 16px; }
.form-control::placeholder { color: var(--muted); opacity: .85; }
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-control.has-toggle { padding-right: 52px; }
.toggle-password { position: absolute; right: 2px; top: 2px; width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: var(--r-s); background: transparent; color: var(--muted); }
.toggle-password:hover { color: var(--text); background: var(--surface-2); }
.toggle-password svg { width: 20px; height: 20px; }
.field-help { margin-top: 6px; font-size: 13px; color: var(--muted); }
.field-msg { margin-top: 6px; font-size: 14px; color: var(--danger); }
.auth-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.check-row { display: flex; align-items: center; gap: 10px; min-height: var(--tap); font-size: 15px; cursor: pointer; }
.check-row input { width: 20px; height: 20px; accent-color: var(--btn-bg); flex: none; }
.auth-foot { margin-top: 24px; text-align: center; color: var(--muted); font-size: 15px; }
.auth-foot a { font-weight: 600; }

.alert { display: flex; gap: 10px; align-items: flex-start; margin: 0 0 20px; padding: 12px 14px; border-radius: var(--r-s); font-size: 15px; }
.alert svg { width: 20px; height: 20px; margin-top: 1px; }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }

.otp-inputs { display: flex; justify-content: center; gap: 10px; margin-bottom: 24px; }
.otp-box { width: 48px; height: 58px; text-align: center; font-size: 24px; font-weight: 600; border: 1px solid var(--line-strong); border-radius: var(--r-s); background: var(--surface); color: var(--text); }
.otp-box:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
@media (max-width: 380px) { .otp-box { width: 42px; height: 52px; } .otp-inputs { gap: 6px; } }

@media (pointer: coarse) { .search kbd { display: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 991px) {
    .topbar-left { min-width: 0; }
    .brand-name { display: none; }
    .sidebar { transform: translateX(-100%); width: 296px; max-width: 86vw; box-shadow: var(--shadow-2); }
    body.sidebar-open .sidebar { transform: none; }
    body.sidebar-open .scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(8, 11, 20, .5); z-index: 20; }
    .content, body.sidebar-collapsed .content { margin-left: 0; padding: 20px 16px 72px; }
    .contacts th:nth-child(5), .contacts td:nth-child(5) { display: none; }
}
@media (max-width: 767px) {
    .contacts th:nth-child(4), .contacts td:nth-child(4),
    .contacts th:nth-child(6), .contacts td:nth-child(6) { display: none; }
    .content-head h1 { font-size: 24px; }
    .col-actions { width: auto; }
}
@media (max-width: 575px) {
    .grid-2 { grid-template-columns: 1fr; }
    .form-row { gap: 12px; }
    .row-icon { width: 24px; }
    .view-head { flex-direction: column; align-items: flex-start; gap: 16px; }
    .auth-card { padding: 28px 20px; }
    .topbar { padding: 0 8px; gap: 4px; }
    .topbar-right .btn-text { padding: 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media print {
    .topbar, .sidebar, .toolbar, .snackbar { display: none !important; }
    .content { margin: 0; padding: 0; }
}
