:root {
    color-scheme: light;
    --navy: #0a2d63;
    --navy-2: #123f83;
    --blue: #2477df;
    --cyan: #42b9dc;
    --ink: #102a55;
    --muted: #667793;
    --line: #d7e4f1;
    --panel: rgba(255, 255, 255, .97);
    --shadow: 0 22px 60px rgba(7, 37, 81, .2);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body { color: var(--ink); background: #edf6ff; }
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

/* Anmeldung */
.login-page {
    min-height: 100svh;
    background:
        radial-gradient(circle at 78% 15%, rgba(70, 194, 225, .36), transparent 30rem),
        radial-gradient(circle at 8% 88%, rgba(255, 220, 122, .4), transparent 27rem),
        linear-gradient(145deg, #062756, #1269b8 53%, #57cbdc);
}
.login-shell {
    min-height: 100svh;
    display: grid;
    place-items: center;
    padding: calc(24px + var(--safe-top)) calc(18px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(18px + var(--safe-left));
}
.login-card {
    width: min(470px, 100%);
    padding: clamp(24px, 5vw, 38px);
    border: 1px solid rgba(255, 255, 255, .72);
    border-radius: 30px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 34px 90px rgba(2, 25, 62, .35);
    backdrop-filter: blur(18px);
}
.login-brand { display: flex; align-items: center; gap: 13px; }
.login-brand img { border-radius: 16px; box-shadow: 0 9px 24px rgba(11, 50, 100, .18); }
.login-brand span { display: grid; gap: 2px; }
.login-brand strong { font-size: 20px; letter-spacing: -.3px; }
.login-brand small { color: #2673b6; font-size: 10px; font-weight: 900; letter-spacing: 1.5px; }
.login-icon {
    width: 64px; height: 64px; display: grid; place-items: center;
    margin: 34px 0 18px; border-radius: 21px; font-size: 30px;
    background: linear-gradient(145deg, #e5f3ff, #eefcff);
    box-shadow: inset 0 0 0 1px #d6e9f8;
}
.eyebrow { margin: 0 0 6px; color: #2685bf; font-size: 11px; font-weight: 950; letter-spacing: 1.6px; text-transform: uppercase; }
.login-card h1 { margin: 0; color: var(--ink); font-size: clamp(32px, 8vw, 42px); line-height: 1.05; letter-spacing: -1.5px; }
.login-intro { margin: 14px 0 22px; color: var(--muted); line-height: 1.62; }
.login-error { margin: 0 0 16px; padding: 12px 14px; border: 1px solid #f2bcbc; border-radius: 14px; background: #fff1f1; color: #941f2a; font-size: 14px; font-weight: 750; }
.login-form { display: grid; gap: 8px; }
.login-form label { margin-top: 8px; color: #254775; font-size: 12px; font-weight: 850; }
.login-form input {
    width: 100%; min-height: 51px; padding: 12px 14px;
    border: 1px solid #ccdeed; border-radius: 14px; outline: 0;
    color: var(--ink); background: #f9fcff; transition: .18s ease;
}
.login-form input:focus { border-color: #3b8fe3; background: #fff; box-shadow: 0 0 0 4px rgba(45, 129, 217, .12); }
.login-form button {
    min-height: 53px; margin-top: 14px; border: 0; border-radius: 15px;
    color: #fff; background: linear-gradient(135deg, #1e68d8, #42badb);
    box-shadow: 0 15px 30px rgba(28, 104, 203, .27); font-weight: 900; cursor: pointer;
}
.login-security { display: flex; flex-wrap: wrap; gap: 7px 14px; margin-top: 20px; color: #718099; font-size: 11px; font-weight: 700; }

/* Editor-Grundgerüst */
.editor-page { width: 100%; height: 100dvh; min-height: 480px; overflow: hidden; overscroll-behavior: none; }
.editor-app { width: 100%; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; background: #dfeef9; }
.editor-topbar {
    position: relative; z-index: 4000; min-height: calc(65px + var(--safe-top));
    display: flex; align-items: center; gap: 15px;
    padding: calc(9px + var(--safe-top)) calc(13px + var(--safe-right)) 9px calc(13px + var(--safe-left));
    color: #fff; background: linear-gradient(115deg, #082858, #176fc2 62%, #42b9dc);
    box-shadow: 0 7px 25px rgba(5, 42, 89, .28);
}
.editor-brand { min-width: 0; display: flex; align-items: center; gap: 9px; }
.editor-brand img { flex: 0 0 auto; border-radius: 11px; }
.editor-brand span, .editor-user > span { min-width: 0; display: grid; }
.editor-brand strong { font-size: 17px; line-height: 1.05; }
.editor-brand small, .editor-user small { opacity: .78; font-size: 9px; font-weight: 800; letter-spacing: .9px; text-transform: uppercase; }
.save-state { margin-left: auto; display: flex; align-items: center; gap: 7px; padding: 7px 10px; border: 1px solid rgba(255,255,255,.22); border-radius: 999px; background: rgba(255,255,255,.1); font-size: 11px; }
.save-state span { width: 8px; height: 8px; border-radius: 50%; background: #65e596; box-shadow: 0 0 0 4px rgba(101,229,150,.13); }
.save-state.offline span { background: #ffcb66; box-shadow: 0 0 0 4px rgba(255,203,102,.14); }
.editor-user { display: flex; align-items: center; gap: 9px; }
.editor-user > span { text-align: right; max-width: 180px; }
.editor-user strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.editor-user form { margin: 0; }
.editor-user button { width: 37px; height: 37px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.24); border-radius: 12px; color: #fff; background: rgba(255,255,255,.12); font-size: 18px; cursor: pointer; }

.map-workspace { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.live-map { position: absolute; inset: 0; z-index: 1; background: #d8e8d3; }
.leaflet-container { font-family: inherit; }
.leaflet-control-zoom { margin-top: 74px !important; border: 0 !important; box-shadow: 0 8px 25px rgba(10,43,87,.2) !important; }
.leaflet-control-zoom a { color: var(--navy) !important; border-color: #e0e9f2 !important; }
.leaflet-control-attribution { max-width: 78vw; font-size: 8px !important; }

.map-toolbar {
    position: absolute; z-index: 900; top: 12px; left: calc(12px + var(--safe-left));
    display: flex; gap: 4px; padding: 4px; border: 1px solid rgba(26, 74, 128, .13); border-radius: 14px;
    background: rgba(255,255,255,.94); box-shadow: 0 9px 28px rgba(9, 43, 88, .19); backdrop-filter: blur(13px);
}
.map-toolbar button { min-height: 38px; padding: 8px 11px; border: 0; border-radius: 10px; color: #375778; background: transparent; font-size: 12px; font-weight: 850; cursor: pointer; }
.map-toolbar button.active { color: #fff; background: linear-gradient(135deg, #246cdb, #47b8dc); }
.map-actions {
    position: absolute; z-index: 950; right: calc(12px + var(--safe-right)); bottom: calc(18px + var(--safe-bottom));
    display: grid; gap: 9px;
}
.map-actions button {
    width: 50px; height: 50px; display: grid; place-items: center; border: 1px solid rgba(23, 75, 134, .16); border-radius: 17px;
    color: var(--navy); background: rgba(255,255,255,.96); box-shadow: 0 10px 28px rgba(8, 41, 86, .22); font-size: 24px; font-weight: 700; cursor: pointer;
}
.map-actions .add-button { width: 59px; height: 59px; border: 3px solid rgba(255,255,255,.95); border-radius: 20px; color: #fff; background: linear-gradient(145deg, #1d67db, #38b8df); box-shadow: 0 15px 35px rgba(22, 101, 204, .4); font-size: 34px; }
.map-hint {
    position: absolute; z-index: 1000; top: 70px; left: 50%; transform: translateX(-50%);
    width: max-content; max-width: calc(100% - 28px); padding: 10px 14px; border: 1px solid rgba(19, 68, 125, .14); border-radius: 14px;
    color: #fff; background: rgba(8, 45, 94, .9); box-shadow: 0 11px 30px rgba(3, 31, 70, .28); font-size: 12px; font-weight: 850; text-align: center; backdrop-filter: blur(12px);
}
.map-workspace.is-picking .live-map { cursor: crosshair; }

/* Marker */
.mr-marker { position: relative; width: 38px; height: 45px; }
.mr-marker-pin {
    position: absolute; left: 2px; top: 0; width: 34px; height: 34px; display: grid; place-items: center;
    border: 3px solid #fff; border-radius: 50% 50% 50% 10px; transform: rotate(-45deg);
    background: var(--marker-color, #2874d8); box-shadow: 0 5px 14px rgba(0,0,0,.28);
}
.mr-marker-pin > span { transform: rotate(45deg); font-size: 16px; line-height: 1; }
.mr-marker.selected .mr-marker-pin { box-shadow: 0 0 0 5px rgba(36,119,223,.28), 0 8px 18px rgba(0,0,0,.3); }
.mr-location-dot { width: 18px; height: 18px; border: 3px solid #fff; border-radius: 50%; background: #1877ed; box-shadow: 0 0 0 8px rgba(24,119,237,.2), 0 5px 14px rgba(3,50,110,.3); }

/* Suche */
.search-panel {
    position: absolute; z-index: 1200; top: 12px; right: calc(76px + var(--safe-right));
    width: min(390px, calc(100% - 105px)); max-height: min(620px, calc(100% - 24px));
    display: flex; flex-direction: column; overflow: hidden; border: 1px solid rgba(28, 81, 139, .18); border-radius: 20px;
    background: var(--panel); box-shadow: var(--shadow); backdrop-filter: blur(18px);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 15px 9px; }
.panel-head > div { min-width: 0; display: grid; gap: 2px; }
.panel-head small { color: var(--muted); font-size: 10px; font-weight: 750; }
.panel-head button, .sheet-head > button { width: 35px; height: 35px; border: 0; border-radius: 11px; color: var(--navy); background: #edf5fd; font-size: 23px; cursor: pointer; }
.search-field { display: flex; align-items: center; gap: 8px; margin: 0 13px 10px; padding: 0 11px; border: 1px solid #d5e3f0; border-radius: 13px; background: #f7fbff; }
.search-field input { width: 100%; min-height: 44px; border: 0; outline: 0; color: var(--ink); background: transparent; }
.search-results { min-height: 80px; overflow: auto; padding: 0 8px 10px; }
.search-result { width: 100%; display: grid; grid-template-columns: 38px minmax(0,1fr); gap: 10px; align-items: center; padding: 10px; border: 0; border-bottom: 1px solid #e5edf5; color: var(--ink); background: transparent; text-align: left; cursor: pointer; }
.search-result > span { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: #eaf4ff; font-size: 19px; }
.search-result strong, .search-result small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.search-empty { padding: 24px 14px; color: var(--muted); text-align: center; font-size: 13px; }

/* Bearbeitungs-Sheet */
.editor-sheet {
    position: absolute; z-index: 1500; top: 10px; right: calc(10px + var(--safe-right)); bottom: calc(10px + var(--safe-bottom));
    width: min(430px, calc(100% - 20px - var(--safe-left) - var(--safe-right)));
    display: flex; flex-direction: column; overflow: hidden; border: 1px solid rgba(24, 75, 133, .19); border-radius: 24px;
    background: var(--panel); box-shadow: var(--shadow); backdrop-filter: blur(19px);
}
.sheet-grip { display: none; }
.sheet-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 17px 13px; border-bottom: 1px solid #e2ebf3; }
.sheet-head small { color: #2a86be; font-size: 9px; font-weight: 950; letter-spacing: 1.25px; }
.sheet-head h2 { margin: 3px 0 0; font-size: 23px; line-height: 1.12; letter-spacing: -.55px; }
.sheet-body { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 14px 15px 20px; }
.new-object-grid { display: grid; gap: 11px; }
.new-object-grid button { display: grid; grid-template-columns: 52px minmax(0,1fr); gap: 2px 12px; align-items: center; padding: 16px; border: 1px solid #d8e6f2; border-radius: 18px; color: var(--ink); background: linear-gradient(145deg,#fff,#f4faff); text-align: left; cursor: pointer; }
.new-object-grid button > span { grid-row: 1/3; width: 52px; height: 52px; display: grid; place-items: center; border-radius: 16px; background: #eaf4ff; font-size: 26px; }
.new-object-grid button strong { font-size: 16px; }
.new-object-grid button small { color: var(--muted); line-height: 1.4; }
.sheet-note { margin: 14px 2px 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.object-preview { margin: -14px -15px 15px; }
.object-preview img { width: 100%; height: 150px; display: block; object-fit: cover; }

.object-form { display: grid; gap: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid label { min-width: 0; display: grid; align-content: start; gap: 5px; }
.form-grid label.full, .form-grid .full { grid-column: 1 / -1; }
.form-grid label > span { color: #234675; font-size: 11px; font-weight: 900; }
.form-grid label > span em { color: #8290a6; font-style: normal; font-weight: 650; }
.object-form input:not([type="hidden"]):not([type="radio"]), .object-form select, .object-form textarea {
    width: 100%; min-height: 44px; padding: 10px 11px; border: 1px solid #d4e1ed; border-radius: 12px; outline: 0; color: var(--ink); background: #f9fcff;
}
.object-form textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
.object-form input:focus, .object-form select:focus, .object-form textarea:focus { border-color: #3d8fe0; box-shadow: 0 0 0 3px rgba(48,128,213,.1); background: #fff; }
.object-form input[type="color"] { min-height: 44px; padding: 4px; }
.file-field { padding: 11px; border: 1px dashed #b9d4ea; border-radius: 14px; background: #f3f9ff; }
.file-field > span { display: block; margin-bottom: 8px; font-weight: 900; color: var(--ink); }
.file-field .image-source-input { position: absolute; width: 1px !important; height: 1px; min-height: 0 !important; padding: 0 !important; opacity: 0; overflow: hidden; pointer-events: none; }
.image-source-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-bottom: 7px; }
.image-source-actions button { min-height: 42px; border: 1px solid #bcd6ec; border-radius: 11px; background: #fff; color: #143d73; font: inherit; font-size: 12px; font-weight: 900; cursor: pointer; }
.image-source-actions button:first-child { background: linear-gradient(135deg,#eaf6ff,#fff); border-color: #8fc4ec; }
.image-source-actions button:active { transform: translateY(1px); }
.file-field small { color: var(--muted); font-size: 10px; line-height: 1.4; }
.form-details { border: 1px solid #dce7f1; border-radius: 13px; }
.form-details summary { padding: 11px; color: #2a4e7c; font-size: 12px; font-weight: 850; cursor: pointer; }
.form-details > .form-grid { padding: 0 10px 10px; }
.feature-type-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 5px; border: 1px solid #d8e5f0; border-radius: 14px; background: #f3f8fd; }
.feature-type-picker input { position: absolute; opacity: 0; pointer-events: none; }
.feature-type-picker span { min-height: 39px; display: grid; place-items: center; border-radius: 10px; color: #49647f; font-size: 11px; font-weight: 850; cursor: pointer; }
.feature-type-picker input:checked + span { color: #fff; background: linear-gradient(135deg,#256edb,#46b8dc); box-shadow: 0 6px 15px rgba(37,110,219,.22); }
.position-card { display: grid; grid-template-columns: 42px minmax(0,1fr); gap: 10px; align-items: center; padding: 10px; border: 1px solid #d6e4f0; border-radius: 14px; background: #f6faff; }
.position-card > span { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: #e5f2ff; font-size: 20px; }
.position-card strong, .position-card small { display: block; }
.position-card small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.position-card.ready { border-color: #a9ddba; background: #f0fbf3; }
.position-card.ready > span { background: #ddf5e5; }
.position-actions, .drawing-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.drawing-actions { grid-template-columns: repeat(3, 1fr); }
.position-actions button, .drawing-actions button { min-height: 42px; padding: 9px; border: 1px solid #cfe0ef; border-radius: 12px; color: #174482; background: #eef6ff; font-size: 11px; font-weight: 850; cursor: pointer; }
.primary-save { min-height: 50px; border: 0; border-radius: 14px; color: #fff; background: linear-gradient(135deg,#1f69db,#42b8da); box-shadow: 0 13px 27px rgba(30,103,204,.25); font-weight: 900; cursor: pointer; }
.primary-save:disabled { opacity: .58; cursor: wait; }
.danger-delete {
    min-height: 48px; border: 1px solid #efb8be; border-radius: 14px;
    color: #a61e2d; background: #fff3f4; font-weight: 900; cursor: pointer;
}
.danger-delete:hover, .danger-delete:focus-visible { border-color: #d94b59; background: #ffe8eb; outline: 0; }
.danger-delete:disabled { opacity: .55; cursor: wait; }

/* Toast und Laden */
.toast-stack { position: fixed; z-index: 6000; top: calc(76px + var(--safe-top)); left: 50%; width: min(420px, calc(100% - 24px)); transform: translateX(-50%); display: grid; gap: 8px; pointer-events: none; }
.toast { padding: 12px 14px; border: 1px solid rgba(255,255,255,.42); border-radius: 14px; color: #fff; background: rgba(10,45,96,.94); box-shadow: 0 14px 35px rgba(4,31,69,.28); font-size: 13px; font-weight: 800; line-height: 1.45; backdrop-filter: blur(13px); animation: toast-in .22s ease both; }
.toast.ok { background: rgba(18,111,65,.95); }
.toast.err { background: rgba(157,38,46,.96); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
.loading-cover { position: fixed; z-index: 7000; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; color: #fff; background: linear-gradient(145deg,#072757,#166ebd); transition: opacity .25s ease, visibility .25s ease; }
.loading-cover.done { opacity: 0; visibility: hidden; }
.spinner { width: 46px; height: 46px; border: 4px solid rgba(255,255,255,.22); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
    .editor-topbar { min-height: calc(61px + var(--safe-top)); padding-top: calc(7px + var(--safe-top)); padding-bottom: 7px; }
    .editor-brand img { width: 35px; height: 35px; }
    .editor-brand strong { font-size: 15px; }
    .save-state { padding: 6px 8px; }
    .save-state strong { display: none; }
    .editor-user > span { display: none; }
    .map-toolbar { top: 9px; }
    .map-toolbar button { min-height: 36px; padding: 7px 9px; }
    .map-actions { bottom: calc(14px + var(--safe-bottom)); }
    .search-panel {
        top: 8px; right: calc(8px + var(--safe-right));
        width: calc(100% - 16px - var(--safe-left) - var(--safe-right));
        max-height: min(58dvh, 560px);
    }
    .editor-sheet {
        top: auto; left: calc(7px + var(--safe-left)); right: calc(7px + var(--safe-right)); bottom: calc(7px + var(--safe-bottom));
        width: auto; max-height: min(68dvh, 660px); border-radius: 25px 25px 18px 18px;
        transform: translateY(0); transition: transform .22s ease, max-height .22s ease;
    }
    .editor-sheet.collapsed { max-height: 48px; }
    .editor-sheet.collapsed .sheet-head, .editor-sheet.collapsed .sheet-body { visibility: hidden; }
    .sheet-grip {
        flex: 0 0 38px; width: 100%; display: flex; align-items: center; justify-content: center; gap: 9px;
        border: 0; color: #244d80; background: transparent; font-size: 11px; font-weight: 900; cursor: pointer;
    }
    .sheet-grip::after { content: "Karte anzeigen"; }
    .editor-sheet.collapsed .sheet-grip::after { content: "Bearbeitung öffnen"; }
    .sheet-grip span { width: 38px; height: 5px; border-radius: 99px; background: #c7d5e2; }
    .sheet-head { padding: 4px 15px 11px; }
    .sheet-head h2 { font-size: 21px; }
    .sheet-body { padding: 12px 13px calc(16px + var(--safe-bottom)); }
    .object-preview { margin: -12px -13px 13px; }
    .object-preview img { height: 128px; }
    .leaflet-control-zoom { margin-top: 63px !important; }
}

@media (max-width: 390px) {
    .map-toolbar button span { display: none; }
    .map-toolbar button { width: 39px; padding: 7px; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid label.full, .form-grid .full { grid-column: auto; }
    .drawing-actions { grid-template-columns: 1fr; }
}

@media (min-width: 1100px) {
    .editor-sheet:not([hidden]) ~ * { }
    .map-actions { right: 455px; }
    .search-panel { right: 455px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
