:root {
    --bg-main: #f4f7f1;
    --bg-card: #ffffff;
    --bg-soft: #fbfdf9;

    --primary: #3f7d20;
    --primary-dark: #2f6118;
    --primary-light: #e7f3df;

    --text-main: #1f2a1b;
    --text-muted: #6b7566;

    --border: #dce5d5;
    --danger: #c0392b;
    --danger-dark: #922b21;
    --danger-bg: #fdecea;
    --success: #217a21;
    --success-bg: #e7f7e7;

    --warning: #d89200;
    --warning-bg: #fff4d8;

    --radius: 18px;
    --radius-small: 12px;
    --shadow: 0 20px 45px rgba(31, 42, 27, 0.12);
    --shadow-small: 0 12px 24px rgba(31, 42, 27, 0.10);
}

/* =========================
   GLOBAL
========================= */

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
}

a {
    color: inherit;
}

h1,
h2,
h3,
p {
    line-height: 1.35;
}

.muted {
    color: var(--text-muted);
}

/* =========================
   BUTTONS
========================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius-small);
    padding: 14px 18px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: 0.2s ease;
    white-space: nowrap;
}

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

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

.btn-secondary {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.btn-secondary:hover {
    background: #d8edcc;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: var(--danger-dark);
}

/* =========================
   ALERTS
========================= */

.alert {
    padding: 13px 15px;
    border-radius: var(--radius-small);
    margin-bottom: 18px;
    font-size: 15px;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(192, 57, 43, 0.25);
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(33, 122, 33, 0.25);
}

/* =========================
   AUTH / LOGIN
========================= */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at top left, rgba(63, 125, 32, 0.12), transparent 35%),
        var(--bg-main);
}

.auth-wrapper {
    width: 100%;
    max-width: 430px;
}

.auth-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 36px 32px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

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

.logo-icon {
    font-size: 42px;
    margin-bottom: 10px;
}

.auth-logo h1 {
    margin: 0;
    font-size: 30px;
    color: var(--primary);
}

.auth-logo p {
    margin: 8px 0 0;
    color: var(--text-muted);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.auth-form label {
    font-weight: 700;
}

.auth-form input {
    width: 100%;
    padding: 15px 16px;
    border-radius: var(--radius-small);
    border: 1px solid var(--border);
    font-size: 17px;
    outline: none;
}

.auth-form input[name="code"] {
    letter-spacing: 3px;
    text-align: center;
    font-size: 20px;
}

.auth-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
}

/* =========================
   APP FRONTEND
========================= */

.app-page {
    min-height: 100vh;
    background: var(--bg-main);
}

.app-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 18px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-icon {
    width: 48px;
    height: 48px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    flex-shrink: 0;
}

.app-brand h1 {
    margin: 0;
    font-size: 24px;
    color: var(--primary);
}

.app-brand p {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 14px;
}

.app-main {
    max-width: 1350px;
    margin: 0 auto;
    padding: 32px;
}

.welcome-card,
.content-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
    margin-bottom: 24px;
}

.welcome-card h2,
.content-card h2 {
    margin-top: 0;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.section-header p {
    margin-bottom: 0;
    color: var(--text-muted);
}

/* =========================
   FILTER
========================= */

.filter-box {
    display: grid;
    grid-template-columns: 1fr 230px auto;
    gap: 14px;
    margin-top: 24px;
}

.filter-box input,
.filter-box select {
    padding: 14px 16px;
    border-radius: var(--radius-small);
    border: 1px solid var(--border);
    font-size: 16px;
    font-family: inherit;
    outline: none;
    background: white;
}

.filter-box input:focus,
.filter-box select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
}

/* =========================
   MAP + LIST
========================= */

.map-list-layout {
    display: grid;
    grid-template-columns: 1fr 370px;
    gap: 22px;
    margin-top: 24px;
    align-items: stretch;
}

#mainMap {
    width: 100%;
    height: 560px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    z-index: 1;
}

#locationMap {
    width: 100%;
    height: 450px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    margin-bottom: 22px;
    z-index: 1;
}

.location-panel {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    max-height: 560px;
    overflow-y: auto;
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 0 16px;
    gap: 12px;
}

.list-header h3 {
    margin: 0;
}

.list-header p {
    margin: 0;
    color: var(--text-muted);
}

.location-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
}

.location-list.compact {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.location-card {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    cursor: pointer;
    transition: 0.2s ease;
}

.location-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-small);
    border-color: rgba(63, 125, 32, 0.35);
}

.compact-card {
    padding: 16px;
}

.location-card h3 {
    margin: 12px 0 8px;
}

.compact-card h3 {
    margin: 10px 0 6px;
    font-size: 17px;
}

.location-card p {
    margin: 0 0 8px;
    color: var(--text-muted);
}

.compact-card p {
    font-size: 14px;
}

.location-badge {
    display: inline-block;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
}

.location-badge.automat {
    background: var(--warning-bg);
    color: #8a5a00;
}

.location-badge.bauernladen {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.location-actions,
.modal-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 18px;
}

.location-actions a {
    color: var(--primary);
    font-weight: 800;
    text-decoration: none;
}

.location-actions a:hover {
    text-decoration: underline;
}

/* =========================
   LEAFLET MARKER
========================= */

.custom-marker-wrapper {
    background: transparent !important;
    border: none !important;
}

.custom-marker {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: white;
    border: 3px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.25);
    cursor: pointer;
    pointer-events: auto;
}

.automat-marker {
    border-color: var(--warning);
}

.bauernladen-marker {
    border-color: var(--primary);
}

.leaflet-marker-icon,
.leaflet-marker-shadow {
    pointer-events: auto;
}

/* =========================
   MODAL
========================= */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 22px;
    z-index: 9999;
}

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

.modal-card {
    width: 100%;
    max-width: 540px;
    background: white;
    border-radius: 22px;
    padding: 28px;
    box-shadow: 0 25px 70px rgba(0,0,0,0.25);
    position: relative;
    animation: modalIn 0.18s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 18px;
    border: none;
    background: var(--primary-light);
    color: var(--primary-dark);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
}

.modal-card h2 {
    margin: 16px 0 8px;
}

.modal-address {
    font-weight: 800;
    margin-bottom: 14px;
}

/* =========================
   EMPTY STATE
========================= */

.empty-state {
    margin-top: 28px;
    padding: 42px 24px;
    border: 2px dashed var(--border);
    border-radius: 16px;
    text-align: center;
    background: var(--bg-soft);
}

.small-empty {
    padding: 30px 18px;
    margin-top: 0;
}

.empty-icon {
    font-size: 42px;
    margin-bottom: 12px;
}

.empty-state h3 {
    margin: 0 0 8px;
}

.empty-state p {
    margin: 0;
    color: var(--text-muted);
}

/* =========================
   ADMIN LAYOUT
========================= */

.admin-page {
    min-height: 100vh;
    display: flex;
    background: var(--bg-main);
}

.admin-sidebar {
    width: 260px;
    min-height: 100vh;
    background: #1f2a1b;
    color: white;
    padding: 24px 18px;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1200;
}

.admin-logo {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 32px;
}

.admin-sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.admin-sidebar nav a {
    color: white;
    text-decoration: none;
    padding: 13px 14px;
    border-radius: 12px;
    font-weight: 700;
    transition: 0.2s ease;
}

.admin-sidebar nav a:hover {
    background: rgba(255,255,255,0.12);
}

.admin-content {
    margin-left: 260px;
    width: calc(100% - 260px);
}

.admin-topbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 18px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.admin-topbar h1 {
    margin: 0;
    color: var(--primary);
}

.admin-topbar p {
    margin: 4px 0 0;
    color: var(--text-muted);
}

.admin-main {
    padding: 32px;
}

/* =========================
   ADMIN FORMS
========================= */

.admin-form {
    display: flex;
    gap: 14px;
    align-items: center;
}

.admin-form-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.admin-form input,
.admin-form select,
.admin-form textarea,
.admin-form-column input,
.admin-form-column select,
.admin-form-column textarea {
    padding: 14px 16px;
    border-radius: var(--radius-small);
    border: 1px solid var(--border);
    font-size: 16px;
    width: 100%;
    font-family: inherit;
    outline: none;
    background: white;
}

.admin-form input:focus,
.admin-form select:focus,
.admin-form textarea:focus,
.admin-form-column input:focus,
.admin-form-column select:focus,
.admin-form-column textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
}

.admin-form-column textarea {
    min-height: 120px;
    resize: vertical;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
}

.checkbox-row input {
    width: 18px;
    height: 18px;
}

.admin-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* =========================
   TABLES
========================= */

.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 18px;
    overflow: hidden;
}

.admin-table th,
.admin-table td {
    padding: 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.admin-table th {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 800;
}

.admin-table tr:hover td {
    background: var(--bg-soft);
}

.admin-table .btn {
    padding: 9px 12px;
    font-size: 14px;
    margin: 3px 4px 3px 0;
}

/* =========================
   DASHBOARD STATS
========================= */

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 22px;
    margin-bottom: 24px;
}

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

.stat-card h3 {
    margin: 0 0 12px;
    color: var(--text-muted);
    font-size: 16px;
}

.stat-card strong {
    font-size: 32px;
    color: var(--primary);
}

/* =========================
   RESPONSIVE
========================= */

@media (max-width: 1100px) {
    .map-list-layout {
        grid-template-columns: 1fr;
    }

    .location-panel {
        max-height: none;
    }

    #mainMap {
        height: 430px;
    }

    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 900px) {
    .admin-page {
        display: block;
    }

    .admin-sidebar {
        position: relative;
        width: 100%;
        min-height: auto;
    }

    .admin-content {
        margin-left: 0;
        width: 100%;
    }

    .admin-topbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .admin-main {
        padding: 18px;
    }

    .admin-form {
        flex-direction: column;
        align-items: stretch;
    }

    .admin-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

@media (max-width: 850px) {
    .filter-box {
        grid-template-columns: 1fr;
    }

    .location-list {
        grid-template-columns: 1fr;
    }

    #mainMap {
        height: 380px;
    }

    .list-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
}

@media (max-width: 700px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 18px;
    }

    .app-main {
        padding: 18px;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .section-header .btn {
        width: 100%;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .auth-card {
        padding: 28px 22px;
    }

    .auth-logo h1 {
        font-size: 26px;
    }

    .modal-card {
        padding: 24px 20px;
    }

    .btn {
        width: 100%;
    }

    .modal-actions .btn {
        width: 100%;
    }
}

.product-select-box {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.product-category-box {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
}

.product-category-box h4 {
    margin: 0 0 14px;
    color: var(--primary-dark);
}

.product-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.product-checkbox {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 700;
}

.product-checkbox:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.product-checkbox input {
    width: 18px;
    height: 18px;
}

@media (max-width: 900px) {
    .product-checkbox-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 520px) {
    .product-checkbox-grid {
        grid-template-columns: 1fr;
    }
}