:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #e3e6eb;
    --text: #1b1f27;
    --muted: #6b7280;
    --accent: #2f5bea;
    --accent-soft: #e8eefe;
    --danger: #c62828;
    --danger-soft: #fdecec;
    --success: #1f7a4d;
    --success-soft: #e6f4ec;
    --warn: #9a6200;
    --warn-soft: #fff4dc;
    --sidebar: #12161f;
    --sidebar-text: #c4c9d4;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.01em; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
p { margin: .25rem 0 .75rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger); }
.count { font-size: 1rem; font-weight: 400; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
    width: 232px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
    display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-size: 1.05rem; padding: 4px 8px 18px; }
.brand:hover { text-decoration: none; }
.brand-dark { color: var(--text); padding: 0 0 18px; }
.brand-mark {
    width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff;
    display: inline-grid; place-items: center; font-weight: 700;
}
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a, .nav-soon { color: var(--sidebar-text); padding: 8px 10px; border-radius: 7px; font-size: .95rem; }
.nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav a.is-active { background: rgba(255, 255, 255, .1); color: #fff; font-weight: 600; }
.nav-soon { opacity: .45; cursor: default; display: flex; justify-content: space-between; }
.nav-soon em { font-style: normal; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; }
.nav-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #6f7686; padding: 16px 10px 4px; }
.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-foot .link-button { color: var(--sidebar-text); font-size: .85rem; }
.me { display: flex; align-items: center; gap: 10px; color: #fff; min-width: 0; }
.me:hover { text-decoration: none; }
.me small { display: block; color: #8a91a0; font-size: .75rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #2a3140; display: grid; place-items: center; font-weight: 600; flex-shrink: 0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 28px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.global-search { flex: 1; max-width: 520px; }
.menu-toggle { display: none; background: none; border: 0; font-size: 1.3rem; cursor: pointer; color: var(--text); }
.content { padding: 28px; max-width: 1280px; width: 100%; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }

/* Kort og grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px; }
.card.narrow { max-width: 560px; }
.table-card { padding: 0; overflow-x: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-2 .card { margin-bottom: 0; }
.customer-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); color: var(--text); display: flex; flex-direction: column; }
a.stat:hover { border-color: var(--accent); text-decoration: none; }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.9rem; font-weight: 650; letter-spacing: -.02em; }
.stat-note { color: var(--muted); font-size: .75rem; }
.stat-soon .stat-value { color: var(--muted); }

/* Formularer */
input[type=text], input[type=email], input[type=password], input[type=search], input[type=tel],
input[type=date], input[type=datetime-local], select, textarea {
    width: 100%; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; padding: 9px 11px; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 5px; font-size: .88rem; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 550;
    padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
    cursor: pointer; white-space: nowrap; list-style: none;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #2549c4; }
.btn-danger { background: var(--surface); border-color: #f0c4c4; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-block { width: 100%; }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link-button:hover { text-decoration: underline; }
.link-button.muted { color: var(--muted); }
.icon-button { background: none; border: 0; color: var(--muted); font-size: 1.15rem; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.icon-button:hover { background: var(--danger-soft); color: var(--danger); }
.danger-zone { margin-top: 8px; }

/* Segmented */
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.segmented a, .segmented label span { padding: 6px 12px; border-radius: 7px; color: var(--muted); font-size: .88rem; font-weight: 500; cursor: pointer; display: block; }
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented a.is-active, .segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented label { display: block; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-small a, .segmented-small label span { padding: 4px 10px; font-size: .82rem; }

.filters { display: flex; gap: 12px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.filters input[type=search] { max-width: 360px; }

/* Tabeller */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--border); background: #fafbfc; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table-click tbody tr { cursor: pointer; }
.table-click tbody tr:hover td { background: #fafbfd; }
.table .actions { display: flex; gap: 14px; justify-content: flex-end; }
.table .is-muted td { color: var(--muted); }
.table .empty { text-align: center; color: var(--muted); padding: 40px 16px; }

.pager { display: flex; gap: 4px; margin-top: 16px; }
.pager a { padding: 6px 11px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); }
.pager a.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Badges */
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; vertical-align: middle; }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-customer { background: var(--success-soft); color: var(--success); }
.badge-lead { background: var(--accent-soft); color: var(--accent); }
.badge-former { background: var(--surface-2); color: var(--muted); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }

/* Flash */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: .92rem; border: 1px solid transparent; }
.flash-success { background: var(--success-soft); color: var(--success); border-color: #c6e6d4; }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: #f3caca; }
.flash-info { background: var(--accent-soft); color: var(--accent); border-color: #cddafc; }

/* Lister */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.check-button { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #c3c8d1; background: none; cursor: pointer; margin-top: 2px; flex-shrink: 0; }
.check-button:hover { border-color: var(--success); background: var(--success-soft); }
.plain-list, .contact-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; flex-wrap: wrap; }
.plain-list li a { margin-right: auto; word-break: break-all; }
.contact-list li { display: flex; justify-content: space-between; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.contact-list li:last-child { border-bottom: 0; }
.add-contact { margin-top: 12px; }
.add-contact summary { width: 100%; }
.add-contact summary::-webkit-details-marker { display: none; }
.add-contact[open] summary { margin-bottom: 12px; }

.dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; font-size: .92rem; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }
.notes { margin-top: 14px; padding: 12px; background: var(--surface-2); border-radius: 8px; font-size: .9rem; }

/* Tidslinje */
.activity-form { display: flex; flex-direction: column; gap: 10px; padding-bottom: 18px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.activity-form .row { justify-content: space-between; }
.due-field { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; color: var(--muted); }
.due-field input { width: auto; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 14px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.timeline-actions { margin-left: auto; display: flex; gap: 12px; font-size: .85rem; }
.timeline-body { margin-top: 6px; white-space: normal; }
.timeline .is-open-task .badge { background: var(--warn-soft); color: var(--warn); }
.timeline .is-done .timeline-body { color: var(--muted); text-decoration: line-through; }

/* Login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 0%, #e8eefe 0, var(--bg) 45%); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px; box-shadow: 0 10px 30px rgba(16, 24, 40, .08); }
.auth-card h1 { font-size: 1.35rem; margin-bottom: .25rem; }
.auth-card form { margin-top: 18px; }
.code-input { font-size: 1.6rem !important; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.qr { display: grid; place-items: center; min-height: 200px; margin: 16px 0; }
.qr svg { width: 200px; height: 200px; }
.secret { display: block; margin-top: 8px; padding: 10px; text-align: center; letter-spacing: .08em; word-break: break-all; }
details summary { cursor: pointer; }

.empty-state { text-align: center; padding: 48px 16px; }
.empty-state h1 { justify-content: center; margin-bottom: 8px; }

/* Mobil */
@media (max-width: 1000px) {
    .customer-layout { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
    .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
    .nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
    .menu-toggle { display: block; }
    .topbar { padding: 0 16px; }
    .content { padding: 20px 16px; }
    .grid-2, .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .page-head { flex-wrap: wrap; }
}
