/* ===================================================
   Buchhaltungssystem - Hauptstylesheet
   =================================================== */

/* --- CSS Variablen / Theme --- */
:root {
    --primary: #2c3e50;
    --primary-light: #34495e;
    --primary-dark: #1a252f;
    --accent: #3498db;
    --accent-hover: #2980b9;
    --success: #27ae60;
    --success-bg: #d4edda;
    --warning: #f39c12;
    --warning-bg: #fff3cd;
    --danger: #e74c3c;
    --danger-bg: #f8d7da;
    --info: #17a2b8;
    --info-bg: #d1ecf1;
    --bg: #f0f2f5;
    --bg-white: #ffffff;
    --text: #333333;
    --text-light: #666666;
    --text-muted: #999999;
    --border: #dee2e6;
    --border-light: #e9ecef;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --radius: 8px;
    --radius-sm: 4px;
    --sidebar-width: 260px;
    --transition: all 0.2s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* --- Sidebar Navigation --- */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--primary);
    color: white;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: var(--transition);
    overflow-y: auto;
}
.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    text-align: center;
}
.sidebar-header .logo-text { font-size: 1.6rem; margin: 0; font-weight: 700; }
.sidebar-header .logo-subtitle { font-size: 0.8rem; opacity: 0.7; }
.nav-menu {
    list-style: none;
    padding: 10px 0;
    margin: 0;
    flex: 1;
}
.nav-item { margin: 0; }
.nav-link {
    display: flex;
    align-items: center;
    padding: 11px 20px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: var(--transition);
    border-left: 3px solid transparent;
}
.nav-link:hover {
    background: rgba(255,255,255,0.1);
    color: white;
    text-decoration: none;
}
.nav-link.active {
    background: rgba(255,255,255,0.15);
    color: white;
    border-left-color: var(--accent);
    font-weight: 600;
}
.nav-icon { margin-right: 10px; font-size: 1.1rem; }
.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    text-align: center;
}
.sidebar-footer .user-info { margin-bottom: 10px; }
.sidebar-footer .user-info strong { display: block; font-size: 0.9rem; }
.sidebar-footer .user-info small { opacity: 0.7; font-size: 0.75rem; }

/* --- Main Content --- */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.top-bar {
    background: var(--bg-white);
    padding: 15px 30px;
    display: flex;
    align-items: center;
    gap: 20px;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.page-title {
    font-size: 1.3rem;
    margin: 0;
    flex: 1;
    color: var(--primary);
}
.welcome-text { color: var(--text-light); font-size: 0.9rem; }
.hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
}
.content-wrapper {
    padding: 25px 30px;
    flex: 1;
}

/* --- Page Header --- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}
.page-header h2 { margin: 0; color: var(--primary); }
.page-header-right { display: flex; gap: 10px; }

/* --- Cards --- */
.form-card {
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}
.form-card h3 {
    margin-top: 0;
    margin-bottom: 18px;
    color: var(--primary);
    font-size: 1.1rem;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-light);
}
.dashboard-card {
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}
.dashboard-card h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: var(--primary);
    font-size: 1.05rem;
}
.card-footer {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
}

/* --- KPI Cards --- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}
.kpi-card {
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    border-left: 4px solid var(--accent);
    transition: var(--transition);
}
.kpi-card:hover { box-shadow: var(--shadow-lg); }
.kpi-card.kpi-blue { border-left-color: var(--accent); }
.kpi-card.kpi-green { border-left-color: var(--success); }
.kpi-card.kpi-orange { border-left-color: var(--warning); }
.kpi-card.kpi-red { border-left-color: var(--danger); }
.kpi-icon { font-size: 2rem; }
.kpi-data h3 { margin: 0; font-size: 1.3rem; color: var(--primary); }
.kpi-data p { margin: 3px 0 0 0; color: var(--text-light); font-size: 0.85rem; }

/* --- Dashboard Grid --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: var(--text);
    font-size: 0.9rem;
}
.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    transition: var(--transition);
    background: var(--bg-white);
    color: var(--text);
}
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(52,152,219,0.15);
}
.form-control[readonly] {
    background: #f5f5f5;
    color: var(--text-light);
}
select.form-control {
    appearance: auto;
    background-image: none;
}
textarea.form-control { resize: vertical; min-height: 80px; }
.form-text { font-size: 0.8rem; color: var(--text-muted); margin-top: 3px; display: block; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 25px;
}
.form-row {
    display: flex;
    gap: 15px;
}
.form-row .half { flex: 1; }
.form-section h3 {
    font-size: 1rem;
    margin-top: 0;
    margin-bottom: 15px;
    color: var(--primary);
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}
.form-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    align-items: center;
}
.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: normal !important;
}
.checkbox-label input[type="checkbox"] {
    width: auto;
    accent-color: var(--accent);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    background: var(--bg-white);
    color: var(--text);
    line-height: 1.4;
}
.btn:hover { background: #f0f0f0; text-decoration: none; color: var(--text); }
.btn-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: white; }
.btn-secondary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.btn-secondary:hover { background: var(--primary-light); color: white; }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-success:hover { background: #219a52; color: white; }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #c0392b; color: white; }
.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-outline:hover { background: #f0f0f0; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-block { display: flex; justify-content: center; width: 100%; }
.inline-form { display: inline-flex; gap: 5px; align-items: center; }
.action-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

/* --- Tables --- */
.table-responsive { overflow-x: auto; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.table th {
    background: #f8f9fa;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
.table tbody tr:hover { background: #f8f9fa; }
.table tbody tr.row-overdue { background: #fff5f5; }
.table tbody tr.row-overdue:hover { background: #ffe8e8; }
.table tbody tr.row-highlight { background: #e8f4fd; }
.table .text-right { text-align: right; }
.table .text-center { text-align: center; }
.table-sm th, .table-sm td { padding: 6px 10px; font-size: 0.85rem; }
.table .row-total {
    border-top: 2px solid var(--primary);
    font-weight: 600;
}
.table .row-total td { padding-top: 12px; }
.table .actions { white-space: nowrap; }
.total-amount { font-size: 1.1rem; color: var(--primary); }

/* --- Detail Tables --- */
.detail-table { width: 100%; }
.detail-table td {
    padding: 6px 0;
    border: none;
    vertical-align: top;
    font-size: 0.9rem;
}
.detail-table td:first-child {
    width: 160px;
    color: var(--text-light);
    font-weight: 500;
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.badge-lg { font-size: 0.9rem; padding: 5px 15px; }
.badge-draft { background: #e9ecef; color: #495057; }
.badge-open { background: #fff3cd; color: #856404; }
.badge-paid { background: #d4edda; color: #155724; }
.badge-overdue { background: #f8d7da; color: #721c24; }
.badge-cancelled { background: #e2e3e5; color: #383d41; }
.badge-green { background: #d4edda; color: #155724; }
.badge-blue { background: #d1ecf1; color: #0c5460; }
.badge-gray { background: #e9ecef; color: #495057; }
.badge-admin { background: #e2d5f1; color: #4a235a; }
.badge-accountant { background: #d1ecf1; color: #0c5460; }
.badge-invoice_only { background: #fff3cd; color: #856404; }
.badge-viewer { background: #e9ecef; color: #495057; }

/* --- Alerts --- */
.alert {
    padding: 12px 20px;
    margin-bottom: 20px;
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}
.alert-success { background: var(--success-bg); color: #155724; border: 1px solid #c3e6cb; }
.alert-error { background: var(--danger-bg); color: #721c24; border: 1px solid #f5c6cb; }
.alert-warning { background: var(--warning-bg); color: #856404; border: 1px solid #ffeeba; }
.alert-info { background: var(--info-bg); color: #0c5460; border: 1px solid #bee5eb; }
.alert-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    padding: 0 5px;
}
.alert-close:hover { opacity: 1; }

/* --- Filter Bar --- */
.filter-bar {
    margin-bottom: 20px;
}
.search-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
}
.filter-form .form-group { margin-bottom: 0; }
.filter-form select.form-control { min-width: 150px; }

/* --- Login Page --- */
.login-page {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
}
.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}
.login-card {
    background: var(--bg-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.login-header {
    background: var(--primary);
    color: white;
    padding: 30px;
    text-align: center;
}
.login-header h1 { margin: 0; font-size: 1.5rem; }
.login-header p { margin: 5px 0 0 0; opacity: 0.8; font-size: 0.9rem; }
.login-form { padding: 30px; }
.login-footer {
    padding: 15px 30px;
    text-align: center;
    border-top: 1px solid var(--border-light);
    background: #fafafa;
}

/* --- Stat List --- */
.stat-list { }
.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
}
.stat-item:last-child { border-bottom: none; }

/* --- Permissions Grid --- */
.permissions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 6px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    max-height: 300px;
    overflow-y: auto;
}

/* --- Invoice Status Bar --- */
.invoice-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}
.status-current { display: flex; align-items: center; gap: 10px; }
.status-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.status-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.status-form .form-control-sm {
    padding: 5px 10px;
    font-size: 0.85rem;
    width: auto;
}

/* --- Text Utilities --- */
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

/* --- Responsive --- */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .hamburger { display: block; }
    .top-bar { padding: 10px 15px; }
    .content-wrapper { padding: 15px; }
    .form-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; }
    .form-row .half { flex: auto; }
    .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
    .dashboard-grid { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; gap: 10px; align-items: flex-start; }
    .page-header-right { width: 100%; }
    .search-form { flex-direction: column; }
    .search-form .form-control { width: 100%; }
    .permissions-grid { grid-template-columns: 1fr; }
    .invoice-status-bar { flex-direction: column; align-items: flex-start; }
}

/* --- Print Styles --- */
@media print {
    .sidebar, .top-bar, .no-print, .hamburger { display: none !important; }
    .main-content { margin-left: 0; }
    .content-wrapper { padding: 0; }
    .form-card, .dashboard-card { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; }
    body { background: white; }
}

/* --- App Footer --- */
.app-footer {
    text-align: center;
    padding: 12px 20px;
    font-size: 0.8rem;
    color: var(--text-light);
    border-top: 1px solid var(--border-light);
    background: var(--bg-light);
    margin-left: 250px;
}
@media (max-width: 768px) {
    .app-footer { margin-left: 0; }
}
