:root {
    --bg-true-black: #000000;
    --bg-panel: #141414;
    --bg-card: #1e1e1e;
    --bg-input: #2a2a2a;
    --primary-purple: #8a2be2;
    --primary-hover: #9b4ce5;
    --text-main: #f5f5f5;
    --text-muted: #a0a0a0;
    --border: #333333;
    --accent-blue: #2563eb;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-true-black);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-layout {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    border-bottom: 1px solid var(--border);
}

.logo {
    width: 40px;
    height: 40px;
    background-color: var(--primary-purple);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
}

.brand-text h3 {
    font-size: 1rem;
    margin: 0;
}

.brand-text small {
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 20px;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-item:hover, .nav-item.active {
    color: var(--text-main);
    background-color: rgba(138, 43, 226, 0.1);
    border-left: 3px solid var(--primary-purple);
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    border-bottom: 1px solid var(--border);
    background-color: var(--bg-true-black);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.back-btn {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn {
    padding: 8px 16px;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background-color: var(--accent-blue);
    color: white;
}

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

.btn-icon {
    background: none;
    color: var(--text-main);
    padding: 8px;
}

.editor-workspace {
    flex: 1;
    display: flex;
    overflow: auto;
    padding: 30px;
    gap: 40px;
}

/* Form Area */
.form-area {
    flex: 1;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-card {
    background-color: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border);
}

.action-card {
    display: flex;
    flex-direction: column;
}

.action-btn {
    background: none;
    border: none;
    color: var(--accent-blue);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
}

.form-group-row {
    display: flex;
    gap: 15px;
}

.form-group-row .form-group {
    flex: 1;
}

label {
    font-size: 0.9rem;
    color: var(--text-muted);
}

input {
    background-color: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 10px 15px;
    border-radius: 6px;
    font-family: inherit;
}

input:focus {
    outline: none;
    border-color: var(--primary-purple);
}

.totals-summary {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    width: 250px;
}

.grand-total {
    font-size: 1.2rem;
    font-weight: bold;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

/* Live Preview Area */
.preview-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow: hidden;
    padding: 20px;
    min-width: 0;
}

.preview-area-inner {
    display: flex;
    justify-content: center;
    max-width: 100%;
    overflow: hidden;
}

.a4-scaler {
    width: var(--a4-scaled-w, 210mm);
    height: var(--a4-scaled-h, 297mm);
    overflow: hidden;
    flex-shrink: 0;
}

.a4-paper {
    background-color: #ffffff;
    color: #000000;
    width: 210mm;
    height: 297mm;
    box-sizing: border-box;
    padding: 18mm;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    position: relative;
    font-family: Arial, sans-serif;
    font-size: 9pt;
    line-height: 1.25;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    --inv-footer-reserve: 32mm;
    transform-origin: top left;
    transform: scale(var(--a4-scale, 1));
}

.inv-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-bottom: var(--inv-footer-reserve);
}

.inv-body > :last-child {
    margin-bottom: 0;
}

/* Invoice Layout (German PDF look) */
.inv-top {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 6px 10px;
    margin-bottom: 26px;
}

.inv-sender-line {
    font-size: 7pt;
    text-decoration: underline;
    color: #555;
}

.inv-sender-name {
    text-align: right;
    font-size: 14pt;
    font-weight: 700;
}

.inv-receiver {
    grid-column: 1 / 2;
    font-size: 10pt;
    line-height: 1.5;
    margin-top: 2px;
}

.inv-title-meta {
    margin-bottom: 45px;
}

.inv-title-line {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 10px;
}

.inv-title {
    font-size: 11pt;
    font-weight: 700;
}

.inv-title-rule {
    height: 1px;
    background: #777;
    flex: 1;
}

.inv-meta {
    width: 52%;
    margin-left: auto;
}

.inv-meta-row {
    display: grid;
    grid-template-columns: auto auto;
    gap: 5px 30px;
    font-size: 9pt;
    margin: 6px 0;
}

.inv-meta-strong {
    font-weight: 700;
}

.text-right { text-align: right; }
.text-left { text-align: left; }
.text-center { text-align: center; }

.preview-intro {
    margin-bottom: 85px;
    margin-top: 35px;
    line-height: 1.5;
}

.intro-paragraph {
    margin: 0 0 10px 0;
}

.intro-paragraph:last-child {
    margin-bottom: 0;
}

.intro-label {
    font-weight: 700;
}

.intro-amount {
    font-weight: 700;
}

.intro-ref {
    font-weight: 700;
}

.intro-date {
    margin-top: 12px;
}

.intro-signoff {
    margin-top: 14px;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.preview-table th {
    background-color: #e0e0e0;
    padding: 6px 8px;
    font-weight: 700;
    border-bottom: 1px solid #ccc;
    border-top: 1px solid #ccc;
}

.preview-table td {
    padding: 6px 8px;
    border-bottom: 1px solid #eee;
    vertical-align: top;
}

.text-muted {
    color: #666;
}

.inv-totals {
    width: 55%;
    margin-left: auto;
    margin-top: 10px;
    margin-bottom: 18px;
}

.inv-totals-row {
    display: grid;
    grid-template-columns: 1fr 90px;
    gap: 8px 18px;
    margin: 8px 0;
}

.inv-totals-grand {
    display: grid;
    grid-template-columns: 1fr 90px;
    gap: 8px 18px;
    margin-top: 10px;
    font-weight: bold;
}

.inv-totals-grand > div {
    background: #e0e0e0;
    padding: 6px 10px;
}

.inv-footer {
    position: absolute;
    left: 18mm;
    right: 18mm;
    bottom: 12mm;
    display: grid;
    grid-template-columns: 90px 1fr 90px;
    column-gap: 10px;
    align-items: start;
    font-size: 6pt;
    border-top: 1px solid #bbb;
    padding-top: 23px;
    page-break-inside: avoid;
    break-inside: avoid;
}

.inv-footer-left {
    width: 90px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.inv-qr-text {
    line-height: 1.15;
    font-size: 5.8pt;
}

.inv-qr-title {
    font-weight: 700;
    margin-bottom: 1px;
}

.inv-footer-center {
    grid-column: 2;
    width: 100%;
    max-width: 125mm;
    justify-self: center;
    text-align: center;
    line-height: 1.2;
    font-size: 5.8pt;
}

.inv-qr-url {
    word-break: break-word;
    line-height: 1.15;
}

.inv-footer-page {
    display: inline-block;
    margin-top: 6px;
    white-space: nowrap;
}

#qrcode img,
#qrcode canvas {
    width: 52px !important;
    height: 52px !important;
}

/* PRINT MEDIA QUERY */
@media print {
    html,
    body {
        width: 210mm;
        height: 297mm;
        margin: 0;
        padding: 0;
        background: white;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .no-print,
    .sidebar {
        display: none !important;
    }
    .app-layout {
        height: auto;
        display: block;
    }
    .editor-workspace {
        padding: 0;
        overflow: visible;
        display: block;
    }
    .preview-area {
        padding: 0;
        justify-content: flex-start;
    }
    .a4-paper {
        box-shadow: none;
        width: 210mm;
        height: 297mm;
        padding: 18mm;
        margin: 0;
        overflow: hidden;
        font-size: 8.5pt;
        line-height: 1.2;
        page-break-inside: avoid;
    }
    .inv-body {
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    @page {
        size: A4;
        margin: 0;
    }
}

/* Data Tables (Kunden, Artikel, etc.) */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    background: rgba(255,255,255,0.02);
}

.data-table tbody tr:hover {
    background: rgba(138, 43, 226, 0.05);
}

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

/* ─── Dashboard: Vibrant Stat Cards ─── */
.stat-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}
@media (max-width: 1200px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px) { .stat-row { grid-template-columns: 1fr; } }

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform .15s, border-color .2s;
}
.stat-card:hover {
    transform: translateY(-2px);
    border-color: rgba(138,43,226,0.35);
}
.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}
.stat-icon.purple { background: linear-gradient(135deg, #8a2be2, #b366ff); color: #fff; }
.stat-icon.cyan   { background: linear-gradient(135deg, #0ea5e9, #22d3ee); color: #fff; }
.stat-icon.green  { background: linear-gradient(135deg, #10b981, #34d399); color: #fff; }
.stat-icon.pink   { background: linear-gradient(135deg, #e11d48, #f43f5e); color: #fff; }
.stat-icon.amber  { background: linear-gradient(135deg, #f59e0b, #fbbf24); color: #fff; }
.stat-icon.violet { background: linear-gradient(135deg, #7c3aed, #a78bfa); color: #fff; }

.stat-body .stat-num {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1;
}
.stat-body .stat-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ─── Business Switcher in Sidebar ─── */
.biz-switcher {
    margin: 0 16px 12px;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(138,43,226,0.04);
}
.biz-switcher label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    display: block;
    margin-bottom: 6px;
}
.biz-switcher select {
    width: 100%;
    background: var(--bg-input);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}
.biz-switcher select:focus { outline: none; border-color: var(--primary-purple); }
.biz-name-display {
    display: none;
}

/* ─── Dashboard Activity / Latest Table ─── */
.dash-table-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px;
}
.dash-table-wrapper h3 {
    font-size: 16px;
    margin-bottom: 14px;
    display:flex;
    align-items:center;
    gap:10px;
    color: var(--text-main);
}
.dash-table-wrapper h3 i { color: var(--primary-purple); }
.dash-table th { background: rgba(255,255,255,0.03); }
.badge-green { background: rgba(16,185,129,0.12); color: #34d399; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-blue  { background: rgba(37,99,235,0.12); color: #60a5fa; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-amber { background: rgba(245,158,11,0.12); color: #fbbf24; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-gray  { background: rgba(255,255,255,0.06); color: #a0a0a0; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }

/* ─── Settings: Centered + Vibrant ─── */
.settings-container {
    display: flex;
    justify-content: center;
    padding: 30px;
    overflow-y: auto;
}
.settings-inner {
    width: 100%;
    max-width: 800px;
}
.settings-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    margin-bottom: 22px;
}
.settings-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.settings-card h3 .icon-col { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.settings-card h3 .icon-col.purple { background: rgba(138,43,226,0.15); color: #b366ff; }
.settings-card h3 .icon-col.cyan   { background: rgba(14,165,233,0.15); color: #22d3ee; }
.settings-card h3 .icon-col.green  { background: rgba(16,185,129,0.15); color: #34d399; }

/* Business list table */
.biz-table td, .biz-table th { padding: 10px 12px; font-size: 14px; }
.biz-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); }
.biz-row { cursor: pointer; transition: background .15s; }
.biz-row:hover { background: rgba(138,43,226,0.06); }
.biz-row.active { background: rgba(138,43,226,0.12); border-left: 3px solid var(--primary-purple); }
