/* ═══════════════════════════════════════════════════════════════
   LicensePortal – Haupt-Stylesheet
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS-Variablen ─────────────────────────────────────────── */
:root {
    --primary:       #2563eb;
    --primary-dark:  #1d4ed8;
    --primary-light: #eff6ff;
    --sidebar:       #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active:#2563eb;
    --text:          #1f2937;
    --text-light:    #374151;
    --muted:         #6b7280;
    --border:        #e5e7eb;
    --bg:            #f8fafc;
    --white:         #ffffff;
    --success:       #16a34a;
    --success-bg:    #f0fdf4;
    --warning:       #d97706;
    --warning-bg:    #fffbeb;
    --danger:        #dc2626;
    --danger-bg:     #fef2f2;
    --info:          #0891b2;
    --info-bg:       #ecfeff;
    --sidebar-width: 240px;
    --topbar-height: 56px;
    --radius:        6px;
    --shadow:        0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:     0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
    --shadow-lg:     0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
}

/* ── Reset & Basis ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

ul, ol { list-style: none; }

img { max-width: 100%; }

/* ── Layout ─────────────────────────────────────────────────── */
.layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform .25s ease;
}

.sidebar-header {
    padding: 0 16px;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: white;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: .5px;
    flex-shrink: 0;
}

.logo-text {
    font-weight: 600;
    font-size: 15px;
    color: #f1f5f9;
    letter-spacing: .3px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius);
    color: #94a3b8;
    font-size: 13.5px;
    font-weight: 500;
    transition: background .15s, color .15s;
    margin-bottom: 2px;
    text-decoration: none;
}

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

.nav-item.active {
    background: var(--primary);
    color: white;
}

.nav-icon {
    font-size: 15px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    opacity: .85;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
}

.version {
    font-size: 11px;
    color: #475569;
}

/* ── Hauptbereich ───────────────────────────────────────────── */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-height);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 90;
    box-shadow: var(--shadow);
}

.sidebar-toggle {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    margin-right: 12px;
}

.sidebar-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: .2s;
}

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}

/* ── Inhalt ─────────────────────────────────────────────────── */
.main-content {
    flex: 1;
    padding: 24px;
    max-width: 1400px;
    width: 100%;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.3px;
}

.page-subtitle {
    font-size: 13px;
    color: var(--muted);
    margin-top: 2px;
}

/* ── Karten ─────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-body { padding: 20px; }

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

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

/* ── Dashboard-Stat-Karten ──────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.stat-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--muted);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }
.stat-value.danger  { color: var(--danger); }
.stat-value.info    { color: var(--info); }

.stat-sub {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}

/* ── Tabellen ───────────────────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--white);
    box-shadow: var(--shadow);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    background: #f8fafc;
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--muted);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background .1s;
}

tbody tr:last-child { border-bottom: none; }

tbody tr:hover { background: #f9fafb; }

td {
    padding: 11px 14px;
    vertical-align: middle;
    color: var(--text-light);
}

td.nowrap { white-space: nowrap; }

.table-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--muted);
    font-size: 13px;
}

/* ── Formulare ──────────────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-light);
}

label .required { color: var(--danger); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="tel"],
select,
textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13.5px;
    color: var(--text);
    background: var(--white);
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
    appearance: none;
}

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

input[readonly], input:disabled, select:disabled {
    background: #f1f5f9;
    color: var(--muted);
    cursor: not-allowed;
}

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

select {
    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='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

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

/* ── Formular-Sektionen ─────────────────────────────────────── */
.form-section {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.form-section-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
    border-radius: var(--radius) var(--radius) 0 0;
}

.form-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.form-section-body { padding: 20px; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, border-color .15s, box-shadow .15s, transform .08s;
    line-height: 1.4;
    white-space: nowrap;
    text-decoration: none;
}

.btn:active { transform: scale(.98); }

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

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

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}
.btn-danger:hover { background: #b91c1c; }

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

.btn-warning {
    background: var(--warning);
    color: white;
    border-color: var(--warning);
}
.btn-warning:hover { background: #b45309; }

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

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 10px 22px; font-size: 15px; }
.btn-icon { padding: 6px; width: 32px; height: 32px; justify-content: center; }

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

/* ── Badges / Status ────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .2px;
}

.badge-active  { background: var(--success-bg); color: var(--success); }
.badge-cancelled { background: var(--warning-bg); color: var(--warning); }
.badge-ended   { background: #f3f4f6; color: var(--muted); }
.badge-done    { background: var(--success-bg); color: var(--success); }
.badge-pending { background: var(--warning-bg); color: var(--warning); }
.badge-info    { background: var(--info-bg); color: var(--info); }

/* ── Filter-Leiste ──────────────────────────────────────────── */
.filter-bar {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 140px;
}

.filter-group label {
    font-size: 11.5px;
}

.filter-bar select,
.filter-bar input {
    min-width: 130px;
    max-width: 200px;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-top: 20px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}

.filter-checkbox input[type="checkbox"] {
    width: auto;
    min-width: unset;
    cursor: pointer;
}

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

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

.modal {
    background: var(--white);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn .18s ease;
}

.modal-lg { max-width: 800px; }
.modal-xl { max-width: 1000px; }

@keyframes modalIn {
    from { opacity: 0; transform: translateY(-12px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--white);
    z-index: 1;
}

.modal-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.modal-close {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--bg);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--muted);
    transition: background .15s, color .15s;
}

.modal-close:hover { background: var(--border); color: var(--text); }

.modal-body { padding: 20px; }

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    border-radius: 0 0 8px 8px;
    position: sticky;
    bottom: 0;
}

/* ── Tabs ───────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 16px;
}

.tab-btn {
    padding: 9px 18px;
    border: none;
    background: none;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color .15s, border-color .15s;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-color: var(--primary); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13.5px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--success-bg);
    color: #166534;
    border-color: #86efac;
}

.alert-error {
    background: var(--danger-bg);
    color: #991b1b;
    border-color: #fca5a5;
}

.alert-warning {
    background: var(--warning-bg);
    color: #92400e;
    border-color: #fcd34d;
}

/* ── Checkboxen ─────────────────────────────────────────────── */
.checkbox-cell {
    display: flex;
    align-items: center;
    justify-content: center;
}

input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

.toggle-done {
    width: 18px;
    height: 18px;
    accent-color: var(--success);
    cursor: pointer;
}

/* ── Paginierung / Summen ───────────────────────────────────── */
.table-summary {
    display: flex;
    justify-content: flex-end;
    gap: 24px;
    padding: 10px 14px;
    background: #f8fafc;
    border-top: 1px solid var(--border);
    font-size: 13px;
}

.table-summary .sum-label { color: var(--muted); }
.table-summary .sum-value { font-weight: 600; color: var(--text); }

/* ── Login-Seite ────────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 20px;
}

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

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo-icon {
    width: 52px;
    height: 52px;
    background: var(--primary);
    color: white;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 12px;
}

.login-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 13px;
    color: var(--muted);
}

/* ── Hilfeklassen ───────────────────────────────────────────── */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.font-bold { font-weight: 700; }
.font-mono { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12.5px; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }

.d-flex  { display: flex; }
.gap-1   { gap: 4px; }
.gap-2   { gap: 8px; }
.gap-3   { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

.hidden { display: none !important; }

/* ── Lade-Indikator ─────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: middle;
}

.loading-row td {
    text-align: center;
    padding: 40px;
    color: var(--muted);
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Abrechnung: Periodenzeile ──────────────────────────────── */
.billing-period-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 6px;
    background: var(--white);
    transition: background .1s;
}

.billing-period-row:hover { background: #f9fafb; }

.billing-period-row.is-done {
    background: var(--success-bg);
    border-color: #86efac;
}

.billing-period-info { display: flex; flex-direction: column; gap: 2px; }
.billing-period-label { font-weight: 600; font-size: 13px; }
.billing-period-dates { font-size: 11.5px; color: var(--muted); }
.billing-period-amount { font-weight: 600; font-size: 14px; }

/* ── Vertrag: berechnete Felder ─────────────────────────────── */
.computed-field {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 13.5px;
    color: var(--text-light);
    min-height: 38px;
    display: flex;
    align-items: center;
}

.computed-warning { color: var(--warning); font-weight: 600; }
.computed-danger  { color: var(--danger);  font-weight: 600; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
    .form-grid-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-wrapper {
        margin-left: 0;
    }
    .sidebar-toggle { display: flex; }
    .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar select, .filter-bar input { max-width: 100%; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .modal-lg, .modal-xl { max-width: 100%; }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr; }
    .main-content { padding: 16px; }
    .login-card { padding: 24px 20px; }
}

/* ── Divider ────────────────────────────────────────────────── */
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* ── Kündbarkeits-Warnung ───────────────────────────────────── */
.expiry-urgent { color: var(--danger); font-weight: 600; }
.expiry-soon   { color: var(--warning); font-weight: 600; }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
