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

/* ── DESIGN-TOKENS ─────────────────────────────────────────────────────────── */

:root {
    --bg:          #edf0f8;
    --surface:     #ffffff;
    --surface-2:   #f4f6fc;
    --border:      #dce0ee;
    --text:        #0e1524;
    --text-2:      #48527a;
    --text-3:      #8590b8;
    --accent:      #4f6ef7;
    --accent-dark: #3758e8;
    --accent-bg:   #eef1fe;
    --green:       #22c55e;
    --yellow:      #f59e0b;
    --red:         #ef4444;
    --radius:      10px;
    --radius-sm:   6px;
    --shadow:      0 1px 3px rgba(14,21,36,.06), 0 2px 8px rgba(14,21,36,.05);
    --shadow-lg:   0 6px 28px rgba(14,21,36,.11);
    color-scheme: light;
}

[data-theme="dark"] {
    --bg:          #0c0e1a;
    --surface:     #13162a;
    --surface-2:   #1a1e36;
    --border:      #232745;
    --text:        #e2e6f8;
    --text-2:      #7078a8;
    --text-3:      #3d4468;
    --accent:      #6b84ff;
    --accent-dark: #4f6ef7;
    --accent-bg:   #14183a;
    --shadow:      0 1px 4px rgba(0,0,0,.5), 0 3px 10px rgba(0,0,0,.4);
    --shadow-lg:   0 8px 32px rgba(0,0,0,.55);
    color-scheme: dark;
}

/* ── BASE ───────────────────────────────────────────────────────────────────── */

body {
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.55;
    min-height: 100vh;
    transition: background 0.2s, color 0.2s;
}

a { color: var(--accent); }

/* ── NAV ────────────────────────────────────────────────────────────────────── */

nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.nav-logo {
    font-size: 18px;
    font-weight: 800;
    color: var(--accent);
    text-decoration: none;
    letter-spacing: -0.5px;
}

.nav-links {
    display: flex;
    gap: 2px;
    align-items: center;
}

.nav-links a {
    text-decoration: none;
    color: var(--text-2);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}

.nav-links a:hover { background: var(--bg); color: var(--text); }
.nav-logout { font-size: 13px !important; }
.nav-icon { font-size: 16px !important; }

/* ── THEME TOGGLE ───────────────────────────────────────────────────────────── */

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    width: 34px;
    height: 34px;
    cursor: pointer;
    font-size: 15px;
    color: var(--text-2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
    margin-left: 4px;
}

.theme-toggle:hover { background: var(--bg); border-color: var(--accent); }

/* ── LAYOUT ─────────────────────────────────────────────────────────────────── */

main { max-width: 1100px; margin: 0 auto; padding: 28px 20px; }

/* ── BUTTONS ────────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    border: none;
    transition: all 0.15s;
    white-space: nowrap;
    font-family: inherit;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg); }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-sm  { padding: 5px 10px; font-size: 13px; }
.btn-lg  { padding: 12px 24px; font-size: 16px; }
.btn-full { width: 100%; justify-content: center; }

/* ── BADGES ─────────────────────────────────────────────────────────────────── */

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-green  { background: #dcfce7; color: #15803d; }
.badge-yellow { background: #fef9c3; color: #a16207; }
.badge-red    { background: #fee2e2; color: #dc2626; }
.badge-gray   { background: var(--surface-2); color: var(--text-2); }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }

[data-theme="dark"] .badge-green  { background: rgba(34,197,94,.15);  color: #4ade80; }
[data-theme="dark"] .badge-yellow { background: rgba(245,158,11,.15); color: #fbbf24; }
[data-theme="dark"] .badge-red    { background: rgba(239,68,68,.15);  color: #f87171; }
[data-theme="dark"] .badge-gray   { background: var(--surface-2); color: var(--text-2); }
[data-theme="dark"] .badge-blue   { background: rgba(59,130,246,.15); color: #60a5fa; }

/* ── ALERTS ─────────────────────────────────────────────────────────────────── */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid transparent;
}

.alert ul { margin: 0; padding-left: 18px; }

.alert-error   { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
.alert-success { background: #dcfce7; color: #15803d; border-color: #86efac; }
.alert-warning { background: #fef9c3; color: #92400e; border-color: #fde68a; }

[data-theme="dark"] .alert-error   { background: rgba(239,68,68,.12);  color: #fca5a5; border-color: rgba(239,68,68,.3); }
[data-theme="dark"] .alert-success { background: rgba(34,197,94,.12);  color: #86efac; border-color: rgba(34,197,94,.3); }
[data-theme="dark"] .alert-warning { background: rgba(245,158,11,.12); color: #fde68a; border-color: rgba(245,158,11,.3); }

/* ── LOGIN ──────────────────────────────────────────────────────────────────── */

body.login-page { display: flex; align-items: center; justify-content: center; }

.login-box {
    background: var(--surface);
    padding: 48px 44px;
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 380px;
    border: 1px solid var(--border);
}

.login-box h1 {
    font-size: 36px;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 4px;
    letter-spacing: -1px;
}

.login-sub { color: var(--text-3); margin-bottom: 28px; }

/* ── FORMS ──────────────────────────────────────────────────────────────────── */

.form-group { display: flex; flex-direction: column; gap: 5px; }

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
}

.form-group small { font-size: 11px; color: var(--text-3); font-weight: 400; }

.form-input,
.form-select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input::placeholder { color: var(--text-3); }

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79,110,247,.15);
}

[data-theme="dark"] .form-input:focus,
[data-theme="dark"] .form-select:focus {
    box-shadow: 0 0 0 3px rgba(107,132,255,.18);
}

textarea.form-input { resize: vertical; min-height: 82px; }

.form-input-sm {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    flex: 1;
    min-width: 150px;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.form-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.form-section h3 {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.form-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 20px 0;
}

/* ── CHECKBOXES ─────────────────────────────────────────────────────────────── */

.checkbox-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 4px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    user-select: none;
    transition: background 0.12s, border-color 0.12s;
}

.checkbox-label input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: var(--accent);
}

/* ── PAGE HEADER ────────────────────────────────────────────────────────────── */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.page-header h2 { font-size: 22px; font-weight: 700; }
.count { font-size: 16px; font-weight: 400; color: var(--text-3); }

/* ── SEARCH ─────────────────────────────────────────────────────────────────── */

.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    transition: border-color 0.15s;
}

.search-input::placeholder { color: var(--text-3); }
.search-input:focus { outline: none; border-color: var(--accent); }

.search-select {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
}

/* ── CARD GRID ──────────────────────────────────────────────────────────────── */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 16px;
}

.person-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s, transform 0.2s, border-color 0.2s;
}

.person-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
    border-color: var(--accent);
}

.card-photo {
    height: 120px;
    overflow: hidden;
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-photo img { width: 100%; height: 100%; object-fit: cover; }

.card-body { padding: 12px 14px; }

.card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.card-name { font-size: 15px; font-weight: 700; line-height: 1.2; }
.card-nick { font-size: 12px; color: var(--text-3); margin-bottom: 4px; font-style: italic; }
.card-meta { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }

.card-actions {
    display: flex;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

/* ── PHOTO PLACEHOLDERS ─────────────────────────────────────────────────────── */

.photo-placeholder,
.photo-placeholder-lg {
    border-radius: 50%;
    background: var(--accent-bg);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.photo-placeholder    { width: 58px;  height: 58px;  font-size: 24px; }
.photo-placeholder-lg { width: 96px;  height: 96px;  font-size: 38px; }

.foto-preview {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 10px;
    display: block;
}

/* ── PROFILE ────────────────────────────────────────────────────────────────── */

.profile-header {
    display: flex;
    align-items: center;
    gap: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    flex-wrap: wrap;
}

.profile-photo { flex-shrink: 0; }

.profile-photo img {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

.profile-title { flex: 1; min-width: 200px; }

.profile-title h1 {
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 8px;
    letter-spacing: -0.3px;
}

.nick { font-size: 18px; font-weight: 400; color: var(--text-3); font-style: italic; }
.meta-dates { font-size: 12px; color: var(--text-3); margin-top: 6px; }

.profile-actions { display: flex; gap: 8px; flex-shrink: 0; }

.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}

.profile-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.profile-section h2 {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 12px;
}

/* ── INFO LIST ──────────────────────────────────────────────────────────────── */

.info-list { display: flex; flex-direction: column; gap: 9px; }

.info-list > div {
    display: flex;
    gap: 12px;
    font-size: 14px;
    align-items: flex-start;
}

.info-list dt {
    color: var(--text-3);
    min-width: 118px;
    flex-shrink: 0;
    font-weight: 500;
    font-size: 13px;
    padding-top: 1px;
}

.info-list dd { color: var(--text); }

/* ── TAG LIST ───────────────────────────────────────────────────────────────── */

.tag-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.tag-list li {
    background: var(--surface-2);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 13px;
    border: 1px solid var(--border);
    color: var(--text-2);
}

/* ── TAGS & GRUPPEN PILLS ───────────────────────────────────────────────────── */

.tag-pill {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid transparent;
}

.gruppe-pill {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid;
    text-decoration: none;
    transition: opacity 0.15s;
}

.gruppe-pill:hover { opacity: 0.75; }

/* ── CONTACT LINKS ──────────────────────────────────────────────────────────── */

.contact-link { color: var(--accent); text-decoration: none; }
.contact-link:hover { text-decoration: underline; }

/* ── CONTACT HISTORY ────────────────────────────────────────────────────────── */

.contact-history { margin-bottom: 14px; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.add-contact-form {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border: 1px solid var(--border);
}

.form-row-contact { display: flex; gap: 10px; flex-wrap: wrap; }
.form-row-contact .form-input,
.form-row-contact .form-select { width: auto; flex: 1; min-width: 130px; }

.hidden { display: none !important; }

.contact-table { width: 100%; border-collapse: collapse; font-size: 14px; }

.contact-table th {
    text-align: left;
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
}

.contact-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    color: var(--text);
}

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

.empty-text { color: var(--text-3); font-size: 14px; text-align: center; padding: 24px; }

/* ── NOTES ──────────────────────────────────────────────────────────────────── */

.notes-text {
    font-size: 14px;
    color: var(--text);
    line-height: 1.7;
}

/* ── DANGER ZONE ────────────────────────────────────────────────────────────── */

.danger-zone {
    padding: 24px 0 8px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

/* ── DELETE CONFIRM ─────────────────────────────────────────────────────────── */

.delete-confirm {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    max-width: 480px;
    box-shadow: var(--shadow);
}

.delete-confirm h2 { margin-bottom: 14px; }

.delete-confirm p {
    margin-bottom: 24px;
    color: var(--text-2);
    line-height: 1.6;
}

/* ── EMPTY STATE ────────────────────────────────────────────────────────────── */

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

.empty-state p { margin-bottom: 20px; font-size: 16px; }

/* ── BEZIEHUNGSNETZ ─────────────────────────────────────────────────────────── */

.bez-list { display: flex; flex-direction: column; }

.bez-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 4px;
    border-bottom: 1px solid var(--border);
}

.bez-row:last-child { border-bottom: none; }
.bez-name { font-weight: 600; text-decoration: none; color: var(--accent); }
.bez-name:hover { text-decoration: underline; }
.bez-desc { font-size: 13px; color: var(--text-3); }

/* ── ANHÄNGE ────────────────────────────────────────────────────────────────── */

.anhang-list { display: flex; flex-direction: column; }

.anhang-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 4px;
    border-bottom: 1px solid var(--border);
}

.anhang-row:last-child { border-bottom: none; }
.anhang-icon { font-size: 18px; flex-shrink: 0; }

.anhang-name {
    text-decoration: none;
    color: var(--accent);
    font-size: 14px;
    font-weight: 500;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.anhang-name:hover { text-decoration: underline; }
.anhang-meta { font-size: 12px; color: var(--text-3); white-space: nowrap; }

/* ── SETTINGS ───────────────────────────────────────────────────────────────── */

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.settings-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.settings-card h3 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.settings-card .form-group { margin-bottom: 12px; }

.color-input {
    width: 48px;
    height: 36px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: var(--surface);
}

.create-tag-form {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.create-tag-form .form-input { flex: 1; }

.tag-manager-list { display: flex; flex-direction: column; gap: 8px; }

.tag-manager-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

/* ── GRUPPEN ────────────────────────────────────────────────────────────────── */

.gruppen-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.gruppe-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s;
}

.gruppe-card:hover { box-shadow: var(--shadow-lg); }
.gruppe-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.gruppe-name { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.gruppe-desc { font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.gruppe-meta { font-size: 12px; color: var(--text-3); }
.gruppe-card-actions { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.gruppe-edit-form { background: var(--surface-2); border-radius: var(--radius-sm); padding: 14px; margin-top: 8px; border: 1px solid var(--border); }

/* ── RESPONSIVE ─────────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
    .profile-header  { flex-direction: column; align-items: flex-start; }
    .profile-grid    { grid-template-columns: 1fr; }
    .form-row        { grid-template-columns: 1fr; }
    .card-grid       { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .settings-grid   { grid-template-columns: 1fr; }
    .gruppen-grid    { grid-template-columns: 1fr; }
    .login-box       { padding: 32px 22px; }
    main             { padding: 16px 14px; }
    .nav-links a span { display: none; }
}
