/* CARmove Custom Styles - Design System Implementation */

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--ground);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 23px;
    overflow-x: hidden;
}

/* Layout Grid */
.app {
    display: grid;
    grid-template-columns: 1fr;
    min-height: 100vh;
}

@media (min-width: 960px) {
    .app {
        grid-template-columns: var(--sidebar-width) 1fr;
    }
}

.app-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Sidebar */
.sidebar {
    display: none;
    background: var(--brand);
    color: var(--on-brand);
    padding: var(--space-4);
    flex-direction: column;
    gap: var(--space-1);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

@media (min-width: 960px) {
    .sidebar {
        display: flex;
    }
}

.sidebar .brandline {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 18px;
    margin-bottom: var(--space-3);
}

.sidebar .brandline img {
    width: 28px;
    height: 28px;
    border-radius: 6px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--on-brand);
    text-decoration: none;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    opacity: .85;
    font-size: 15px;
}

.sidebar a:hover {
    background: rgba(255,255,255,.1);
    opacity: 1;
}

.sidebar a.active {
    background: rgba(255,255,255,.16);
    opacity: 1;
    font-weight: 600;
}

.sidebar .sep {
    margin-top: auto;
    padding-top: var(--space-3);
    border-top: 1px solid rgba(255,255,255,.18);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar .sep .label {
    color: var(--on-brand);
    opacity: .7;
    margin-bottom: 4px;
}

.sidebar .version {
    font-size: 11px;
    opacity: .5;
    margin-top: var(--space-2);
    text-align: center;
}

/* Topbar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-4);
    gap: var(--space-3);
}

.topbar-left {
    display: flex;
    align-items: center;
    min-width: 0;
}

.page-title {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.tenant-name {
    font-size: 14px;
    color: var(--ink-muted);
}

.user-name {
    font-size: 14px;
    color: var(--ink-muted);
}

/* Page Content */
.page {
    flex: 1;
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--space-4);
    padding-bottom: 80px; /* Space for bottom nav on mobile */
}

@media (min-width: 960px) {
    .page {
        padding: var(--space-6);
        padding-bottom: var(--space-6);
    }
}

.page-narrow {
    max-width: 600px;
    margin: 0 auto;
    padding: var(--space-6);
}

/* Bottom Nav */
.bottomnav {
    display: flex;
    justify-content: space-around;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: 6px 0 4px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

@media (min-width: 960px) {
    .bottomnav {
        display: none;
    }
}

.bottomnav a, .bottomnav summary {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 11px;
    color: var(--ink-muted);
    text-decoration: none;
    min-width: 56px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.bottomnav a.active, .bottomnav summary.active {
    color: var(--brand-text);
    font-weight: 600;
}

/* Sheet (Mobile Menu) */
.sheet {
    position: relative;
    flex: 1;
    display: flex;
    justify-content: center;
}

.sheet summary {
    list-style: none;
}

.sheet summary::-webkit-details-marker {
    display: none;
}

.sheet-content {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    box-shadow: var(--shadow-float);
    padding: var(--space-4);
    display: none;
    flex-direction: column;
    gap: var(--space-2);
    max-height: 70vh;
    overflow-y: auto;
}

.sheet[open] .sheet-content {
    display: flex;
}

.sheet-content a {
    color: var(--ink);
    text-decoration: none;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
}

.sheet-content a:last-child {
    border-bottom: none;
}

.sheet-content .label {
    margin-top: var(--space-2);
    margin-bottom: 4px;
}

/* Components */
.icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 10px 16px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font: 600 15px/23px var(--font-sans);
    cursor: pointer;
    background: var(--brand);
    color: var(--on-brand);
    text-decoration: none;
    transition: background 150ms;
}

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

.btn:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.btn.secondary {
    background: var(--surface);
    color: var(--brand-text);
    border-color: var(--line-strong);
}

.btn.secondary:hover {
    background: var(--brand-tint);
}

.btn.ghost {
    background: transparent;
    color: var(--brand-text);
    border-color: transparent;
}

.btn.ghost:hover {
    background: var(--brand-tint);
}

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

.btn.icon-only {
    padding: 8px;
    border-radius: var(--radius-sm);
}

.btn.small {
    padding: 6px 12px;
    font-size: 13px;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 19px;
    font-weight: 600;
}

.badge.ok { background: var(--ok-tint); color: var(--ok); }
.badge.warn { background: var(--warn-tint); color: var(--warn); }
.badge.danger { background: var(--danger-tint); color: var(--danger); }
.badge.info { background: var(--info-tint); color: var(--info); }
.badge.neutral { background: var(--surface-sunken); color: var(--ink-muted); }

.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    padding: var(--space-4);
}

.kpi {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-width: 0;
}

.kpi .value {
    font-size: 36px;
    line-height: 40px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.kpi .value small {
    font-size: 15px;
    font-weight: 500;
    color: var(--ink-muted);
    margin-left: 4px;
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.table th {
    background: var(--surface-sunken);
    text-align: left;
    padding: 10px 12px;
    font-size: 12px;
    line-height: 16px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.table td {
    padding: 12px;
    border-top: 1px solid var(--line);
    vertical-align: middle;
}

.table tr:hover td {
    background: var(--brand-tint);
}

.table td.num, .table th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field label {
    font-size: 12px;
    line-height: 16px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.field input, .field select, .field textarea {
    font: 400 15px/23px var(--font-sans);
    color: var(--ink);
    background: var(--surface-sunken);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    width: 100%;
}

.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
    border-color: var(--line-strong);
}

.banner {
    display: flex;
    gap: var(--space-3);
    align-items: flex-start;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    background: var(--info-tint);
    color: var(--ink);
    border: 1px solid var(--line);
    margin-top: var(--space-4);
}

.banner.warn { background: var(--warn-tint); }
.banner.danger { background: var(--danger-tint); }
.banner.ok { background: var(--ok-tint); }

.banner strong { display: block; }
.banner .actions { margin-left: auto; display: flex; gap: var(--space-2); flex-shrink: 0; }

.label {
    font-size: 12px;
    line-height: 16px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.num {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

/* Compatibility Layer */
.grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

article, .card, article.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    padding: var(--space-4);
}

button, .button, input[type=submit] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 10px 16px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font: 600 15px/23px var(--font-sans);
    cursor: pointer;
    background: var(--brand);
    color: var(--on-brand);
    text-decoration: none;
}

button:hover, .button:hover, input[type=submit]:hover {
    background: var(--brand-strong);
}

button.secondary, .button.secondary, .outline, input[type=submit].secondary {
    background: var(--surface);
    color: var(--brand-text);
    border-color: var(--line-strong);
}

button.secondary:hover, .button.secondary:hover, .outline:hover {
    background: var(--brand-tint);
}

button.ghost, .button.ghost, .contrast {
    background: transparent;
    color: var(--brand-text);
    border-color: transparent;
}

a {
    color: var(--brand-text);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius-md);
    overflow: hidden;
}

table th {
    background: var(--surface-sunken);
    text-align: left;
    padding: 10px 12px;
    font-size: 12px;
    line-height: 16px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

table td {
    padding: 12px;
    border-top: 1px solid var(--line);
    vertical-align: middle;
}

.table-container {
    overflow-x: auto;
}

input, select, textarea {
    font: 400 15px/23px var(--font-sans);
    color: var(--ink);
    background: var(--surface-sunken);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    width: 100%;
}

label {
    font-size: 12px;
    line-height: 16px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--ink-muted);
    display: block;
    margin-bottom: 6px;
}

form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

details.dropdown, details.menu {
    position: relative;
}

details.dropdown summary, details.menu summary {
    list-style: none;
    cursor: pointer;
}

details.dropdown summary::-webkit-details-marker, details.menu summary::-webkit-details-marker {
    display: none;
}

details.dropdown ul, details.menu ul, .menu-list {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-float);
    list-style: none;
    padding: var(--space-2);
    margin: 4px 0 0;
    min-width: 150px;
    z-index: 1000;
}

details.dropdown li, details.menu li, .menu-list li {
    padding: 0;
}

details.dropdown li a, details.menu li a, .menu-list li a, .menu-list li button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--ink);
    text-decoration: none;
    background: none;
    border: none;
    font: inherit;
    cursor: pointer;
}

details.dropdown li a:hover, details.menu li a:hover, .menu-list li a:hover, .menu-list li button:hover {
    background: var(--brand-tint);
}

.notification, .banner {
    display: flex;
    gap: var(--space-3);
    align-items: flex-start;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    margin-top: var(--space-4);
}

.notification.is-neutral, .banner.is-neutral {
    background: var(--info-tint);
    color: var(--ink);
    border: 1px solid var(--line);
}

.notification.is-positive, .banner.is-positive {
    background: var(--ok-tint);
    color: var(--ink);
    border: 1px solid var(--line);
}

.notification.is-negative, .banner.is-negative {
    background: var(--danger-tint);
    color: var(--ink);
    border: 1px solid var(--line);
}

.container {
    width: 100%;
    max-width: none;
    padding: 0;
    margin: 0;
}

dialog {
    border: none;
    border-radius: var(--radius-md);
    padding: 0;
    width: 90%;
    max-width: 500px;
    background: var(--surface);
    color: var(--ink);
}

dialog::backdrop {
    background-color: rgba(0,0,0,0.5);
}

.badge-new { background: var(--info-tint); color: var(--info); }
.badge-ready { background: var(--ok-tint); color: var(--ok); }
.badge-sold { background: var(--surface-sunken); color: var(--ink-muted); }
.badge-archived { background: var(--warn-tint); color: var(--warn); }
.badge-default { background: var(--surface-sunken); color: var(--ink-muted); }

.stock-ok { color: var(--ok); font-weight: 600; }
.stock-warn { color: var(--warn); font-weight: 600; }
.stock-alert { color: var(--danger); font-weight: 600; }

.text-big {
    font-size: 36px;
    line-height: 40px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.feedback-fab {
    position: fixed;
    bottom: 84px;
    right: 20px;
    z-index: 1000;
    background-color: var(--brand);
    color: var(--on-brand);
    border: none;
    border-radius: 999px;
    padding: 12px 20px;
    box-shadow: var(--shadow-float);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
}

@media (min-width: 960px) {
    .feedback-fab {
        bottom: 20px;
    }
}

.feedback-fab:hover {
    background-color: var(--brand-strong);
}

.feedback-actions {
    display: flex;
    gap: 10px;
    margin-top: 1rem;
    justify-content: flex-end;
}

.feedback-thanks {
    padding: 1rem;
}

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

/* Kopfzeile am Handy: nur Symbole, Namen ausblenden */
@media (max-width: 959px) {
    .topbar .tenant-name,
    .topbar .user-name { display: none; }
}

/* Kennzahl-Zustände und Hilfsklassen für Listen, Formulare, Login (Phase B/C) */
.kpi.is-ok .value { color: var(--ok); }
.kpi.is-warn .value { color: var(--warn); }
.kpi.is-danger .value { color: var(--danger); }
.kpi .badge { align-self: flex-start; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-left: auto; }
.filter-bar { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; margin-bottom: var(--space-4); }
.filter-bar .field { flex: 1 1 200px; min-width: 0; }
.filter-bar .btn { flex: 0 0 auto; }
.empty { padding: var(--space-8) var(--space-4); text-align: center; color: var(--ink-muted); background: var(--surface); border-radius: var(--radius-md); border: 1px dashed var(--line-strong); }
.field-row { display: grid; grid-template-columns: 1fr; gap: var(--space-3); }
@media (min-width: 600px) { .field-row { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); } }
.form { display: flex; flex-direction: column; gap: var(--space-4); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: flex-end; padding-top: var(--space-3); border-top: 1px solid var(--line); }
.card.narrow { max-width: 720px; }
.mono { font-family: var(--font-mono); font-size: 13px; }
.muted { color: var(--ink-muted); }
.check { display: flex; align-items: center; gap: var(--space-2); font-size: 15px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.check input { width: auto; }
.login-card { max-width: 420px; margin: var(--space-8) auto; }
.brand-wordmark { font-family: var(--font-display); font-weight: 700; font-size: 28px; color: var(--brand-text); text-align: center; margin-bottom: var(--space-4); }
.is-unread { font-weight: 600; }
.text-ok { color: var(--ok); font-weight: 600; }
.text-warn { color: var(--warn); font-weight: 600; }
.text-danger { color: var(--danger); font-weight: 600; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line-strong); }

/* Filterleiste: waagerecht, unabhängig von den allgemeinen form-Regeln */
form.filter-bar { display: flex; flex-direction: row; flex-wrap: wrap; align-items: flex-end; justify-content: flex-start; gap: var(--space-3); margin: 0 0 var(--space-4); max-width: none; }
form.filter-bar .field { flex: 1 1 200px; margin: 0; }
form.filter-bar .field select, form.filter-bar .field input { margin: 0; }
.page-head:empty, .page-head > .page-actions:empty { display: none; }

/* Detailseiten, Hof, Kalender (Phase D) */
.kv { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr; gap: var(--space-2) var(--space-3); margin: 0; }
.kv dt { font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-muted); align-self: center; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.spot { padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-1); }
.spot .label { margin: 0; }
.calendar { table-layout: fixed; }
.calendar th, .calendar td { vertical-align: top; min-height: 96px; }
.calendar td .badge { display: inline-flex; margin: 2px 2px 0 0; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-2); }
.photo-grid img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius-sm); }
.detail-grid { display: grid; grid-template-columns: 1fr; gap: var(--space-4); align-items: start; }
@media (min-width: 1100px) { .detail-grid { grid-template-columns: 2fr 3fr; } }
.detail-grid .card { min-width: 0; }

/* Kontrollkästchen und Radios nicht auf volle Breite ziehen */
.field input[type="checkbox"], .field input[type="radio"], input[type="checkbox"], input[type="radio"] { width: auto; margin: 0; }
.field > input[type="checkbox"] { align-self: flex-start; }

/* Stellplatz-Karte: Badges nicht dehnen */
.spot .badge { align-self: flex-start; }
