:root {
    --bg: #f4f7f6;
    --surface: #ffffff;
    --surface-strong: #eef3f1;
    --ink: #17211d;
    --muted: #68746f;
    --line: #dce5e1;
    --green: #168060;
    --green-dark: #0f5e48;
    --amber: #b7791f;
    --red: #b42318;
    --red-soft: #fff0ee;
    --shadow: 0 18px 45px rgba(23, 33, 29, 0.08);
}

* {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
    letter-spacing: 0;
}

body.auth-body {
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(120deg, rgba(16, 24, 21, 0.96), rgba(22, 128, 96, 0.78)),
        var(--bg);
}

a {
    color: inherit;
    text-decoration: none;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    padding: 28px 22px;
    background: #101815;
    color: #f7fbf9;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

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

.brand-mark {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--green);
    font-weight: 800;
    font-size: 24px;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: #abc0b8;
    margin-top: 3px;
}

.nav {
    display: grid;
    gap: 8px;
}

.nav a {
    padding: 13px 14px;
    border-radius: 8px;
    color: #dce8e3;
    transition: background 160ms ease, color 160ms ease;
}

.nav a.active,
.nav a:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.nav a.disabled {
    color: #6f8179;
    cursor: not-allowed;
}

.sidebar-note {
    margin-top: auto;
    padding: 16px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    display: grid;
    gap: 8px;
    color: #cddbd6;
    line-height: 1.45;
}

.sidebar-note strong {
    color: #ffffff;
}

.main {
    margin-left: 280px;
    padding: 34px;
    min-width: 0;
}

.topbar {
    width: min(1120px, 100%);
    margin: 0 auto 18px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 14px;
}

.topbar div {
    display: grid;
    text-align: right;
}

.topbar span {
    color: var(--muted);
    font-size: 13px;
    text-transform: capitalize;
}

.page-hero,
.page-heading,
.section,
.toolbar,
.table-panel,
.form-panel,
.empty-state {
    width: min(1120px, 100%);
    margin: 0 auto 24px;
}

.page-hero,
.page-heading {
    display: flex;
    justify-content: space-between;
    gap: 22px;
    align-items: center;
}

.page-hero {
    min-height: 250px;
    padding: 36px;
    border-radius: 8px;
    background:
        linear-gradient(110deg, rgba(16, 24, 21, 0.95), rgba(22, 128, 96, 0.82)),
        url("data:image/svg+xml,%3Csvg width='900' height='360' viewBox='0 0 900 360' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.13' stroke-width='2'%3E%3Cpath d='M80 270h740M120 80h660M180 130h240M500 130h180M180 185h180M430 185h290'/%3E%3Ccircle cx='188' cy='83' r='34'/%3E%3Ccircle cx='738' cy='252' r='58'/%3E%3Crect x='620' y='78' width='112' height='112' rx='8'/%3E%3C/g%3E%3C/svg%3E");
    background-size: cover;
    color: #ffffff;
    box-shadow: var(--shadow);
}

.page-hero h1,
.page-heading h1,
.section h2,
.empty-state h1 {
    margin: 6px 0 8px;
    line-height: 1.05;
}

.page-hero h1 {
    font-size: 46px;
}

.page-heading h1 {
    font-size: 34px;
}

.page-hero p,
.page-heading p,
.empty-state p {
    margin: 0;
    max-width: 680px;
    color: inherit;
    opacity: 0.78;
    line-height: 1.6;
}

.eyebrow {
    display: inline-flex;
    color: var(--green);
    text-transform: uppercase;
    font-size: 12px;
    font-weight: 800;
}

.page-hero .eyebrow {
    color: #bcebd9;
}

.button {
    border: 0;
    border-radius: 8px;
    min-height: 42px;
    padding: 11px 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 750;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}

.button.primary {
    background: var(--green);
    color: #ffffff;
}

.button.secondary {
    background: var(--surface-strong);
    color: var(--ink);
}

.button.ghost {
    background: transparent;
    color: var(--muted);
}

.button.danger {
    background: var(--red-soft);
    color: var(--red);
}

.button.light {
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
}

.button.small {
    min-height: 34px;
    padding: 8px 12px;
    font-size: 13px;
}

.metric-grid {
    width: min(1120px, 100%);
    margin: 0 auto 24px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.hero-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.metric {
    padding: 22px;
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.metric span {
    display: block;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: 10px;
}

.metric strong {
    font-size: 34px;
}

.section,
.table-panel,
.form-panel,
.empty-state {
    padding: 24px;
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.epi-grid {
    width: min(1120px, 100%);
    margin: 0 auto 24px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.epi-card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.epi-photo {
    background: #ffffff;
    aspect-ratio: 4 / 3;
    min-height: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-weight: 800;
}

.epi-photo img,
.photo-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.epi-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
}

.epi-content h2 {
    margin: 6px 0 0;
    font-size: 16px;
    line-height: 1.3;
}

.epi-data {
    margin: 0;
    display: grid;
    gap: 7px;
}

.epi-data div {
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr);
    gap: 8px;
}

.epi-data dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.epi-data dd {
    margin: 0;
    font-size: 12px;
    line-height: 1.35;
}

.epi-meta,
.card-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.code-count {
    border-radius: 999px;
    padding: 8px 12px;
    background: var(--surface-strong);
    color: var(--muted);
    font-weight: 800;
    font-size: 12px;
}

.sap-summary {
    font-size: 12px;
}

.card-actions form {
    margin: 0;
}

.epi-form-panel {
    max-width: 860px;
}

.photo-preview {
    min-height: 360px;
    border-radius: 8px;
    background: var(--surface-strong);
    overflow: hidden;
    display: grid;
    place-items: center;
}

.photo-preview div {
    display: grid;
    gap: 8px;
    padding: 24px;
    text-align: center;
    color: var(--muted);
}

.photo-preview strong {
    color: var(--ink);
    font-size: 20px;
}

.inline-photo-preview {
    width: min(360px, 100%);
    aspect-ratio: 4 / 3;
    border-radius: 8px;
    background: var(--surface-strong);
    display: grid;
    place-items: center;
    overflow: hidden;
    color: var(--muted);
    font-weight: 800;
}

.inline-photo-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    background: #ffffff;
}

.clickable-metric {
    transition: transform 160ms ease, box-shadow 160ms ease;
}

.clickable-metric:hover {
    transform: translateY(-2px);
}

.category-dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.category-stat-card {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 8px;
    background: #fbfdfc;
}

.category-stat-card strong {
    font-size: 14px;
    line-height: 1.3;
}

.category-stat-card span {
    font-size: 24px;
    font-weight: 850;
    color: var(--green-dark);
}

.category-stat-card small {
    color: var(--muted);
    font-weight: 700;
}

.dashboard-category-search {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
}

.dashboard-category-search span {
    font-weight: 800;
}

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

.full-span {
    grid-column: 1 / -1;
}

.category-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.category-cloud a,
.status {
    border-radius: 999px;
    padding: 8px 12px;
    font-weight: 750;
    font-size: 13px;
}

.category-cloud a {
    background: var(--surface-strong);
    color: var(--green-dark);
}

.toolbar {
    display: flex;
    justify-content: space-between;
}

.filter-context {
    width: min(1120px, 100%);
    margin: 0 auto 24px;
    padding: 20px 24px;
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.category-filter-context {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: center;
}

.filter-context h2 {
    margin: 5px 0 8px;
}

.filter-context p {
    margin: 0;
    color: var(--muted);
}

.filtered-counts {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.filtered-counts span {
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--surface-strong);
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.filtered-counts strong {
    color: var(--ink);
    font-size: 18px;
}

.search-form {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(220px, 1.1fr) minmax(220px, 1fr) auto auto;
    gap: 10px;
}

input,
textarea,
select {
    min-width: 0;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    font: inherit;
    color: var(--ink);
    background: #ffffff;
}

input:focus,
textarea:focus,
select:focus {
    outline: 3px solid rgba(22, 128, 96, 0.16);
    border-color: var(--green);
}

input[type="file"] {
    padding: 10px;
}

textarea.auto-grow {
    min-height: 48px;
    overflow: hidden;
    resize: vertical;
    line-height: 1.5;
}

.responsive-table {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

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

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

td {
    line-height: 1.45;
}

.actions-col {
    width: 190px;
}

.actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.actions form {
    margin: 0;
}

.status.on {
    background: #e9f8f2;
    color: var(--green-dark);
}

.status.off {
    background: #eef0f0;
    color: #5f6865;
}

.status.ok {
    background: #e9f8f2;
    color: var(--green-dark);
}

.status.warning {
    background: #fff7e6;
    color: var(--amber);
}

.status.danger {
    background: var(--red-soft);
    color: var(--red);
}

.status.neutral {
    background: #eef0f0;
    color: #5f6865;
}

.form {
    display: grid;
    gap: 20px;
}

.form-section-title {
    display: grid;
    gap: 5px;
    padding-top: 6px;
    border-top: 1px solid var(--line);
}

.form-section-title h2 {
    margin: 0;
    font-size: 19px;
}

.form-section-title p,
.epi-detail,
.sap-summary {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.form-grid {
    display: grid;
    gap: 16px;
}

.form-grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.sap-list {
    display: grid;
    gap: 12px;
}

.sap-row {
    display: grid;
    grid-template-columns: minmax(90px, 0.7fr) minmax(150px, 1fr) 92px;
    gap: 12px;
    align-items: end;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfdfc;
}

.mini-switch {
    min-height: 46px;
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 800;
}

.mini-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.mini-switch span {
    width: 34px;
    height: 20px;
    border-radius: 999px;
    background: #cbd5d1;
    position: relative;
    flex: 0 0 auto;
}

.mini-switch span::after {
    content: "";
    width: 14px;
    height: 14px;
    position: absolute;
    top: 3px;
    left: 3px;
    border-radius: 50%;
    background: #ffffff;
    transition: transform 160ms ease;
}

.mini-switch input:checked + span {
    background: var(--green);
}

.mini-switch input:checked + span::after {
    transform: translateX(14px);
}

.add-row-button {
    width: fit-content;
}

.field {
    display: grid;
    gap: 8px;
}

.field span {
    font-weight: 800;
}

.error {
    color: var(--red);
    font-weight: 700;
}

.switch {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 800;
}

.switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.switch span {
    width: 46px;
    height: 26px;
    border-radius: 999px;
    background: #cbd5d1;
    position: relative;
    transition: background 160ms ease;
}

.switch span::after {
    content: "";
    width: 20px;
    height: 20px;
    position: absolute;
    top: 3px;
    left: 3px;
    border-radius: 50%;
    background: #ffffff;
    transition: transform 160ms ease;
}

.switch input:checked + span {
    background: var(--green);
}

.switch input:checked + span::after {
    transform: translateX(20px);
}

.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.alert {
    width: min(1120px, 100%);
    margin: 0 auto 18px;
    padding: 14px 16px;
    border-radius: 8px;
    font-weight: 750;
}

.alert-success {
    background: #e9f8f2;
    color: var(--green-dark);
}

.alert-danger {
    background: var(--red-soft);
    color: var(--red);
}

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

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

.empty-state {
    text-align: center;
}

.danger-state code {
    display: block;
    margin-top: 18px;
    padding: 14px;
    background: var(--red-soft);
    color: var(--red);
    white-space: pre-wrap;
    text-align: left;
    border-radius: 8px;
}

.auth-shell {
    width: min(1040px, 100%);
}

.auth-panel {
    min-height: 620px;
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.28);
}

.auth-copy {
    padding: 48px;
    color: #ffffff;
    background:
        linear-gradient(135deg, rgba(16, 24, 21, 0.84), rgba(22, 128, 96, 0.72)),
        url("data:image/svg+xml,%3Csvg width='760' height='620' viewBox='0 0 760 620' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.15' stroke-width='2'%3E%3Crect x='78' y='102' width='220' height='280' rx='8'/%3E%3Crect x='342' y='88' width='290' height='88' rx='8'/%3E%3Crect x='342' y='210' width='290' height='88' rx='8'/%3E%3Crect x='342' y='332' width='290' height='88' rx='8'/%3E%3Cpath d='M118 454h504M118 500h420M118 546h350'/%3E%3Ccircle cx='188' cy='188' r='52'/%3E%3C/g%3E%3C/svg%3E");
    background-size: cover;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 16px;
}

.auth-copy .brand-mark {
    background: #ffffff;
    color: var(--green-dark);
}

.auth-copy h1 {
    margin: 0;
    font-size: 48px;
    line-height: 1;
}

.auth-copy p {
    max-width: 440px;
    margin: 0;
    color: rgba(255, 255, 255, 0.78);
    line-height: 1.65;
}

.login-card {
    padding: 48px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 20px;
}

.login-card h2 {
    margin: 4px 0 0;
    font-size: 30px;
}

.compact-alert {
    width: 100%;
    margin: 0;
}

.login-hint {
    display: grid;
    gap: 6px;
    padding: 14px;
    border-radius: 8px;
    background: var(--surface-strong);
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.login-hint strong {
    color: var(--ink);
}

@media (max-width: 860px) {
    .sidebar {
        position: static;
        width: auto;
        min-height: auto;
    }

    .main {
        margin-left: 0;
        padding: 20px;
    }

    .topbar {
        justify-content: space-between;
    }

    .category-filter-context {
        flex-direction: column;
        align-items: stretch;
    }

    .page-hero,
    .page-heading,
    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .search-form {
        grid-template-columns: 1fr;
    }

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

    .page-hero h1 {
        font-size: 38px;
    }

    .actions {
        flex-wrap: wrap;
    }

    .epi-grid,
    .form-grid.two,
    .sap-row,
    .category-dashboard-grid {
        grid-template-columns: 1fr;
    }

    .epi-card {
        display: flex;
    }

    .epi-photo {
        min-height: 0;
    }

    .auth-panel {
        grid-template-columns: 1fr;
    }

    .auth-copy,
    .login-card {
        padding: 28px;
    }

    .auth-copy h1 {
        font-size: 40px;
    }
}
