:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #06b6d4;
    --dark: #1e293b;
    --light: #f8fafc;
    --white: #ffffff;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--gray-800);
    background: var(--gray-100);
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: linear-gradient(180deg, var(--dark) 0%, var(--gray-800) 100%);
    color: var(--white);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--white);
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.sidebar-logo span {
    background: var(--primary);
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.nav-section {
    margin-bottom: 24px;
}

.nav-section-title {
    padding: 8px 20px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--gray-400);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--gray-300);
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--white);
    text-decoration: none;
}

.nav-link.active {
    background: rgba(37, 99, 235, 0.2);
    color: var(--white);
    border-left-color: var(--primary);
}

.nav-link svg {
    width: 20px;
    height: 20px;
    opacity: 0.7;
}

.nav-link.active svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 13px;
}

.sidebar-footer a {
    color: var(--gray-400);
}

.sidebar-footer a:hover {
    color: var(--white);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 24px 32px;
}

.page-header {
    margin-bottom: 24px;
}

.page-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 8px;
}

.page-subtitle {
    color: var(--gray-500);
}

/* Cards */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-icon.primary {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
}

.stat-icon.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.stat-icon.warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.stat-icon.danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.stat-content h3 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.stat-content p {
    color: var(--gray-500);
    font-size: 13px;
}

.stat-subtitle {
    font-size: 11px;
    color: var(--gray-400);
    margin-top: 2px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

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

th {
    background: var(--gray-100);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-600);
}

tr:hover {
    background: var(--gray-100);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 50px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.badge-info {
    background: rgba(6, 182, 212, 0.1);
    color: var(--info);
}

.badge-secondary {
    background: var(--gray-100);
    color: var(--gray-600);
}

.badge-dark {
    background: var(--gray-200);
    color: var(--gray-700);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn:hover {
    text-decoration: none;
    transform: translateY(-1px);
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-success {
    background: var(--success);
    color: var(--white);
}

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

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

.btn-icon {
    padding: 8px;
}

.btn-group {
    display: flex;
    gap: 8px;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--gray-700);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-control::placeholder {
    color: var(--gray-400);
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* Alerts */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

/* Login Page */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--dark) 0%, var(--gray-800) 100%);
}

.login-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    padding: 40px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h1 {
    font-size: 28px;
    margin-bottom: 8px;
}

.login-header p {
    color: var(--gray-500);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-500);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    margin-bottom: 8px;
    color: var(--gray-700);
}

/* Actions Column */
.actions {
    white-space: nowrap;
}

/* ===========================================
   MOBILE RESPONSIVE STYLES
   =========================================== */

/* Mobile Header with Hamburger */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: linear-gradient(180deg, var(--dark) 0%, var(--gray-800) 100%);
    z-index: 200;
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-md);
}

.mobile-header .mobile-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--white);
    font-weight: 700;
    font-size: 18px;
    text-decoration: none;
}

.mobile-header .mobile-logo span {
    background: var(--primary);
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.hamburger-btn {
    background: transparent;
    border: none;
    color: var(--white);
    cursor: pointer;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
}

.hamburger-btn span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--white);
    border-radius: 2px;
    transition: all 0.3s;
}

.hamburger-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.hamburger-btn.active span:nth-child(2) {
    opacity: 0;
}

.hamburger-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    /* Über Header (200), unter Sidebar (250) */
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    opacity: 1;
}

/* Floating Action Button */
.fab {
    display: none;
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    border: none;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    z-index: 100;
    font-size: 24px;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none;
}

.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
    text-decoration: none;
    color: var(--white);
}

/* Responsive Breakpoint */
@media (max-width: 768px) {

    /* Hide elements on mobile */
    .hide-on-mobile {
        display: none !important;
    }

    /* Show Mobile Header */
    .mobile-header {
        display: flex;
    }

    /* Sidebar as Off-Canvas Drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        transition: left 0.3s ease;
        z-index: 175;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-overlay {
        display: block;
        pointer-events: none;
    }

    .sidebar-overlay.active {
        pointer-events: auto;
    }

    /* Main Content adjustments */
    .main-content {
        margin-left: 0;
        padding: 72px 16px 80px 16px;
    }

    .app-container {
        flex-direction: column;
    }

    /* Stats Grid */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
    }

    /* Page Header */
    .page-header {
        margin-bottom: 16px;
    }

    .page-title {
        font-size: 20px;
    }

    /* Card adjustments */
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 12px 16px;
    }

    .card-header .btn-group {
        width: 100%;
    }

    .card-header .btn-group .btn {
        flex: 1;
        justify-content: center;
    }

    .card-body {
        padding: 12px 16px;
    }

    /* Responsive Tables as Cards */
    .table-responsive {
        overflow-x: visible;
    }

    .table-responsive table,
    .table-responsive thead,
    .table-responsive tbody,
    .table-responsive th,
    .table-responsive td,
    .table-responsive tr {
        display: block;
    }

    .table-responsive thead {
        display: none;
    }

    .table-responsive tr {
        background: var(--white);
        margin-bottom: 12px;
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        padding: 12px 16px;
        border: 1px solid var(--gray-200);
    }

    .table-responsive tr:hover {
        background: var(--white);
    }

    .table-responsive td {
        padding: 8px 0;
        border-bottom: 1px solid var(--gray-100);
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        text-align: right;
        word-break: break-word;
        gap: 8px;
    }

    .table-responsive td:last-child {
        border-bottom: none;
        padding-top: 12px;
    }

    .table-responsive td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--gray-600);
        text-align: left;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .table-responsive td.actions {
        justify-content: flex-end;
        gap: 8px;
    }

    .table-responsive td.actions::before {
        display: none;
    }

    /* Touch-friendly Buttons */
    .btn {
        min-height: 44px;
        padding: 12px 16px;
    }

    .btn-sm {
        min-height: 40px;
        padding: 10px 14px;
    }

    .btn-icon {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
    }

    .btn-group {
        flex-wrap: wrap;
    }

    /* Forms */
    .form-control {
        min-height: 44px;
        font-size: 16px;
        /* Prevents iOS zoom */
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* Invoice Items - Stacked Layout for Mobile */
    .invoice-item-row.invoice-item-header {
        display: none !important;
    }

    .invoice-item-row {
        display: flex !important;
        flex-direction: column;
        gap: 12px;
        padding: 16px;
        margin-bottom: 16px;
        background: var(--bg-secondary);
        border-radius: var(--radius);
        border: 1px solid var(--gray-200);
        position: relative;
    }

    .invoice-item-row>div,
    .invoice-item-row>input,
    .invoice-item-row>select {
        width: 100% !important;
    }

    .invoice-item-row input,
    .invoice-item-row select {
        padding: 12px;
        font-size: 16px;
        width: 100% !important;
    }

    .invoice-item-row .btn-remove {
        position: absolute;
        top: 8px;
        right: 8px;
        width: 36px;
        height: 36px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
    }

    /* Mobile Labels */
    .mobile-label {
        display: block !important;
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--gray-500);
        margin-bottom: 4px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .invoice-item-row .item-field {
        display: flex !important;
        flex-direction: column;
    }

    /* Mini-Grid für Zahlenfelder auf Mobile */
    .invoice-item-row .item-numbers {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .invoice-item-row .item-numbers-3 {
        display: grid !important;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 12px;
    }

    /* Show empty divs on mobile for grid alignment */
    .item-numbers>div:empty,
    .item-numbers-3>div:empty {
        display: block !important;
    }

    /* Tabs */
    .tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 2px;
    }

    .tab {
        white-space: nowrap;
        padding: 12px 16px;
        flex-shrink: 0;
    }

    /* Show FAB */
    .fab {
        display: flex;
    }

    /* Hide desktop-only new invoice button on header */
    .card-header a[href="/invoices/create"] {
        display: none;
    }

    /* Alerts */
    .alert {
        padding: 12px 14px;
        font-size: 13px;
    }

    /* Login Page */
    .login-card {
        margin: 16px;
        padding: 24px;
    }

    .login-header h1 {
        font-size: 22px;
    }

    /* Empty State */
    .empty-state {
        padding: 40px 16px;
    }

    /* Mobile visibility utilities */
    .mobile-hide {
        display: none !important;
    }

    .mobile-show {
        display: inline-flex !important;
    }

    /* Actions dropdown or buttons */
    .actions {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        justify-content: flex-end;
    }

    .actions .btn {
        flex: 1;
        min-width: 80px;
        justify-content: center;
        font-size: 12px;
        padding: 8px 10px;
        min-height: 36px;
    }

    /* Search input in sidebar */
    .sidebar-search {
        padding: 76px 16px 16px;
        /* 56px Header + 20px Abstand */
    }

    .sidebar-search .search-input {
        font-size: 16px;
        padding: 12px;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .stats-grid {
        gap: 8px;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .stat-content h3 {
        font-size: 20px;
    }

    .page-title {
        font-size: 18px;
    }

    .fab {
        bottom: 16px;
        right: 16px;
    }

    /* Stack action buttons vertically on very small screens */
    .table-responsive td.actions {
        flex-direction: column;
    }

    .table-responsive td.actions .btn {
        width: 100%;
    }
}

/* Invoice Items Form */
.invoice-items {
    margin-bottom: 20px;
}

/* Hide mobile labels on desktop */
.mobile-label {
    display: none;
}

/* Desktop: wrapper divs should disappear and let inputs flow in grid */
.item-numbers .item-field,
.item-numbers-3 .item-field,
.item-numbers,
.item-numbers-3 {
    display: contents;
}

/* But description field should stay as block */
.invoice-item-row>.item-field {
    display: flex;
    flex-direction: column;
}

/* Hide the empty div placeholders on desktop */
.item-numbers>div:empty,
.item-numbers-3>div:empty {
    display: none;
}

.invoice-item-row {
    display: grid;
    grid-template-columns: 2fr 80px 80px 100px 80px 40px;
    gap: 10px;
    margin-bottom: 10px;
    align-items: end;
}

.invoice-item-row>.item-field input {
    width: 100%;
}

.invoice-item-row input {
    padding: 8px 10px;
    font-size: 13px;
}

.invoice-item-row .btn-remove {
    padding: 8px;
    background: var(--gray-200);
    color: var(--danger);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
}

/* Tabbed Settings */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 20px;
}

.tab {
    padding: 12px 20px;
    color: var(--gray-500);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--gray-700);
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Code Editor */
.code-editor {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
    line-height: 1.6;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    min-height: 300px;
}

/* Utilities */
.text-right {
    text-align: right;
}

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

.text-muted {
    color: var(--gray-500);
}

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

.mb-0 {
    margin-bottom: 0;
}

.mb-2 {
    margin-bottom: 8px;
}

.mb-4 {
    margin-bottom: 16px;
}

.mt-4 {
    margin-top: 16px;
}

.d-flex {
    display: flex;
}

.justify-between {
    justify-content: space-between;
}

.align-center {
    align-items: center;
}

.gap-2 {
    gap: 8px;
}

.gap-4 {
    gap: 16px;
}

/* Mobile visibility utilities */
.mobile-hide {
    display: inline-flex;
}

.mobile-show {
    display: none;
}

/* Sidebar Search */
.sidebar-search {
    padding: 12px 12px 0px;
}

.sidebar-search .search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
    font-size: 13px;
    font-family: inherit;
    transition: all 0.2s;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.sidebar-search .search-input::placeholder {
    color: var(--gray-400);
    opacity: 1;
}

.sidebar-search .search-input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary);
}

/* Button Outline */
.btn-outline {
    background: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}

.btn-outline:hover {
    background: var(--gray-100);
}

/* Alert Info */
.alert-info {
    background: rgba(6, 182, 212, 0.1);
    color: var(--info);
    border: 1px solid rgba(6, 182, 212, 0.2);
}