/* Peargament – modern theme (light + dark).
   Layout/geometry (grids, widths, margins) is unchanged from the 1:1 Avalonia port;
   only colours, borders, radii, shadows and transitions differ. */

/* ---------- Design tokens: light ---------- */
:root {
    color-scheme: light;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: #e8f0fe;
    --accent-ring: rgba(37, 99, 235, .28);
    --on-accent: #ffffff;

    --text: #111827;
    --text-muted: #6b7280;
    --text-disabled: #9ca3af;

    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --panel: #eef1f5;            /* replaces the Avalonia LightGray (#d3d3d3) panels */
    --panel-border: #e2e6ec;
    --border: #e5e7eb;
    --border-strong: #d1d5db;

    --control-bg: #ffffff;
    --control-bg-disabled: #f3f4f6;
    --control-border: #d1d5db;
    --control-border-hover: #9ca3af;

    --button-bg: #ffffff;
    --button-bg-hover: #f3f4f6;
    --button-bg-active: #e5e7eb;
    --button-border: #d1d5db;

    --row-hover: #f3f4f6;
    --row-selected: #dbeafe;
    --group-row: #eef1f5;
    --group-row-2: #f6f7f9;
    --menu-bg: #ffffff;

    --save-bg: #cdeef3;          /* modern PowderBlue */
    --save-bg-hover: #b6e4ec;
    --save-text: #0e4f5c;

    --green: #16a34a;
    --orange: #f59e0b;
    --red: #dc2626;
    --yellow: #fde047;
    --yellow-text: #422006;

    --danger-text: #b91c1c;
    --danger-bg: #fef2f2;
    --info-bg: #eff6ff;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, .08), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow-lg: 0 20px 40px rgba(16, 24, 40, .18), 0 4px 12px rgba(16, 24, 40, .08);
    --backdrop: rgba(17, 24, 39, .45);

    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --ease: 120ms ease;
}

/* ---------- Design tokens: dark ---------- */
:root[data-theme="dark"] {
    color-scheme: dark;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --accent-soft: #172554;
    --accent-ring: rgba(96, 165, 250, .35);
    --on-accent: #0b1220;

    --text: #e5e7eb;
    --text-muted: #9ca3af;
    --text-disabled: #6b7280;

    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1c2029;
    --panel: #1e232c;
    --panel-border: #2a303b;
    --border: #2a303b;
    --border-strong: #3a4250;

    --control-bg: #12151b;
    --control-bg-disabled: #1a1e26;
    --control-border: #3a4250;
    --control-border-hover: #556070;

    --button-bg: #232833;
    --button-bg-hover: #2c3340;
    --button-bg-active: #353d4c;
    --button-border: #3a4250;

    --row-hover: #222833;
    --row-selected: #1e3a8a;
    --group-row: #232934;
    --group-row-2: #1c2129;
    --menu-bg: #1c2029;

    --save-bg: #134e5a;
    --save-bg-hover: #186575;
    --save-text: #d5f5fa;

    --green: #22c55e;
    --orange: #fbbf24;
    --red: #ef4444;
    --yellow: #ca8a04;
    --yellow-text: #fffbeb;

    --danger-text: #fca5a5;
    --danger-bg: #2a1215;
    --info-bg: #0f1d3a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
    --shadow-lg: 0 24px 48px rgba(0, 0, 0, .6);
    --backdrop: rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
body { transition: background-color 200ms ease, color 200ms ease; }

a { color: inherit; }
::selection { background: var(--accent-ring); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Thin themed scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

.bold { font-weight: 600; }
.m5 { margin: 5px; }
.w200 { width: 200px; }
.center { text-align: center; }
.hstack { display: flex; flex-direction: row; align-items: center; gap: 0; flex-wrap: wrap; }
.vstack { display: flex; flex-direction: column; }
.text-danger, .text-unsaved { color: var(--danger-text); }
.text-unsaved { font-weight: 500; }

/* ---------- Controls ---------- */
.btn {
    font: inherit;
    font-weight: 500;
    background: var(--button-bg);
    border: 1px solid var(--button-border);
    border-radius: var(--radius-sm);
    padding: 5px 11px 6px 11px;
    min-height: 32px;
    cursor: pointer;
    color: var(--text);
    box-shadow: var(--shadow-sm);
    transition: background-color var(--ease), border-color var(--ease), box-shadow var(--ease), color var(--ease);
}
.btn:hover:not(:disabled) { background: var(--button-bg-hover); border-color: var(--control-border-hover); }
.btn:active:not(:disabled) { background: var(--button-bg-active); box-shadow: none; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.btn:disabled { color: var(--text-disabled); cursor: default; box-shadow: none; opacity: .7; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-accent:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.tb, select.tb, textarea.tb {
    font: inherit;
    min-height: 32px;
    padding: 5px 10px 6px 10px;
    border: 1px solid var(--control-border);
    border-radius: var(--radius-sm);
    background: var(--control-bg);
    color: var(--text);
    transition: border-color var(--ease), box-shadow var(--ease), background-color var(--ease);
}
.tb:hover:not(:disabled):not([readonly]) { border-color: var(--control-border-hover); }
.tb:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.tb:disabled, .tb[readonly] { background: var(--control-bg-disabled); color: var(--text-muted); }
.tb::placeholder { color: var(--text-disabled); }
textarea.tb { resize: vertical; }

.checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--accent); }

.hstack > span { margin-right: 4px; }

.error-box {
    margin: 8px 0;
    padding: 8px 12px;
    border-left: 4px solid var(--red);
    border-radius: var(--radius-sm);
    background: var(--danger-bg);
}
.error-text { color: var(--danger-text); margin-top: 6px; }
.info-box { margin: 8px 0; padding: 8px 12px; border-left: 4px solid var(--accent); border-radius: var(--radius-sm); background: var(--info-bg); }

/* ---------- Main window ---------- */
.main-window { display: grid; grid-template-rows: auto auto 1fr; min-height: 100vh; }

.menubar {
    display: flex; align-items: center; min-height: 32px; padding: 0 4px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.menubar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.menubar-user { color: var(--text-muted); }
.menubar form { margin: 0; }
.menu-item { position: relative; outline: none; }
.menu-button {
    font: inherit; background: transparent; border: none; padding: 6px 10px;
    border-radius: var(--radius-sm); cursor: pointer; color: var(--text);
    transition: background-color var(--ease);
}
.menu-button:hover, .menu-item.open > .menu-button { background: var(--row-hover); }
.menu-popup {
    position: absolute; top: 100%; left: 0; z-index: 100; min-width: 260px; margin-top: 4px;
    background: var(--menu-bg); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-md); padding: 4px;
    animation: pop-in 120ms ease-out;
}
.menu-popup a { display: block; padding: 7px 12px; border-radius: var(--radius-sm); text-decoration: none; }
.menu-popup a:hover { background: var(--row-hover); }

/* Theme toggle (menubar) */
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.main-header {
    display: grid; grid-template-columns: 1fr auto; align-items: start;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.main-title { margin: 10px; font-weight: 700; font-size: 30px; text-decoration: none; letter-spacing: -.02em; }
.main-title:hover { color: var(--accent); }
.main-logo { width: 300px; margin: 10px; border-radius: var(--radius); }
:root[data-theme="dark"] .main-logo { background: #fff; box-shadow: var(--shadow-sm); }
.main-content { margin: 10px; min-width: 0; }

/* ---------- Tabs ---------- */
.tabcontrol { display: flex; flex-direction: column; min-width: 0; }
.tab-headers { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.tab-header {
    font: inherit; font-size: 20px; font-weight: 500; background: none; border: none; cursor: pointer;
    padding: 6px 12px 10px 12px; color: var(--text-muted); position: relative;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    transition: color var(--ease), background-color var(--ease);
}
.tab-header:hover:not(:disabled) { color: var(--text); background: var(--row-hover); }
.tab-header.active { color: var(--text); }
.tab-header.active::after {
    content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 3px;
    border-radius: 3px 3px 0 0; background: var(--accent);
}
.tab-header:disabled { color: var(--text-disabled); cursor: default; }
.tab-content { padding-top: 6px; min-width: 0; }

/* ---------- Overview (Aufzüge / Kunden) ---------- */
.overview-header { display: grid; grid-template-columns: auto 1fr; align-items: center; }

/* ---------- DataGrid ---------- */
.datagrid {
    overflow: auto; max-height: calc(100vh - 260px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.datagrid table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
.datagrid th {
    position: sticky; top: 0; background: var(--surface-2); z-index: 1;
    text-align: left; font-weight: 600; font-size: 13px; color: var(--text-muted);
    padding: 8px 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    border-bottom: 1px solid var(--border); user-select: none;
}
.datagrid th.sortable { cursor: pointer; transition: color var(--ease), background-color var(--ease); }
.datagrid th.sortable:hover { background: var(--row-hover); color: var(--text); }
.sort-indicator { font-size: 10px; margin-left: 4px; color: var(--accent); }
.datagrid td { padding: 6px 12px; height: 32px; white-space: nowrap; border-bottom: 1px solid var(--border); }
.datagrid tbody tr:last-child td { border-bottom: none; }
.datagrid tbody tr { cursor: default; transition: background-color 80ms ease; }
.datagrid tbody tr:hover { background: var(--row-hover); }
.datagrid tbody tr.selected { background: var(--row-selected); }
.datagrid tbody tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.datagrid td.center, .datagrid th.center { text-align: center; }
.datagrid td input.tb, .datagrid td select.tb { min-height: 28px; padding: 2px 6px; }
.datagrid-boxed { height: 200px; }

.status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }
.status-1 { background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent); }
.status-2 { background: var(--orange); box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 22%, transparent); }
.status-3 { background: var(--red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 22%, transparent); }
.cell-yellow { background: var(--yellow); color: var(--yellow-text); }
.cell-red { background: var(--red); color: #fff; }

/* ---------- "Windows" (detail pages, dialogs) ---------- */
.window-titlebar {
    display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 12px; font-weight: 500;
    color: var(--text-muted); border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.window-titlebar img { width: 16px; height: 16px; }
.page-toolbar { display: flex; align-items: center; gap: 0; margin-bottom: 6px; }

/* Form grid like Avalonia Grid with label column + control column */
.form-grid { display: grid; grid-template-columns: max-content minmax(150px, 1fr); gap: 4px 10px; align-items: center; }
.form-grid > label { white-space: nowrap; }
.form-cols { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(300px, 1fr); gap: 20px; align-items: start; }
.groupbox { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin: 5px; background: var(--surface); }
.groupbox > .groupbox-header { font-weight: 600; margin-bottom: 8px; }

/* Modal dialog (replaces separate Avalonia windows / MessageBox) */
.modal-backdrop {
    position: fixed; inset: 0; background: var(--backdrop); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(3px);
    animation: fade-in 150ms ease-out;
}
.modal-window {
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 320px; max-width: 95vw; max-height: 92vh; overflow: auto;
    animation: pop-in 160ms ease-out;
}
.modal-body { padding: 20px; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 20px 20px; }

/* ---------- Login window (400x200) ---------- */
.login-window {
    width: 400px; margin: 10vh auto 0 auto;
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg); background: var(--surface);
}
.login-panel { display: flex; flex-direction: column; margin: 20px; }
.login-panel > label { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.login-title { font-weight: 700; font-size: 20px; margin-bottom: 20px; letter-spacing: -.01em; }
.login-panel .btn { align-self: flex-start; margin-top: 4px; }
.login-panel .btn[type=submit] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.login-panel .btn[type=submit]:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ---------- Blazor ---------- */
#blazor-error-ui {
    background: var(--danger-bg); color: var(--text); border-top: 1px solid var(--red);
    bottom: 0; box-shadow: var(--shadow-md); display: none; left: 0;
    padding: .6rem 1.25rem .7rem 1.25rem; position: fixed; width: 100%; z-index: 2000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

@media (max-width: 700px) {
    .main-logo { width: 140px; }
    .main-title { font-size: 22px; }
    .login-window { width: auto; margin: 16px; }
}

/* ListBox (multi select) */
.listbox { min-width: 190px; overflow-y: auto; border: 1px solid var(--control-border); border-radius: var(--radius-sm); background: var(--control-bg); }
.listbox-item { padding: 5px 10px; cursor: pointer; user-select: none; transition: background-color 80ms ease; }
.listbox-item:hover { background: var(--row-hover); }
.listbox-item.selected { background: var(--row-selected); }

/* Detail window header (AufzugDetailWindow top grid) */
.detail-header { display: flex; flex-wrap: wrap; align-items: flex-end; }
.detail-field { display: flex; flex-direction: column; }
.detail-field > span { margin: 5px; }
.detail-field > .tb, .detail-field > .btn, .detail-field > .hstack { margin: 5px; }
.btn-save { background: var(--save-bg); border-color: transparent; color: var(--save-text); }
.btn-save:hover:not(:disabled) { background: var(--save-bg-hover) !important; border-color: transparent; }

/* Drop zone (DragDrop border) */
.dropzone {
    position: relative; display: block; padding: 4px 6px 14px 6px; cursor: pointer;
    border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface-2);
    transition: background-color var(--ease), border-color var(--ease);
}
.dropzone:hover { border-color: var(--control-border-hover); }
.dropzone.over { background: var(--accent-soft); border-color: var(--accent); }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dialog-page { border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); background: var(--surface); max-width: 100%; }

/* Grey panels from the desktop app (LightGray StackPanels) -> soft surface panels */
.anlagen-panel, .grey-panel, .vertrag-box, .kontakt-box, .ereignis-box {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
}

/* AufzugAnlagenDaten (grey StackPanels with fixed column grid) */
.w190 { width: 190px; max-width: 190px; }
.anlagen-panel { margin-top: 10px; }
.anlagen-panel:first-child { margin-top: 0; }
.anlagen-grid { display: grid; grid-template-columns: 120px 250px 120px 250px 180px 250px 150px 250px; align-items: center; }
.anlagen-grid > * { margin: 5px; }
.anlagen-bottom { display: grid; grid-template-columns: 1fr auto; align-items: start; }

/* AufzugTermine */
.termine-top { display: grid; grid-template-columns: auto 1fr; align-items: start; }
.termine-top > .grey-panel:last-child { justify-self: start; }
.termine-grid3 { display: grid; grid-template-columns: auto auto auto; align-items: center; }
.termine-grid2 { display: grid; grid-template-columns: auto auto; align-items: center; }
.termine-grid4 { display: grid; grid-template-columns: auto auto auto auto; align-items: center; justify-content: start; }
.termine-grid3 > *, .termine-grid2 > *, .termine-grid4 > * { margin: 5px; }

/* AufzugVertragsdaten (UniformGrid Columns=4) */
.vertrag-grid { display: grid; grid-template-columns: repeat(4, minmax(260px, 1fr)); }
.vertrag-box { padding: 10px; margin: 10px; }

/* AufzugKontaktdaten (UniformGrid Columns=5) */
.kontakt-grid { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); }
.kontakt-box { padding: 10px; margin: 10px; display: flex; flex-direction: column; }
.kontakt-box > .tb { width: 100%; }
.kontakt-label { padding: 6px 0 2px 0; color: var(--text-muted); font-size: 13px; }
.cb { width: 18px; height: 18px; accent-color: var(--accent); }
.group-row td { background: var(--group-row); font-weight: 600; }
.group-row-2 td { background: var(--group-row-2); padding-left: 28px; font-weight: 500; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }

/* EreignisWindow */
.ereignis-box { padding: 10px; margin: 10px; }
.ereignis-top { display: grid; grid-template-columns: repeat(4, 1fr); align-items: center; }
.anlage-steht {
    background: var(--red); color: #fff; padding: 5px; justify-self: start;
    border-radius: var(--radius-sm); font-weight: 600;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 25%, transparent);
}
.ereignis-grid3 { display: grid; grid-template-columns: repeat(3, minmax(320px, 1fr)); }
.ereignis-form { gap: 0 10px; }
.ereignis-form > * { margin: 5px 0; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 5px; }
.two-cols > * { min-width: 0; }
.two-cols .tb, .ereignis-form .tb, .ereignis-form .lookup-combo select { width: 100%; min-width: 0; }
.ereignis-form { grid-template-columns: max-content minmax(0, 1fr); }
.ereignis-grid3 .hstack > .tb { flex: 1 1 auto; min-width: 0; }

/* ---------- Motion ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(4px) scale(.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* inputs inside 2-column form rows must not overflow their grid cell */
.dialog-page .tb, .modal-window .tb { min-width: 0; }
.dialog-page div[style*="grid-template-columns:1fr 1fr"] .tb, .modal-window div[style*="grid-template-columns:1fr 1fr"] .tb { width: 100%; }
