/* ============================================================
   Home CRM — Personal Contact Manager
   ============================================================ */

:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-sidebar: #141620;
    --bg-input: #1e2130;
    --bg-hover: #252838;
    --border: #2a2d3a;
    --text: #e4e6f0;
    --text-muted: #8b8fa3;
    --text-dim: #5c6070;
    --accent: #6c8aff;
    --accent-hover: #5a75e6;
    --accent-bg: rgba(108, 138, 255, 0.1);
    --danger: #ff6b6b;
    --danger-bg: rgba(255, 107, 107, 0.1);
    --success: #4ecdc4;
    --success-bg: rgba(78, 205, 196, 0.1);
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --transition: 0.2s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
}

#app {
    display: grid;
    grid-template-columns: 220px 1fr;
    height: 100vh;
}

/* ── Sidebar ──────────────────────────────── */

#sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 20px 16px 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

nav {
    flex: 1;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    transition: var(--transition);
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent); font-weight: 500; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 12px;
}

/* ── Main Content ─────────────────────────── */

#main-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

#topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.search-wrapper { flex: 1; }

#search-input {
    width: 100%;
    max-width: 400px;
    padding: 10px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--text-dim); }

#content-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.view { display: none; }
.view.active { display: block; }

/* ── Contact List ─────────────────────────── */

.contact-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.contact-card {
    display: grid;
    grid-template-columns: 44px 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
}

.contact-card:hover { background: var(--bg-hover); }
.contact-card.selected { background: var(--accent-bg); }

.contact-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-bg);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
}

.contact-avatar.favorite { background: #ffd43b22; color: #ffd43b; }

.contact-info { min-width: 0; }

.contact-name {
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-meta {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-groups {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.group-tag {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    background: var(--bg-input);
    color: var(--text-muted);
    white-space: nowrap;
}

/* ── Letter Separator ─────────────────────── */

.letter-separator {
    padding: 8px 14px 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 1px;
    text-transform: uppercase;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 1;
}

/* ── Detail Panel ─────────────────────────── */

.detail-panel {
    width: 380px;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
    transition: transform 0.25s ease;
}

.detail-panel[hidden] { display: none; }

#app:has(.detail-panel:not([hidden])) {
    grid-template-columns: 220px 1fr 380px;
}

.detail-header {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

#detail-content { padding: 20px 16px; }

.detail-name {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 4px;
}

.detail-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.detail-section {
    margin-bottom: 20px;
}

.detail-section h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 6px 0;
    font-size: 14px;
}

.detail-label {
    font-size: 12px;
    color: var(--text-muted);
}

.detail-value {
    text-align: right;
    word-break: break-word;
}

.detail-value a {
    color: var(--accent);
    text-decoration: none;
}

.detail-value a:hover { text-decoration: underline; }

.detail-notes {
    padding: 10px 12px;
    background: var(--bg-input);
    border-radius: var(--radius);
    font-size: 13px;
    white-space: pre-wrap;
    color: var(--text-muted);
}

/* ── Interactions Timeline ────────────────── */

.interaction-item {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.interaction-item:last-child { border-bottom: none; }

.interaction-type {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg-input);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.interaction-content { flex: 1; min-width: 0; }
.interaction-date { font-size: 11px; color: var(--text-dim); }

/* Add interaction */
.add-interaction {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.add-interaction input {
    flex: 1;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    outline: none;
}

.add-interaction select {
    padding: 6px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    outline: none;
}

/* ── Birthdays ────────────────────────────── */

.birthday-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--bg-card);
    margin-bottom: 6px;
}

.birthday-days {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.birthday-days.today { background: var(--success-bg); color: var(--success); }
.birthday-days.soon { background: #ffd43b22; color: #ffd43b; }
.birthday-days.later { background: var(--bg-input); color: var(--text-muted); }

.birthday-days .num { font-size: 18px; line-height: 1; }
.birthday-days .label { font-size: 9px; text-transform: uppercase; }

.birthday-info .name { font-weight: 500; }
.birthday-info .date { font-size: 12px; color: var(--text-muted); }

/* ── Groups ───────────────────────────────── */

.group-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--bg-card);
    margin-bottom: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.group-card:hover { background: var(--bg-hover); }
.group-name { font-weight: 500; }
.group-count { color: var(--text-muted); font-size: 13px; }

/* ── Import ───────────────────────────────── */

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-bg);
    color: var(--accent);
}

.import-preview { margin-top: 16px; }

.import-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-weight: 500;
}

.import-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius);
    background: var(--bg-card);
    margin-bottom: 4px;
}

.import-item.duplicate { opacity: 0.5; }
.import-item input[type="checkbox"] { flex-shrink: 0; }

/* ── Modal ────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.modal-overlay[hidden] { display: none; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 600px;
    max-width: 95vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

.modal-header h2 { font-size: 16px; }

.contact-form { padding: 16px 20px; }

.form-section {
    margin-bottom: 20px;
}

.form-section h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-group {
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--accent);
}

.multi-row {
    display: grid;
    grid-template-columns: 100px 1fr 32px;
    gap: 8px;
    align-items: end;
    margin-bottom: 8px;
}

.multi-row.address-row {
    grid-template-columns: 100px 1fr 100px 1fr 32px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ── Buttons ──────────────────────────────── */

.btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

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

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

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

.btn-icon {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-icon:hover { background: var(--bg-hover); color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-bg); color: var(--danger); }

.btn-small {
    padding: 2px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-small:hover { background: var(--bg-hover); color: var(--text); }

.btn-remove {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-dim);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-remove:hover { color: var(--danger); }

/* ── Toast ────────────────────────────────── */

#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    box-shadow: var(--shadow);
    animation: toast-in 0.3s ease;
    max-width: 360px;
}

.toast.success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success); }
.toast.error { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.toast.info { background: var(--accent-bg); color: var(--accent); border: 1px solid var(--accent); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Empty State ──────────────────────────── */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── Mobile Bottom Nav ─────────────────────── */

.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    z-index: 60;
    padding: 4px 0;
    padding-bottom: env(safe-area-inset-bottom, 4px);
}

.mobile-nav-items {
    display: flex;
    justify-content: space-around;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 10px;
    border-radius: var(--radius);
    transition: var(--transition);
    border: none;
    background: none;
    cursor: pointer;
}

.mobile-nav-item .nav-icon { font-size: 20px; }
.mobile-nav-item.active { color: var(--accent); }
.mobile-nav-item:hover { color: var(--text); }

/* ── Responsive ───────────────────────────── */

@media (max-width: 768px) {
    #app { grid-template-columns: 1fr; }
    #sidebar { display: none; }

    .mobile-nav { display: block; }

    #content-area { padding-bottom: 72px; }

    #topbar { padding: 8px 12px; }
    #search-input { max-width: 100%; }

    .detail-panel {
        position: fixed;
        right: 0; top: 0;
        width: 100vw;
        height: 100vh;
        z-index: 50;
    }
    #app:has(.detail-panel:not([hidden])) { grid-template-columns: 1fr; }

    .modal { width: 100vw; max-width: 100vw; max-height: 100vh; border-radius: 0; }

    .multi-row.address-row {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .multi-row.address-row select { grid-column: 1 / -1; }
    .multi-row.address-row .btn-remove { grid-column: 2; justify-self: end; }
}

/* ── Scrollbar ────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
