:root {
    --bg: #eef2f4;
    --bg-accent: #d8e6e1;
    --surface: rgba(255, 255, 255, 0.84);
    --surface-strong: rgba(255, 255, 255, 0.94);
    --text: #10231f;
    --muted: #56716a;
    --line: rgba(16, 35, 31, 0.14);
    --primary: #0f7a70;
    --primary-strong: #0d655d;
    --danger: #b23a48;
    --shadow: 0 18px 40px rgba(16, 35, 31, 0.12);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    color: var(--text);
    font-family: 'Plus Jakarta Sans', sans-serif;
    background: linear-gradient(140deg, var(--bg), var(--bg-accent));
    min-height: 100vh;
}

.app-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 15% 10%, rgba(15, 122, 112, 0.22), transparent 34%),
        radial-gradient(circle at 90% 80%, rgba(178, 58, 72, 0.12), transparent 38%);
}

.app-shell {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px 1fr;
}

.sidebar {
    background: rgba(13, 46, 39, 0.86);
    backdrop-filter: blur(12px);
    color: #f2faf8;
    border-right: 1px solid rgba(255, 255, 255, 0.12);
    padding: 24px 16px;
}

.brand-wrap { margin-bottom: 24px; }
.brand-title {
    margin: 0;
    font-size: 1.15rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.brand-subtitle {
    margin: 8px 0 0;
    color: rgba(242, 250, 248, 0.75);
    font-size: 0.85rem;
}

.menu {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nav-link {
    color: #ebf6f4;
    text-decoration: none;
    border: 1px solid rgba(235, 246, 244, 0.2);
    border-radius: 14px;
    padding: 11px 12px;
    transition: 0.2s ease;
}

.nav-link:hover,
.nav-link.active {
    background: rgba(235, 246, 244, 0.16);
    transform: translateX(3px);
}

.main-content {
    padding: 22px;
}

.mobile-topbar { display: none; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.page-title {
    margin: 0;
    font-size: 1.55rem;
    font-family: 'Space Grotesk', sans-serif;
}

.page-subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.93rem;
}

.flash {
    background: #e8fff9;
    border: 1px solid #8acfc1;
    border-radius: 14px;
    padding: 10px 14px;
    margin-bottom: 14px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 18px;
    box-shadow: var(--shadow);
}

.table-card { padding: 10px 12px; }
.table-wrap { overflow-x: auto; }

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 14px;
}

.tile {
    display: block;
    text-decoration: none;
    color: inherit;
    border: 1px solid var(--line);
    background: linear-gradient(160deg, var(--surface-strong), #f2f9f6);
    border-radius: 15px;
    padding: 14px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tile:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 25px rgba(15, 122, 112, 0.18);
}

.tile h3 { margin: 0 0 6px; }
.tile p { margin: 0; color: var(--muted); }
.tile-tags { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }

.tag {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.78rem;
    background: rgba(15, 122, 112, 0.12);
    border: 1px solid rgba(15, 122, 112, 0.2);
}

.toolbar,
.form-actions,
.row-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.btn {
    display: inline-block;
    border: none;
    text-decoration: none;
    border-radius: 12px;
    padding: 10px 13px;
    font-size: 0.9rem;
    font-weight: 700;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
}

.btn:hover { background: var(--primary-strong); }

.btn.ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line);
}

.btn.danger { background: var(--danger); }
.btn.tiny { padding: 7px 10px; font-size: 0.82rem; }

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid rgba(16, 35, 31, 0.1);
    white-space: nowrap;
    vertical-align: top;
}

th {
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.76rem;
}

.muted {
    color: var(--muted);
    font-size: 0.82rem;
}

.form-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.9rem;
    font-weight: 600;
}

.field input,
.field select,
.field textarea {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px;
    background: var(--surface-strong);
    font: inherit;
    font-weight: 400;
}

.select2-container {
    width: 100% !important;
}

.select2-container .select2-selection--single {
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-strong);
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 40px;
    color: var(--text);
    padding-left: 10px;
    padding-right: 28px;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 40px;
    right: 6px;
}

.select2-container--default .select2-dropdown {
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}

.select2-search__field {
    font-family: 'Plus Jakarta Sans', sans-serif;
}

.field textarea {
    min-height: 95px;
    resize: vertical;
}

.field-full { grid-column: 1 / -1; }

.photo-preview {
    width: min(100%, 360px);
    max-height: 260px;
    object-fit: cover;
    border-radius: 12px;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.epi-thumb {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--line);
    display: block;
}

.epi-name-link {
    color: var(--text);
    text-decoration: none;
    border-bottom: 1px dashed rgba(16, 35, 31, 0.25);
}

.epi-name-link:hover {
    color: var(--primary-strong);
    border-bottom-color: var(--primary-strong);
}

.epi-hero {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 18px;
    background:
        radial-gradient(circle at 90% 0%, rgba(15, 122, 112, 0.12), transparent 40%),
        linear-gradient(150deg, rgba(255, 255, 255, 0.94), rgba(242, 249, 246, 0.95));
}

.epi-hero-media {
    border-radius: 16px;
    border: 1px solid var(--line);
    overflow: hidden;
    min-height: 240px;
    background: rgba(255, 255, 255, 0.65);
}

.epi-hero-photo {
    width: 100%;
    height: 100%;
    max-height: 340px;
    object-fit: cover;
    display: block;
}

.epi-hero-placeholder {
    min-height: 240px;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-weight: 600;
}

.epi-head-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.epi-badge {
    margin: 0;
    display: inline-block;
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(15, 122, 112, 0.14);
    border: 1px solid rgba(15, 122, 112, 0.28);
    font-size: 0.8rem;
    font-weight: 700;
}

.epi-meta-grid {
    margin-top: 14px;
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.meta-item {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.72);
}

.meta-item span {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
}

.meta-item strong {
    display: block;
    margin-top: 3px;
    font-size: 0.93rem;
}

.epi-notes {
    margin-top: 14px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.72);
}

.epi-notes h3 {
    margin: 0 0 6px;
    font-family: 'Space Grotesk', sans-serif;
}

.epi-notes p {
    margin: 0;
    white-space: pre-wrap;
}

.incidents-table td {
    white-space: normal;
    min-width: 120px;
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: -100%;
        width: min(80vw, 320px);
        transition: left 0.25s ease;
        z-index: 20;
    }

    .sidebar.open {
        left: 0;
    }

    .main-content {
        padding: 14px;
    }

    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 10px;
        margin-bottom: 14px;
    }

    .menu-toggle {
        border: 1px solid var(--line);
        background: var(--surface-strong);
        border-radius: 10px;
        padding: 8px 10px;
        font-weight: 700;
    }

    .mobile-title {
        font-weight: 700;
        font-family: 'Space Grotesk', sans-serif;
    }

    .page-title { font-size: 1.2rem; }

    .epi-hero {
        grid-template-columns: 1fr;
    }
}
