/* MeinPortal – zentrales Stylesheet (Admin + Kundenportal)
   Modernes, responsives Business-UI: dunkle Sidebar, helle Arbeitsfläche,
   Karten-basierte Layouts. Mobile-first, funktioniert bis 320px Breite. */

:root {
    --mp-primary: #2563eb;
    --mp-primary-dark: #1743a8;
    --mp-primary-light: #4f8cff;
    --mp-accent: #0ea5e9;
    --mp-sidebar-bg: #0b1220;
    --mp-sidebar-bg-2: #111c33;
    --mp-sidebar-text: #b9c4da;
    --mp-sidebar-text-active: #ffffff;
    --mp-bg: #f2f5f9;
    --mp-card: #ffffff;
    --mp-border: #e3e8f0;
    --mp-text: #1c2536;
    --mp-text-muted: #6b7688;
    --mp-green: #16a34a;
    --mp-green-bg: #e7f8ee;
    --mp-red: #dc2626;
    --mp-red-bg: #fdeaea;
    --mp-amber: #b45309;
    --mp-amber-bg: #fef3e2;
    --mp-blue-bg: #e8f0fe;
    --mp-grey-bg: #eef1f5;
    --mp-radius: 12px;
    --mp-shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --mp-shadow-lg: 0 10px 30px rgba(16, 24, 40, .14);
    --mp-sidebar-w: 264px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
    background: var(--mp-bg);
    color: var(--mp-text);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--mp-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0 0 1em; }
.text-muted { color: var(--mp-text-muted); }
.mb-0 { margin-bottom: 0 !important; }

/* ---------- Auth / Login / Installer ---------- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(1200px 700px at 15% -10%, #1e3a8a 0%, transparent 55%),
                radial-gradient(900px 600px at 110% 10%, #0ea5e9 0%, transparent 45%),
                var(--mp-sidebar-bg);
    padding: 24px;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--mp-card);
    border-radius: 18px;
    box-shadow: var(--mp-shadow-lg);
    padding: 38px 34px;
}
.auth-card.wide { max-width: 640px; }
.auth-logo { display: flex; align-items: center; justify-content: center; margin-bottom: 22px; }
.auth-logo img { height: 52px; }
.auth-card h1 { text-align: center; font-size: 1.3rem; margin-bottom: 6px; }
.auth-sub { text-align: center; color: var(--mp-text-muted); margin-bottom: 24px; font-size: .92rem; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
label { display: block; font-weight: 600; font-size: .84rem; margin-bottom: 6px; color: #374151; }
.form-hint { font-size: .78rem; color: var(--mp-text-muted); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], input[type=tel], input[type=url],
input[type=search], input[type=time], select, textarea {
    width: 100%;
    padding: 10px 13px;
    border: 1.5px solid var(--mp-border);
    border-radius: 9px;
    font-size: .92rem;
    background: #fff;
    color: var(--mp-text);
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--mp-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row > .form-group { flex: 1 1 200px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
fieldset { border: 1.5px solid var(--mp-border); border-radius: 12px; padding: 16px 18px; margin-bottom: 18px; }
legend { padding: 0 8px; font-weight: 700; font-size: .95rem; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 9px;
    border: 1.5px solid transparent;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
    transition: background .15s, border-color .15s, color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--mp-primary); color: #fff; }
.btn-primary:hover { background: var(--mp-primary-dark); text-decoration: none; }
.btn-block { width: 100%; justify-content: center; }
.btn-outline { background: #fff; border-color: var(--mp-border); color: var(--mp-text); }
.btn-outline:hover { border-color: var(--mp-primary); color: var(--mp-primary); text-decoration: none; }
.btn-danger { background: #fff; border-color: var(--mp-red); color: var(--mp-red); }
.btn-danger:hover { background: var(--mp-red); color: #fff; text-decoration: none; }
.btn-success { background: var(--mp-green); color: #fff; }
.btn-success:hover { background: #128038; text-decoration: none; }
.btn-sm { padding: 6px 12px; font-size: .78rem; border-radius: 7px; }
.btn-icon { padding: 8px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--mp-sidebar-w);
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--mp-sidebar-bg) 0%, var(--mp-sidebar-bg-2) 100%);
    color: var(--mp-sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 40;
    transition: transform .2s ease;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand img { height: 30px; }
.sidebar-brand span { font-weight: 800; font-size: 1.08rem; color: #fff; letter-spacing: -.02em; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 14px 12px 20px; }
.sidebar-scroll::-webkit-scrollbar { width: 6px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 3px; }
.nav-section-title {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #6b7c99;
    font-weight: 700;
    margin: 18px 10px 6px;
}
.nav-section-title:first-child { margin-top: 4px; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: 9px;
    color: var(--mp-sidebar-text);
    font-size: .87rem;
    font-weight: 500;
    margin-bottom: 2px;
    white-space: nowrap;
}
.nav-link .nav-ico { width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nav-link .nav-ico img { width: 18px; height: 18px; object-fit: contain; opacity: .82; }
.nav-link:hover .nav-ico img, .nav-link.active .nav-ico img { opacity: 1; }
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--mp-primary); color: #fff; box-shadow: 0 4px 14px rgba(37,99,235,.35); }
.nav-badge {
    margin-left: auto;
    background: var(--mp-red);
    color: #fff;
    font-size: .68rem;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 20px;
}
.sidebar-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: .74rem; color: #6b7c99; }

.main { margin-left: var(--mp-sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: 62px;
    background: var(--mp-card);
    border-bottom: 1px solid var(--mp-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar-title { font-size: 1.08rem; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.menu-toggle { display: none; background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--mp-text); }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 6px 10px 6px 6px; border-radius: 30px; background: var(--mp-bg); position: relative; }
.avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--mp-primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .78rem; flex-shrink: 0;
}
.user-chip .uname { font-size: .82rem; font-weight: 600; }
.user-chip .urole { font-size: .7rem; color: var(--mp-text-muted); display: block; }
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 8px);
    background: #fff; border: 1px solid var(--mp-border); border-radius: 10px;
    box-shadow: var(--mp-shadow-lg); min-width: 190px; padding: 6px; display: none; z-index: 60;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 7px; color: var(--mp-text); font-size: .86rem; }
.dropdown-menu a:hover { background: var(--mp-bg); text-decoration: none; }
.dropdown-menu hr { border: none; border-top: 1px solid var(--mp-border); margin: 6px 0; }
.menu-ico { width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.menu-ico img { width: 16px; height: 16px; object-fit: contain; filter: brightness(0); opacity: .6; }
.dropdown-menu a:hover .menu-ico img { opacity: .9; }

.content { padding: 24px; flex: 1; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.page-head h1 { font-size: 1.5rem; margin: 0; }
.page-head .sub { color: var(--mp-text-muted); font-size: .88rem; margin-top: 2px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(6,10,20,.55); z-index: 39; }

/* ---------- Cards / KPIs ---------- */
.card { background: var(--mp-card); border: 1px solid var(--mp-border); border-radius: var(--mp-radius); box-shadow: var(--mp-shadow); }
.card-pad { padding: 20px 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--mp-border); }
.card-head h3 { font-size: .98rem; margin: 0; }
.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 640px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.kpi { padding: 20px 22px; display: flex; flex-direction: column; gap: 6px; }
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi .kpi-label { color: var(--mp-text-muted); font-size: .8rem; font-weight: 600; }
.kpi .kpi-icon {
    width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
    font-size: 1.05rem; background: var(--mp-blue-bg); color: var(--mp-primary);
}
.kpi .kpi-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; }
.kpi .kpi-delta { font-size: .78rem; font-weight: 600; }
.kpi .kpi-delta.up { color: var(--mp-green); }
.kpi .kpi-delta.down { color: var(--mp-red); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.data-table th {
    text-align: left; padding: 11px 16px; background: #f8fafc; color: var(--mp-text-muted);
    font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700;
    border-bottom: 1px solid var(--mp-border); white-space: nowrap;
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--mp-border); vertical-align: middle; }
.data-table tbody tr:hover { background: #fafbfe; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .row-link { display: block; color: inherit; }
.cell-strong { font-weight: 700; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--mp-text-muted); }
.empty-state .ico { font-size: 2.4rem; margin-bottom: 10px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.badge-blue { background: var(--mp-blue-bg); color: var(--mp-primary-dark); }
.badge-green { background: var(--mp-green-bg); color: var(--mp-green); }
.badge-red { background: var(--mp-red-bg); color: var(--mp-red); }
.badge-amber { background: var(--mp-amber-bg); color: var(--mp-amber); }
.badge-grey { background: var(--mp-grey-bg); color: #55607a; }
.badge-outline { background: transparent; border: 1.5px solid currentColor; }
.priority-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; }

/* ---------- Alerts / Flash ---------- */
.alert { padding: 13px 16px; border-radius: 10px; margin-bottom: 16px; font-size: .87rem; display: flex; gap: 10px; align-items: flex-start; }
.alert-success { background: var(--mp-green-bg); color: #0f5c2c; }
.alert-error { background: var(--mp-red-bg); color: #8a1c1c; }
.alert-info { background: var(--mp-blue-bg); color: var(--mp-primary-dark); }

/* ---------- Progress ---------- */
.progress { height: 9px; background: var(--mp-grey-bg); border-radius: 20px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--mp-primary), var(--mp-accent)); border-radius: 20px; transition: width .3s; }

/* ---------- Timeline / phases ---------- */
.phase-list { list-style: none; margin: 0; padding: 0; }
.phase-item { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px dashed var(--mp-border); }
.phase-item:last-child { border-bottom: none; }
.phase-check { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 800; border: 2px solid var(--mp-border); color: var(--mp-text-muted); }
.phase-item.done .phase-check { background: var(--mp-green); border-color: var(--mp-green); color: #fff; }
.phase-item.progress-active .phase-check { background: var(--mp-amber-bg); border-color: var(--mp-amber); color: var(--mp-amber); }
.phase-item.needs-change .phase-check { background: var(--mp-red-bg); border-color: var(--mp-red); color: var(--mp-red); }
.phase-title { font-weight: 700; margin-bottom: 2px; }
.phase-meta { font-size: .78rem; color: var(--mp-text-muted); }
.phase-actions { margin-top: 8px; display: flex; gap: 8px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding-bottom: 18px; position: relative; }
.timeline li:before { content: ''; position: absolute; left: 5px; top: 20px; bottom: 0; width: 2px; background: var(--mp-border); }
.timeline li:last-child:before { display: none; }
.timeline .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--mp-primary); margin-top: 4px; flex-shrink: 0; }

/* ---------- Chat / replies ---------- */
.reply-list { display: flex; flex-direction: column; gap: 14px; margin-bottom: 20px; }
.reply { display: flex; gap: 12px; }
.reply-bubble { background: var(--mp-bg); border-radius: 12px; padding: 12px 15px; flex: 1; }
.reply.internal .reply-bubble { background: var(--mp-amber-bg); }
.reply.me .reply-bubble { background: var(--mp-blue-bg); }
.reply-head { display: flex; justify-content: space-between; gap: 10px; font-size: .78rem; color: var(--mp-text-muted); margin-bottom: 4px; }
.reply-head strong { color: var(--mp-text); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,15,25,.55); display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-backdrop.open { display: flex; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: var(--mp-shadow-lg); }
.modal.modal-lg { max-width: 820px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--mp-border); }
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--mp-text-muted); }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--mp-border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--mp-border); margin-bottom: 20px; overflow-x: auto; }
.tab-link { padding: 11px 16px; font-size: .86rem; font-weight: 600; color: var(--mp-text-muted); border-bottom: 2.5px solid transparent; white-space: nowrap; }
.tab-link:hover { color: var(--mp-text); text-decoration: none; }
.tab-link.active { color: var(--mp-primary); border-color: var(--mp-primary); }

/* ---------- Misc ---------- */
.stack { display: flex; flex-direction: column; gap: 10px; }
.hstack { display: flex; align-items: center; gap: 10px; }
.between { display: flex; align-items: center; justify-content: space-between; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.file-chip { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--mp-border); border-radius: 9px; font-size: .82rem; background: #fafbfe; }
.file-chip .ico { color: var(--mp-primary); }
.search-input { max-width: 280px; }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.pill-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-nav a { padding: 7px 14px; border-radius: 20px; background: var(--mp-grey-bg); color: var(--mp-text); font-size: .8rem; font-weight: 600; }
.pill-nav a.active { background: var(--mp-primary); color: #fff; }
.divider { border: none; border-top: 1px solid var(--mp-border); margin: 18px 0; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; font-size: .87rem; }
.kv dt { color: var(--mp-text-muted); font-weight: 600; }
.kv dd { margin: 0; }
.text-right { text-align: right; }
.w-full { width: 100%; }
.login-portal-switch { text-align: center; margin-top: 18px; font-size: .84rem; }
.small { font-size: .8rem; }
.installer-steps { display: flex; justify-content: center; gap: 8px; margin-bottom: 26px; }
.installer-steps span { width: 30px; height: 4px; border-radius: 4px; background: var(--mp-border); }
.installer-steps span.done { background: var(--mp-primary); }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--mp-shadow-lg); }
    .main { margin-left: 0; }
    .menu-toggle { display: inline-flex; }
    .sidebar-overlay.open { display: block; }
    .kv { grid-template-columns: 120px 1fr; }
}
/* ---------- Druckansicht (Angebote/Rechnungen) ---------- */
@media print {
    .sidebar, .sidebar-overlay, .topbar, .page-actions, .tabs, .no-print, .modal-backdrop { display: none !important; }
    .main { margin-left: 0 !important; }
    .content { padding: 0 !important; }
    body { background: #fff !important; }
    .card { box-shadow: none !important; border: none !important; }
    .print-sheet { display: block !important; }
}
.print-sheet { display: none; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 30px; }
.doc-head img { height: 46px; }
.doc-meta { text-align: right; font-size: .85rem; }
.doc-parties { display: flex; justify-content: space-between; margin-bottom: 26px; gap: 20px; }
.doc-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.doc-table th { text-align: left; border-bottom: 2px solid var(--mp-text); padding: 8px 6px; font-size: .82rem; }
.doc-table td { padding: 9px 6px; border-bottom: 1px solid var(--mp-border); font-size: .88rem; }
.doc-totals { margin-left: auto; width: 280px; }
.doc-totals .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: .88rem; }
.doc-totals .row.grand { font-weight: 800; font-size: 1.05rem; border-top: 2px solid var(--mp-text); margin-top: 4px; padding-top: 10px; }

@media (max-width: 560px) {
    .content { padding: 16px; }
    .topbar { padding: 0 14px; }
    .user-chip .uname, .user-chip .urole { display: none; }
    .page-head h1 { font-size: 1.25rem; }
    .card-pad { padding: 16px; }
    .modal-body, .modal-head, .modal-foot { padding-left: 16px; padding-right: 16px; }
}
