/* ============================================================
   Steuerkram – Haupt-Stylesheet
   ============================================================ */

:root {
    --color-bg:        #f4f6f9;
    --color-surface:   #ffffff;
    --color-border:    #d1d9e0;
    --color-primary:   #2563eb;
    --color-primary-h: #1d4ed8;
    --color-danger:    #dc2626;
    --color-danger-h:  #b91c1c;
    --color-success:   #16a34a;
    --color-warning:   #d97706;
    --color-text:      #1e293b;
    --color-muted:     #64748b;
    --color-nav-bg:    #1e293b;
    --color-nav-text:  #cbd5e1;
    --color-nav-hover: #334155;
    --color-nav-active:#2563eb;

    --radius:     6px;
    --shadow-sm:  0 1px 3px rgba(0,0,0,.08);
    --shadow:     0 2px 8px rgba(0,0,0,.10);
    --font:       'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono:  'Cascadia Code', 'Consolas', monospace;
    --nav-width:  220px;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: var(--font); background: var(--color-bg); color: var(--color-text); }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ── Layout ─────────────────────────────────────────────────── */
.app-layout {
    display: grid;
    grid-template-columns: var(--nav-width) 1fr;
    min-height: 100vh;
}

/* ── Sidebar Navigation ─────────────────────────────────────── */
.sidebar {
    background: var(--color-nav-bg);
    color: var(--color-nav-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 1.25rem 1rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid #334155;
    letter-spacing: .02em;
}

.sidebar-brand span { color: var(--color-nav-active); }

.sidebar-section {
    padding: .5rem 0 .25rem;
}

.sidebar-label {
    font-size: .65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #475569;
    padding: .5rem 1rem .25rem;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem 1rem;
    color: var(--color-nav-text);
    font-size: .875rem;
    border-left: 3px solid transparent;
    transition: background .15s, color .15s;
}

.sidebar nav a:hover {
    background: var(--color-nav-hover);
    color: #fff;
    text-decoration: none;
}

.sidebar nav a.active {
    background: rgba(37,99,235,.15);
    color: #93c5fd;
    border-left-color: var(--color-nav-active);
}

.sidebar nav a svg {
    width: 16px; height: 16px; flex-shrink: 0;
}

/* ── Main content ───────────────────────────────────────────── */
.main-content {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: .75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.page-body {
    padding: 1.5rem;
    flex: 1;
}

/* ── Flash Messages ─────────────────────────────────────────── */
.flash-list { margin-bottom: 1rem; }

.flash {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: .5rem;
    font-size: .875rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash-warning { background: #fef9c3; color: #854d0e; border: 1px solid #fef08a; }
.flash-info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.card-title { font-size: 1rem; font-weight: 600; }

.card-body { padding: 1.25rem; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .45rem .9rem;
    font-size: .875rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .15s, border-color .15s, opacity .15s;
    text-decoration: none !important;
    white-space: nowrap;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

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

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

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

.btn-success   { background: var(--color-success); color: #fff; }
.btn-success:hover { background: #15803d; }

.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-lg { padding: .65rem 1.25rem; font-size: 1rem; }

/* ── Forms ───────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }

label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    margin-bottom: .3rem;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="tel"],
input[type="url"],
input[type="password"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .875rem;
    font-family: var(--font);
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.input-error { border-color: var(--color-danger) !important; }
.error-text { font-size: .8rem; color: var(--color-danger); margin-top: .25rem; }

textarea { min-height: 80px; resize: vertical; }

.form-grid { display: grid; gap: 1rem; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

.form-row {
    display: flex;
    gap: .75rem;
    align-items: flex-end;
}

.form-hint { font-size: .78rem; color: var(--color-muted); margin-top: .2rem; }

/* ── Tables ──────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

thead th {
    background: var(--color-bg);
    padding: .6rem 1rem;
    text-align: left;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--color-muted);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--color-border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

td { padding: .65rem 1rem; vertical-align: middle; }

.td-right { text-align: right; }
.td-mono   { font-family: var(--font-mono); font-size: .82rem; }
.td-muted  { color: var(--color-muted); font-size: .82rem; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: .15rem .6rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-green   { background: #dcfce7; color: #166534; }
.badge-red     { background: #fee2e2; color: #991b1b; }
.badge-yellow  { background: #fef9c3; color: #854d0e; }
.badge-blue    { background: #dbeafe; color: #1e40af; }
.badge-gray    { background: #f1f5f9; color: #475569; }
.badge-purple  { background: #ede9fe; color: #6d28d9; }

/* ── Toolbar / Filter bar ────────────────────────────────────── */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    align-items: center;
    margin-bottom: 1rem;
}

.toolbar-left  { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.toolbar-right { margin-left: auto; display: flex; gap: .5rem; }

/* ── Stats / Dashboard Cards ─────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.stat-label { font-size: .78rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .4rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-meta  { font-size: .78rem; color: var(--color-muted); margin-top: .25rem; }

/* ── Beleg Detail (Split-Pane) ───────────────────────────────── */
.beleg-layout {
    display: grid;
    grid-template-columns: 1fr 520px;
    gap: 1.5rem;
    align-items: start;
}

.beleg-preview {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: unset;
}

.beleg-preview iframe,
.beleg-preview img {
    width: 100%;
    min-height: 1165px;
    border: none;
    display: block;
}

/* ── Invoice preview (DIN 5008) ──────────────────────────────── */
.invoice-preview thead th {
    text-transform: none;
    letter-spacing: normal;
    font-size: inherit;
    font-weight: normal;
    background: revert;
    padding: revert;
    white-space: revert;
    color: inherit;
    border-bottom: none;
}

.invoice-preview {
    background: #fff;
    padding: 2cm 2cm 2.5cm;
    max-width: 21cm;
    margin: 0 auto;
    box-shadow: var(--shadow);
    font-size: 11pt;
    line-height: 1.4;
    color: #000;
}

/*
 * Adressbereich: DIN 5008-Proportionen (50% = 85mm bei vollem A4-Preview).
 * Breakpoint: nav (220px) + page-body-padding (45px) + A4-max-width (794px) = 1059px.
 * Darunter stapeln sich die Spalten vertikal.
 */
.invoice-address {
    display: grid;
    grid-template-columns: 50% 1fr;
    gap: 1rem;
}

@media (max-width: 1059px) {
    .invoice-address {
        grid-template-columns: 1fr;
    }
    .invoice-address > div:last-child {
        justify-content: flex-start !important;
        border-top: 1px solid #ddd;
        padding-top: 0.75rem;
        font-size: .85rem;
    }
}

/* ── Modals ──────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-width: 500px;
    width: 95%;
    padding: 1.5rem;
}

.modal-title { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }
.modal-actions { display: flex; gap: .75rem; justify-content: flex-end; margin-top: 1.25rem; }

/* ── Pagination ──────────────────────────────────────────────── */
.pagination {
    display: flex;
    gap: .25rem;
    justify-content: center;
    margin-top: 1.25rem;
}

.pagination a, .pagination span {
    padding: .35rem .7rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .82rem;
    color: var(--color-text);
}

.pagination a:hover { background: var(--color-bg); text-decoration: none; }
.pagination .active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ── Utilities ───────────────────────────────────────────────── */
.text-muted  { color: var(--color-muted); }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-sm     { font-size: .82rem; }
.text-lg     { font-size: 1.1rem; }
.font-bold   { font-weight: 700; }
.font-mono   { font-family: var(--font-mono); }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.d-flex { display: flex; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.hidden { display: none; }

/* ── Print ───────────────────────────────────────────────────── */
@media print {
    .sidebar, .topbar, .btn, .toolbar, .pagination { display: none !important; }
    .main-content { grid-column: 1 / -1; }
    .page-body { padding: 0; }
}
