:root {
    --accent: #e11d2e;
    --bg: #f7f7f9;
    --card-bg: #ffffff;
    --text: #222;
    --muted: #777;
    --border: #e2e2e6;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

header.topbar {
    background: var(--accent);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}

header.topbar h1 {
    font-size: 1.1rem;
    margin: 0;
}

header.topbar a.button {
    background: #fff;
    color: var(--accent);
    text-decoration: none;
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
}

main {
    max-width: 900px;
    margin: 0 auto;
    padding: 16px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.toolbar select, .toolbar a.sort {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    font-size: 0.9rem;
    text-decoration: none;
    color: var(--text);
}

.toolbar a.sort.active {
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

.count {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 12px;
}

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

.card {
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.card .image-wrap {
    position: relative;
}

.card img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    background: #eee;
    display: block;
}

.badge {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 999px;
    color: #fff;
    background: #888;
}

.badge.gekauft {
    background: #b8860b;
}

.badge.uebergeben {
    background: #1e7b34;
}

.color-dot {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.card .info {
    padding: 8px 10px;
}

.card .manufacturer {
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.card .model {
    font-weight: 600;
    font-size: 0.95rem;
    margin-top: 2px;
}

.card .notes {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.card .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 10px 10px;
}

.card .actions a {
    font-size: 0.75rem;
    text-decoration: none;
    color: var(--muted);
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: 6px;
}

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

form.vehicle-form {
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 20px;
    max-width: 480px;
    margin: 0 auto;
}

form.vehicle-form label {
    display: block;
    font-weight: 600;
    margin: 16px 0 6px;
    font-size: 0.9rem;
}

form.vehicle-form label:first-of-type {
    margin-top: 0;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radio-option {
    display: flex !important;
    align-items: center;
    gap: 8px;
    font-weight: 400 !important;
    margin: 0 !important;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.radio-option input {
    width: auto;
}

form.vehicle-form select,
form.vehicle-form input[type="text"],
form.vehicle-form input[type="password"],
form.vehicle-form input[type="file"],
form.vehicle-form textarea {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 1rem;
    font-family: inherit;
}

form.vehicle-form textarea {
    resize: vertical;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
}

.color-option {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-weight: 400 !important;
    margin: 0 !important;
    padding: 8px 4px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

.color-option input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.color-option .swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.color-option .color-label {
    font-size: 0.7rem;
    color: var(--muted);
    text-align: center;
}

.color-option:has(input:checked) {
    border-color: var(--accent);
    background: #fdf1f2;
}

.color-option:has(input:checked) .color-label {
    color: var(--accent);
    font-weight: 600;
}

form.vehicle-form .hint {
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 4px;
}

form.vehicle-form button {
    width: 100%;
    margin-top: 24px;
    padding: 14px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
}

.error {
    background: #fdecea;
    color: #b3261e;
    border: 1px solid #f5c2c0;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.success {
    background: #e6f4ea;
    color: #1e7b34;
    border: 1px solid #b7dfc2;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.preview {
    margin-top: 10px;
    max-width: 100%;
    max-height: 220px;
    border-radius: 8px;
    display: none;
}

.rotate-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
}

.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.lightbox.open {
    display: flex;
}

.lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
}

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.login-card {
    width: 100%;
    max-width: 340px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    padding: 32px 24px;
}

.login-card h1 {
    text-align: center;
    margin: 0 0 24px;
    font-size: 1.3rem;
}

.login-card form {
    border: none;
    padding: 0;
    max-width: none;
    margin: 0;
}

.login-card input[type="password"] {
    font-size: 1.1rem;
    padding: 12px;
    text-align: center;
}

.back-link {
    display: inline-block;
    margin-bottom: 16px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
}

.stat-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 28px;
}

.stat-tile {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
}

.stat-number {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.1;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 4px;
}

.stats-section {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}

.stats-section h2 {
    font-size: 1rem;
    margin: 0 0 14px;
}

.bar-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bar-row {
    display: grid;
    grid-template-columns: minmax(90px, 30%) 1fr auto;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
}

.bar-row.no-track {
    grid-template-columns: 1fr auto;
}

.bar-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.bar-track {
    background: var(--bg);
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}

.bar-fill {
    background: var(--accent);
    height: 100%;
    border-radius: 999px;
    min-width: 3px;
}

.bar-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
    min-width: 1.5em;
}

.treemap {
    position: relative;
    width: 100%;
    height: 320px;
    border-radius: 10px;
    overflow: hidden;
}

.treemap-cell {
    position: absolute;
    box-sizing: border-box;
    border: 2px solid var(--card-bg);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 6px 8px;
    overflow: hidden;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}

.treemap-label {
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.treemap-value {
    font-size: 0.7rem;
    opacity: 0.9;
}

.swatch-inline {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}
