:root {
    --bg: #f2f2f7;
    --card: rgba(255, 255, 255, .82);
    --line: rgba(60, 60, 67, .12);
    --fill: rgba(120, 120, 128, .12);
    --text: #1c1c1e;
    --muted: #6e6e73;
    --accent: #4a7296;        /* gedämpftes Stahlblau wie die Dashboard-Kacheln */
    --accent-dark: #3b5d7b;
    --accent-soft: rgba(74, 114, 150, .12);
    --green: #5b8a6d;
    --red: #c0504d;
    --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
    background:
        radial-gradient(900px 500px at 90% -10%, rgba(74, 114, 150, .10), transparent 60%),
        radial-gradient(700px 400px at -10% 110%, rgba(91, 138, 109, .08), transparent 60%),
        var(--bg);
    background-attachment: fixed;
    color: var(--text);
    font: 15px/1.47 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
    padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
}

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
code { background: var(--fill); padding: 1px 6px; border-radius: 6px; font-size: .9em; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Buttons & Felder ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: 0; background: var(--fill); color: var(--text);
    border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 500; cursor: pointer;
}
.btn:hover { background: rgba(120, 120, 128, .2); }
.btn-primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-dark); }

.icon-btn {
    display: inline-grid; place-items: center; width: 36px; height: 36px;
    border-radius: 10px; border: 0; background: transparent;
    color: var(--accent); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn.danger { color: var(--muted); }
.icon-btn.danger:hover { color: var(--red); background: rgba(192, 80, 77, .1); }
.icon-btn.active { background: var(--accent-soft); }

input, textarea {
    width: 100%; font: inherit; color: var(--text);
    background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.alert {
    background: rgba(192, 80, 77, .08); border: 1px solid rgba(192, 80, 77, .25);
    color: #8f2f2c; border-radius: 10px; padding: 10px 14px; margin: 14px 0 0;
}

/* ---------- Login / Einrichtung ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
    width: 100%; max-width: 380px; padding: 30px 28px 22px;
    background: var(--card); border-radius: 22px;
    backdrop-filter: blur(30px) saturate(1.6); -webkit-backdrop-filter: blur(30px) saturate(1.6);
    box-shadow: 0 1px 0 rgba(255,255,255,.8) inset, 0 20px 50px rgba(30, 40, 60, .12);
}
.auth-mark {
    width: 50px; height: 50px; border-radius: 13px; display: grid; place-items: center;
    background: var(--accent); color: #fff; margin-bottom: 18px;
}
.auth-mark svg { width: 24px; height: 24px; }
.auth h1 { margin: 0 0 4px; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.auth p { margin: 0 0 16px; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.auth .btn { width: 100%; margin-top: 20px; padding: 11px; }
.remember { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 14px; color: var(--muted); cursor: pointer; }
.remember input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.setup-line { font-family: ui-monospace, Consolas, monospace; font-size: 12px; resize: none; }
.back-link { display: inline-flex; align-items: center; gap: 4px; margin-top: 18px; text-decoration: none; font-size: 14px; }
.back-link svg { width: 16px; height: 16px; }

/* ---------- Kopfzeile ---------- */
.topbar {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; gap: 12px;
    padding: 10px max(16px, calc((100% - 960px) / 2 + 16px));
    padding-top: calc(10px + env(safe-area-inset-top, 0));
    background: rgba(242, 242, 247, .78);
    backdrop-filter: blur(24px) saturate(1.8); -webkit-backdrop-filter: blur(24px) saturate(1.8);
    border-bottom: 1px solid var(--line);
}
.topbar-title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.topbar-title h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.title-icon { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; }
.title-icon svg { width: 17px; height: 17px; }
.storage { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.storage-bar { width: 110px; height: 6px; border-radius: 6px; background: var(--fill); overflow: hidden; }
.storage-bar span { display: block; height: 100%; width: 0; background: var(--accent); }
.storage-bar.warn span { background: var(--red); }
.logout { margin: 0; }

/* ---------- Inhalt ---------- */
.cloud { max-width: 960px; margin: 0 auto; padding: 22px 16px 60px; }

.drop {
    display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center;
    padding: 34px 20px; border-radius: 18px; cursor: pointer;
    border: 2px dashed rgba(74, 114, 150, .35); background: rgba(255, 255, 255, .55);
    transition: background .15s, border-color .15s;
}
.drop:hover, .drop.over { background: #fff; border-color: var(--accent); }
.drop-icon { width: 54px; height: 54px; border-radius: 15px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 8px; }
.drop-icon svg { width: 28px; height: 28px; }
.drop-main { font-size: 17px; font-weight: 600; }
.drop-main u { text-decoration-color: var(--accent); text-underline-offset: 3px; color: var(--accent); }
.drop-sub { font-size: 13px; color: var(--muted); }

/* Upload-Warteschlange */
.queue { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; }
.queue li {
    display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center;
    padding: 10px 14px; border-radius: 12px; background: var(--card);
    box-shadow: 0 1px 3px rgba(30, 40, 60, .06);
}
.q-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.q-state { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.q-bar { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: var(--fill); overflow: hidden; }
.q-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.queue li.ok .q-state { color: var(--green); }
.queue li.ok .q-bar span { background: var(--green); }
.queue li.err .q-state { color: var(--red); white-space: normal; }
.queue li.err .q-bar span { background: var(--red); }

/* Dateiliste im iOS-Listenstil */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 30px 4px 10px; }
.list-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.count { color: var(--muted); font-weight: 500; }
.list-head input { max-width: 240px; padding: 7px 12px; background: var(--fill); border-color: transparent; }

.files { list-style: none; margin: 0; padding: 0; border-radius: var(--radius); overflow: hidden; background: var(--card); box-shadow: 0 1px 3px rgba(30, 40, 60, .06); }
.files:empty { display: none; }
.file { position: relative; }
.file + .file::before { content: ""; position: absolute; top: 0; left: 76px; right: 0; border-top: 1px solid var(--line); }
.file-row { display: grid; grid-template-columns: 46px 1fr auto auto; gap: 14px; align-items: center; padding: 10px 10px 10px 16px; }
.badge {
    width: 46px; height: 46px; border-radius: 11px; display: grid; place-items: center;
    font-size: 11px; font-weight: 700; text-transform: uppercase; color: #fff; background: #8e8e93;
}
.badge.pdf { background: #b5524f; }
.badge.ppt { background: #c27a46; }
.badge.doc { background: #4a7296; }
.badge.xls { background: #5b8a6d; }
.badge.img { background: #7f6a9e; }
.badge.zip { background: #a08a4a; }
.file-info { min-width: 0; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.file-meta { font-size: 13px; color: var(--muted); }
.file-meta .shared { color: var(--accent); }
.file-size { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.file-actions { display: flex; gap: 2px; }

/* Freigabe */
.share { padding: 2px 16px 14px 76px; }
.share-new { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.share-new .btn { padding: 6px 12px; font-size: 13px; }
.share-links { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.share-links li { display: grid; grid-template-columns: 1fr auto auto auto; gap: 6px; align-items: center; }
.share-links input { padding: 6px 10px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; background: var(--fill); border-color: transparent; }
.share-links small { color: var(--muted); white-space: nowrap; }

.empty { text-align: center; color: var(--muted); padding: 30px 0; }

.toast {
    position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0)); transform: translateX(-50%);
    background: rgba(28, 28, 30, .88); color: #fff; border-radius: 12px;
    padding: 10px 16px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}

/* ---------- Mobil ---------- */
@media (max-width: 640px) {
    .topbar { gap: 8px; }
    .storage-bar { width: 50px; }
    .cloud { padding: 16px 12px 60px; }
    .file-row { grid-template-columns: 40px 1fr auto; gap: 10px; padding-left: 12px; }
    .badge { width: 40px; height: 40px; font-size: 10px; }
    .file + .file::before { left: 62px; }
    .file-size { display: none; }
    .file-actions { grid-column: 2 / -1; margin-top: -4px; }
    .share { padding-left: 12px; }
    .share-links li { grid-template-columns: 1fr auto auto; }
    .share-links small { grid-column: 1 / -1; }
    .list-head input { max-width: 150px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Gemeindewappen ---------- */
/* Großes Wappen als ruhiger, auslaufender Hintergrund (Login und Cloud) */
.bg-wappen {
    position: fixed; z-index: 0; pointer-events: none;
    right: -6vw; bottom: -8vh; height: 92vh; aspect-ratio: 5 / 6;
    display: flex; align-items: flex-end; justify-content: flex-end;
}
.bg-wappen img {
    height: 100%; width: auto; object-fit: contain; opacity: .09;
    filter: saturate(.7);
    /* läuft nach oben-links weich in den Hintergrund aus */
    -webkit-mask-image: radial-gradient(ellipse 75% 70% at 70% 65%, #000 30%, transparent 78%);
            mask-image: radial-gradient(ellipse 75% 70% at 70% 65%, #000 30%, transparent 78%);
}
.auth, .topbar, .cloud { position: relative; z-index: 1; }
.topbar { position: sticky; }

/* Login: Wappen sitzt groß über der Karte, nur der untere Rand läuft weich in sie hinein */
.auth-card { position: relative; padding-top: 112px; margin-top: 96px; text-align: left; }
.auth-wappen {
    position: absolute; left: 50%; top: -92px; transform: translateX(-50%);
    width: 160px; height: 192px; display: grid; place-items: center;
    /* Schatten am Wrapper, damit er der ausgeblendeten Form folgt (kein sichtbares Rechteck) */
    filter: drop-shadow(0 14px 22px rgba(30, 40, 60, .20));
}
.auth-wappen::before {           /* farbiger Lichthof hinter dem Wappen */
    content: ""; position: absolute; inset: -40px -60px;
    background: radial-gradient(closest-side, rgba(74, 114, 150, .22), transparent);
    z-index: -1;
}
.auth-wappen img {
    position: relative; width: 100%; height: 100%; object-fit: contain;
    -webkit-mask-image: linear-gradient(to bottom, #000 74%, rgba(0, 0, 0, .55) 90%, transparent 100%);
            mask-image: linear-gradient(to bottom, #000 74%, rgba(0, 0, 0, .55) 90%, transparent 100%);
    animation: wappen-in .9s cubic-bezier(.2, .8, .2, 1) both;
}
.auth-gemeinde {
    margin: 4px 0 18px !important; font-size: 13px; font-weight: 600; letter-spacing: .01em;
    color: var(--accent); text-align: center;
}
.auth-card:has(.auth-wappen) h1 { text-align: center; }
.auth-card:has(.auth-wappen) h1 + p { text-align: center; }

@keyframes wappen-in {
    from { opacity: 0; transform: translateY(10px) scale(.96); }
    to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .auth-wappen img { animation: none; } }

@media (max-width: 640px) {
    .bg-wappen { right: -25vw; bottom: -4vh; height: 70vh; }
    .bg-wappen img { opacity: .07; }
    .auth-card { padding-top: 96px; margin-top: 84px; }
    .auth-wappen { width: 136px; height: 164px; top: -78px; }
}