*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Атрибут hidden должен работать всегда: классы с display (например, .voice-preview)
   перебивают UA-правило [hidden]{display:none} — без этого скрытые блоки видимы */
[hidden] {
    display: none !important;
}

body {
    font-family: 'Open Sans', sans-serif;
    background: url("/static/img/paper-fibers.5f93b84dd8f8.png") repeat, var(--paper);
    color: var(--ink);
    min-height: 100vh;
    line-height: 1.6;
}

/* Navigation */
.navbar {
    background: var(--card-bg);
    border-bottom: 2px dashed var(--sepia);
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-inner {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}

.nav-brand {
    font-family: 'Fraunces', serif;
    font-size: 24px;
    font-weight: 600;
    color: var(--sepia);
    text-decoration: none;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 24px;
}

.nav-links a {
    color: var(--ink);
    text-decoration: none;
    font-size: 20px;
    font-weight: 600;
    transition: color 0.2s;
}

.nav-links a:hover {
    color: var(--sepia);
}

.nav-badge-link {
    position: relative;
}

.badge {
    position: absolute;
    top: -8px;
    right: -12px;
    background: var(--terracotta);
    color: var(--input-bg);
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
    display: none;  /* показывается JS (badge.style.display = 'inline-block') */
}

/* Django-messages (вынесено из base.html) */
.messages-container { margin-bottom: 15px; }
.message-item { padding: 10px 15px; border-radius: 6px; margin-bottom: 8px; }
.message-success { background: #c8e6c9; color: #2e7d32; border: 1px solid #a5d6a7; }
.message-error { background: #ffcdd2; color: #c62828; border: 1px solid #ef9a9a; }
.message-info { background: #fff3e0; color: #e65100; border: 1px solid #ffcc80; }

.nav-user {
    color: var(--text-secondary);
    font-size: 20px;
}

/* Hauptinhalt */
.main-content {
    max-width: 1280px;
    /* width 100%: body — flex (style.css), иначе main сжимается по содержимому
       (шапка чата с малым числом кнопок сужала окно почти вдвое) */
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
    padding: 32px 24px;
}

/* Überschriften */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Fraunces', serif;
    color: var(--ink);
}

h1 { font-size: 30px; margin-bottom: 24px; color: var(--sepia); text-align: center; text-shadow: 1px 1px 2px rgba(0,0,0,0.2); word-wrap: break-word; overflow-wrap: break-word; }
h2 { font-size: 26px; margin-bottom: 16px; border-bottom: 2px dashed var(--sepia); padding-bottom: 5px; }
h3 { font-size: 20px; margin-bottom: 8px; }

/* Karten */
.card {
    background: var(--card-bg);
    border: 3px solid var(--card-border);
    border-radius: var(--radius);
    padding: 24px;
    margin: 0 auto;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 32px;
    border: none;
    border-radius: 6px;
    font-family: 'Open Sans', sans-serif;
    font-size: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
    text-decoration: none;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
    background: var(--sepia);
    color: var(--input-bg);
}

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

.btn-secondary {
    background: var(--sepia);
    color: var(--input-bg);
    border: 2px solid var(--sepia);
}

.btn-secondary:hover { background: var(--sepia-deep); }

.btn-danger {
    background: transparent;
    color: var(--terracotta);
    border: 2px solid var(--terracotta);
}

.btn-danger:hover { background: rgba(204, 0, 0, 0.06); }

.btn-success {
    background: var(--forest);
    color: #fff;
}

.btn-success:hover { background: #3d5744; }  /* --forest затемнён */

.btn-warning {
    background: var(--gold);
    color: var(--ink);
}

.btn-warning:hover { background: #b08f1d; }  /* --gold затемнён */

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-sm { padding: 10px 20px; font-size: 18px; }
.btn-full { width: 100%; }

/* Formulare */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 20px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid var(--card-border);
    border-radius: 5px;
    font-family: 'Open Sans', sans-serif;
    font-size: 20px;
    color: var(--ink);
    background: var(--input-bg);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--sepia-deep);
}

.form-error {
    color: var(--terracotta);
    font-size: 15px;
    margin-bottom: 12px;
    padding: 10px;
    background: rgba(204, 0, 0, 0.08);
    border: 1px solid var(--terracotta);
    border-radius: 5px;
}

.form-hint {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Authentifizierung */
.auth-card {
    background: var(--card-bg);
    border: 3px solid var(--card-border);
    border-radius: var(--radius);
    padding: 40px;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 420px;
}

.auth-title {
    text-align: center;
    margin-bottom: 32px;
}

.auth-link {
    text-align: center;
    margin-top: 20px;
    font-size: 16px;
    color: var(--text-secondary);
}

.auth-link a {
    color: var(--sepia);
    text-decoration: none;
    font-weight: 600;
}

.auth-link a:hover { color: var(--sepia-deep); }

/* Modale Fenster */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(60, 50, 40, 0.5);
    /* Выше Leaflet (панели 400, контролы 1000) — иначе модалки оказывались под картой */
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s;
    overflow: hidden;
}

.modal {
    background: var(--card-bg);
    border: 3px solid var(--card-border);
    border-radius: var(--radius);
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
    max-width: 640px;
    width: 90%;
    min-width: 0;
    max-height: 85vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 32px;
    position: relative;
    animation: slideUp 0.25s;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    transition: background 0.2s;
}

.modal-close:hover { background: rgba(92, 64, 51, 0.1); }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Benachrichtigungen */
.toast-container {
    position: fixed;
    top: 80px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--card-bg);
    border: 3px solid var(--card-border);
    border-radius: 5px;
    padding: 14px 20px;
    box-shadow: inset 0 0 8px rgba(0,0,0,0.15);
    font-size: 16px;
    max-width: 360px;
    animation: slideIn 0.3s;
}

.toast-success { border-left: 4px solid var(--sepia); }
.toast-error { border-left: 4px solid var(--terracotta); }
.toast-info { border-left: 4px solid var(--sepia); }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Platzhalter für leeren Zustand */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-secondary);
}

.empty-state h2 { border-bottom: none; margin-bottom: 8px; }
.empty-state p { margin-bottom: 24px; }

/* Suche */
.search-bar {
    position: relative;
    margin-bottom: 24px;
}

.search-bar input {
    width: 100%;
    padding: 14px 20px;
    padding-left: 48px;
    border: 2px solid var(--card-border);
    border-radius: var(--radius);
    font-family: 'Open Sans', sans-serif;
    font-size: 16px;
    background: var(--input-bg);
    color: var(--ink);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.search-bar input:focus {
    outline: none;
    border-color: var(--sepia-deep);
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 18px;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border: 3px solid var(--card-border);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
    z-index: 50;
    max-height: 300px;
    overflow-y: auto;
}

.search-result-item {
    padding: 12px 20px;
    border-bottom: 1px dashed var(--card-border);
    cursor: pointer;
    transition: background 0.15s;
}

.search-result-item:hover { background: rgba(139, 90, 43, 0.08); }
.search-result-item:last-child { border-bottom: none; }

/* Breadcrumbs */
.breadcrumbs {
    display: flex;
    justify-content: center;
    gap: 8px;
    align-items: center;
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.breadcrumbs a {
    color: var(--sepia);
    text-decoration: none;
}

.breadcrumbs .sep { color: var(--sepia); }

/* Seite mit Titel und Aktion */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
}

.page-header h1 { margin-bottom: 0; }

/* Text */
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: 15px; }
.text-center { text-align: center; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 20px !important;
    color: var(--ink) !important;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    accent-color: var(--sepia);
}

/* ── Adaptive Formularraster ── */
.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

/* ── Burger-Button ── */
.burger-btn {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    z-index: 110;
}

.burger-btn span {
    display: block;
    width: 24px;
    height: 3px;
    background: var(--sepia);
    border-radius: 2px;
    transition: transform 0.3s, opacity 0.3s;
}

/* ── Tablets (≤1024px) ── */
@media (max-width: 1024px) {
    .main-content {
        padding: 24px 16px;
    }
}

/* ── Mobil (≤768px) — Navigation ── */
@media (max-width: 768px) {
    .burger-btn {
        display: flex;
    }

    .nav-links {
        display: none;
        position: absolute;
        top: 60px;
        left: 0;
        right: 0;
        background: var(--card-bg);
        border-bottom: 3px solid var(--card-border);
        flex-direction: column;
        gap: 0;
        padding: 8px 0;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        z-index: 105;
    }

    .nav-links.open {
        display: flex;
    }

    .nav-links a,
    .nav-links .nav-user {
        padding: 14px 20px;
        font-size: 20px;
        border-bottom: 1px dashed rgba(139, 90, 43, 0.2);
        width: 100%;
    }

    .nav-links a:last-child {
        border-bottom: none;
    }

    .nav-badge-link .badge {
        right: 20px;
        top: 10px;
    }

    .nav-inner {
        position: relative;
    }
}

/* ── Mobil (≤640px) — Inhalt und Karten ── */
@media (max-width: 640px) {
    .main-content {
        padding: 16px 12px;
    }

    h1 { font-size: 24px; margin-bottom: 16px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }

    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .page-header h1 {
        margin-bottom: 0;
    }

    .page-header > div {
        flex-wrap: wrap;
    }

    .card {
        padding: 16px;
    }

    .card-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .form-row-2,
    .form-row-3 {
        grid-template-columns: 1fr !important;
        gap: 0 !important;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 20px;
    }

    select {
        max-width: 100%;
        min-width: 0;
    }

    select option {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .modal {
        width: 95%;
        padding: 16px;
        max-width: none;
        min-width: 0;
        overflow-x: hidden;
        word-wrap: break-word;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    .toast-container {
        left: 12px;
        right: 12px;
    }

    .toast {
        max-width: none;
    }

    .auth-card {
        padding: 24px 16px;
        margin: 0 12px;
    }

    .card-flex-row {
        flex-direction: column !important;
        gap: 12px !important;
        overflow-x: hidden;
    }

    .card-flex-row > * {
        min-width: 0;
        max-width: 100%;
    }

    .card-flex-row img {
        max-width: 100%;
        height: auto;
    }

    .card-actions {
        width: 100%;
    }

    .card-actions .btn {
        flex: 1;
    }

    .card-actions form {
        flex: 1;
    }

    .card-actions form .btn {
        width: 100%;
    }
}

/* Доступность: видимый фокус для клавиатуры */
:focus-visible {
    outline: 2px solid var(--sepia-deep);
    outline-offset: 2px;
}

/* Доступность: отключить анимации для пользователей с prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
