:root {
    --bg: #f6f7f1;
    --panel: #ffffff;
    --ink: #1f2a24;
    --muted: #647067;
    --line: #d9e1d7;
    --brand: #1f6b45;
    --brand-strong: #154832;
    --accent: #d89a2b;
    --accent-strong: #b7791f;
    --danger: #b94a48;
    --sidebar-bg: #123427;
    --sidebar-link: #e2efe5;
    --topbar-start: #1f6b45;
    --topbar-end: #154832;
    --topbar-shadow: rgba(31, 107, 69, 0.2);
    --soft-bg: #f8faf4;
    --notice-bg: #e8f4ec;
    --notice-border: #b9dbc4;
    --focus-ring: rgba(31, 107, 69, 0.28);
}

body[data-theme="eggshell_classic"] {
    --bg: #f8f3e7;
    --panel: #fffdf8;
    --ink: #2c241c;
    --muted: #746a5c;
    --line: #e5dccb;
    --brand: #4f7d45;
    --brand-strong: #355934;
    --accent: #b8793a;
    --accent-strong: #8f5a2a;
    --danger: #a84d42;
    --sidebar-bg: #3a2b1d;
    --sidebar-link: #f6ead9;
    --topbar-start: #4f7d45;
    --topbar-end: #2f4f32;
    --topbar-shadow: rgba(79, 125, 69, 0.2);
    --soft-bg: #fbf6ec;
    --notice-bg: #edf6e7;
    --notice-border: #c6d9b8;
    --focus-ring: rgba(79, 125, 69, 0.28);
}

body[data-theme="modern_agro"] {
    --bg: #f4f7f5;
    --panel: #ffffff;
    --ink: #17211d;
    --muted: #60706a;
    --line: #d7e1dc;
    --brand: #0f766e;
    --brand-strong: #115e59;
    --accent: #84a924;
    --accent-strong: #5f7f18;
    --danger: #b44a4a;
    --sidebar-bg: #0b2f2a;
    --sidebar-link: #dcefed;
    --topbar-start: #0f766e;
    --topbar-end: #0b3f3b;
    --topbar-shadow: rgba(15, 118, 110, 0.2);
    --soft-bg: #f5faf7;
    --notice-bg: #e5f4f1;
    --notice-border: #b3d8d1;
    --focus-ring: rgba(15, 118, 110, 0.28);
}

body[data-theme="sunrise_poultry"] {
    --bg: #fff8ed;
    --panel: #ffffff;
    --ink: #332313;
    --muted: #75675a;
    --line: #eadcc9;
    --brand: #7a5c12;
    --brand-strong: #5b4310;
    --accent: #e68a23;
    --accent-strong: #b76618;
    --danger: #b84d45;
    --sidebar-bg: #3f2b10;
    --sidebar-link: #fff1d6;
    --topbar-start: #b56b18;
    --topbar-end: #6f4d12;
    --topbar-shadow: rgba(181, 107, 24, 0.22);
    --soft-bg: #fffaf1;
    --notice-bg: #f4f3df;
    --notice-border: #ddd6a8;
    --focus-ring: rgba(181, 107, 24, 0.28);
}

body[data-theme="clean_enterprise"] {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --ink: #1b2430;
    --muted: #657286;
    --line: #dbe3ee;
    --brand: #256d5a;
    --brand-strong: #17483c;
    --accent: #2f80ed;
    --accent-strong: #1b5fb8;
    --danger: #b44747;
    --sidebar-bg: #102033;
    --sidebar-link: #e6edf6;
    --topbar-start: #17483c;
    --topbar-end: #102033;
    --topbar-shadow: rgba(16, 32, 51, 0.2);
    --soft-bg: #f7f9fc;
    --notice-bg: #e9f4f0;
    --notice-border: #bdd8cf;
    --focus-ring: rgba(37, 109, 90, 0.28);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--ink);
}

a {
    color: var(--brand);
    text-decoration: none;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--soft-bg), var(--line));
}

.login-shell {
    width: min(440px, calc(100vw - 32px));
}

.login-panel,
.panel,
.metric {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 16px 40px rgba(30, 42, 36, 0.08);
}

.login-panel {
    padding: 32px;
}

.access-denied {
    width: min(620px, calc(100vw - 32px));
}

.access-denied section {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(30, 42, 36, 0.14);
    padding: 38px;
    text-align: center;
}

.access-denied span {
    display: inline-grid;
    place-items: center;
    width: 72px;
    height: 72px;
    margin-bottom: 18px;
    border-radius: 50%;
    background: #fff4e4;
    color: var(--accent);
    font-size: 24px;
    font-weight: 900;
}

.access-denied h1 {
    margin: 0 0 10px;
    font-size: 34px;
}

.access-denied p {
    margin: 0 auto 14px;
    max-width: 460px;
}

.access-denied div {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 22px;
    flex-wrap: wrap;
}

.login-panel h1 {
    margin: 0 0 6px;
    font-size: 30px;
}

.login-panel p,
.muted,
.topbar p {
    color: var(--muted);
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 250px;
    padding: 22px 18px;
    background: var(--sidebar-bg);
    color: #fff;
    transition: width 0.2s ease;
    overflow: hidden;
}

.sidebar-backdrop {
    display: none;
}

.brand {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 24px;
}

.sidebar nav {
    display: grid;
    gap: 6px;
}

.sidebar a {
    display: block;
    color: var(--sidebar-link);
    padding: 11px 12px;
    border-radius: 6px;
    white-space: nowrap;
}

.sidebar a.active,
.sidebar a:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.main {
    margin-left: 250px;
    min-height: 100vh;
    padding: 24px;
    transition: margin-left 0.2s ease;
    display: flex;
    flex-direction: column;
}

.sidebar-collapsed .sidebar {
    width: 78px;
}

.sidebar-collapsed .main {
    margin-left: 78px;
}

.sidebar-collapsed .brand span,
.sidebar-collapsed .sidebar a span {
    opacity: 0;
    pointer-events: none;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    margin: -24px -24px 18px;
    background: linear-gradient(135deg, var(--topbar-start), var(--topbar-end));
    color: #fff;
    box-shadow: 0 16px 36px var(--topbar-shadow);
}

.topbar-strip,
.title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.topbar-strip {
    min-height: 60px;
    padding: 0 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-left: auto;
}

.topbar-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    min-width: 38px;
    padding: 7px 12px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 13px;
    font-weight: 900;
}

.topbar-chip:hover,
.filter-date-link:hover {
    background: rgba(255, 255, 255, 0.17);
    color: #fff;
}

.date-chip {
    letter-spacing: 0;
}

.title-row {
    min-height: 96px;
    padding: 24px 32px;
}

.topbar h1 {
    margin: 0;
    font-size: 36px;
    color: #fff;
}

.topbar p {
    margin: 4px 0 0;
}

.filter-date-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 9px 14px;
    border-radius: 9px;
    background: #fff;
    color: #151a28;
    font-size: 13px;
    font-weight: 900;
    white-space: nowrap;
}

.date-filter-menu {
    position: relative;
}

.date-filter-menu[open] {
    z-index: 35;
}

.date-filter-menu summary {
    list-style: none;
    cursor: pointer;
}

.date-filter-menu summary::-webkit-details-marker {
    display: none;
}

.date-filter-menu summary::after {
    content: "v";
    margin-left: 4px;
    font-size: 11px;
}

.date-filter-panel {
    position: absolute;
    z-index: 30;
    right: 0;
    top: calc(100% + 8px);
    display: grid;
    width: 230px;
    max-height: min(430px, calc(100vh - 180px));
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 22px 55px rgba(30, 42, 36, 0.2);
    color: var(--ink);
}

.date-filter-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    display: none;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(16, 24, 40, 0.08);
    cursor: default;
}

.date-filter-backdrop.open {
    display: block;
}

.date-filter-backdrop:hover {
    background: rgba(16, 24, 40, 0.08);
}

.date-filter-panel a {
    padding: 10px 13px;
    color: #101828;
    font-size: 13px;
    font-weight: 700;
}

.custom-range-title {
    padding: 10px 13px;
    color: #101828;
    font-size: 13px;
    font-weight: 700;
}

.date-filter-panel a:hover,
.date-filter-panel a.active,
.custom-range-title.active {
    background: #0b93cf;
    color: #fff;
}

.date-filter-panel form {
    gap: 9px;
    padding: 12px;
    border-top: 1px solid var(--line);
    background: #f8faf7;
}

.date-filter-panel label {
    color: var(--muted);
    font-size: 12px;
}

.date-filter-panel input {
    padding: 8px;
}

.date-filter-panel button {
    min-height: 34px;
    padding: 8px 10px;
    font-size: 12px;
}

.menu-toggle {
    min-height: 34px;
    min-width: 72px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-radius: 9px;
    font-size: 13px;
}

.menu-toggle:hover {
    background: rgba(255, 255, 255, 0.17);
}

.profile-menu {
    position: relative;
}

.profile-menu summary {
    list-style: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 34px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 9px;
    padding: 7px 10px 7px 13px;
    white-space: nowrap;
    cursor: pointer;
    font-weight: 800;
}

.profile-menu summary::-webkit-details-marker {
    display: none;
}

.profile-menu div {
    position: absolute;
    z-index: 10;
    right: 0;
    top: calc(100% + 8px);
    display: grid;
    min-width: 190px;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 18px 40px rgba(30, 42, 36, 0.14);
}

.profile-menu span,
.profile-menu a {
    padding: 11px 13px;
}

.profile-menu span {
    color: var(--muted);
    font-size: 13px;
    border-bottom: 1px solid var(--line);
}

.profile-menu a:hover {
    background: #f1f5ef;
}

.profile-menu summary .avatar {
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.92);
    background: transparent;
    color: #fff;
    font-size: 9px;
    font-weight: 900;
    line-height: 1;
}

.profile-menu summary .profile-first-name {
    order: -1;
    padding: 0;
    border: 0;
    color: #fff;
    font-size: 13px;
    line-height: 1;
}

.notice,
.alert {
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 16px;
}

.notice {
    background: var(--notice-bg);
    border: 1px solid var(--notice-border);
}

.alert {
    background: #fff0f0;
    border: 1px solid #f0b9b9;
    color: var(--danger);
}

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

.metrics {
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    margin-bottom: 16px;
}

.main > .panel,
.main > .grid {
    margin-bottom: 16px;
}

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

.grid.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel,
.metric {
    padding: 18px;
}

.panel h2 {
    margin: 0 0 14px;
    font-size: 18px;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
}

.panel-heading h2 {
    margin: 0;
}

.table-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.row-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.row-actions form {
    display: inline;
}

.table-actions .button,
.table-actions button,
.row-actions .button,
.row-actions button {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 12px;
}

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

button.danger:hover {
    background: #8f3030;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    place-items: center;
    padding: 20px;
    background: rgba(16, 45, 36, 0.42);
}

.modal.open {
    display: grid;
}

.modal-panel {
    width: min(560px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(30, 42, 36, 0.2);
    padding: 20px;
}

.modal-heading,
.modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.modal-heading {
    margin-bottom: 14px;
}

.modal-heading h2 {
    margin: 0;
    font-size: 18px;
}

.modal-actions {
    justify-content: flex-start;
    margin-top: 4px;
}

.modal .muted strong {
    display: inline-block;
    margin-left: 6px;
    padding: 4px 8px;
    border-radius: 6px;
    background: #fff1a8;
    color: #6f4300;
    font-weight: 900;
}

.icon-button {
    min-height: 34px;
    width: 34px;
    padding: 0;
    border-radius: 50%;
}

.sales-chart-panel {
    overflow: hidden;
}

.chart-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.chart-heading h2 {
    margin: 0;
}

.chart-icon {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid #d8e5ff;
    border-radius: 50%;
    background: #f6fbff;
    color: #1d4ed8;
    font-size: 11px;
    font-weight: 900;
}

.sales-chart {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
}

.chart-svg {
    display: block;
    width: 100%;
    min-width: 920px;
    height: auto;
}

.chart-grid {
    stroke: #e8eee8;
    stroke-width: 1;
}

.chart-line {
    fill: none;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chart-axis-label,
.chart-date-label,
.chart-axis-title,
.chart-legend-text {
    fill: #4d5a52;
    font-size: 12px;
}

.chart-axis-title {
    font-weight: 700;
}

.chart-legend-text {
    font-size: 11px;
    font-weight: 800;
}

.chart-legend-line {
    stroke-width: 2.2;
    stroke-linecap: round;
}

.app-footer {
    margin-top: auto;
    padding: 18px 0 0;
    display: flex;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 13px;
}

.app-footer span + span::before {
    content: "|";
    margin-right: 14px;
    color: #b8c2b9;
}

.role-notes {
    display: grid;
    gap: 12px;
}

.role-notes p {
    margin: 0;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--soft-bg);
}

.role-notes strong,
.role-notes span {
    display: block;
}

.role-notes span {
    margin-top: 4px;
    color: var(--muted);
}

.metric span {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.metric strong {
    display: block;
    margin-top: 8px;
    font-size: 25px;
}

form {
    display: grid;
    gap: 12px;
}

.wide-form {
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    align-items: end;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 11px;
    color: var(--ink);
    background: #fff;
    font: inherit;
}

.theme-preview-list {
    display: flex;
    align-items: end;
    gap: 8px;
    min-height: 40px;
}

.theme-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px var(--line);
}

.theme-dot.farm {
    background: var(--brand);
}

.theme-dot.maize {
    background: var(--accent);
}

.theme-dot.shell {
    background: var(--bg);
}

textarea {
    min-height: 84px;
    resize: vertical;
}

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border: 0;
    border-radius: 6px;
    padding: 10px 14px;
    background: var(--brand);
    color: #fff;
    font-weight: 800;
    cursor: pointer;
}

button:hover,
.button:hover {
    background: var(--brand-strong);
}

.button.secondary {
    background: var(--accent);
}

button.secondary {
    background: var(--accent);
}

button.secondary:hover {
    background: var(--accent-strong);
}

.table-card {
    display: grid;
    gap: 12px;
}

.table-toolbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.table-toolbar label {
    min-width: 160px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

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

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

thead th[role="button"] {
    padding-right: 26px;
    cursor: pointer;
    user-select: none;
}

thead th[role="button"]::after {
    content: "\2195";
    position: absolute;
    right: 9px;
    color: #a8b3ab;
    font-size: 11px;
}

thead th[role="button"].is-sorted {
    color: var(--brand);
}

thead th[role="button"][data-sort-direction="asc"]::after {
    content: "\2191";
    color: var(--brand);
}

thead th[role="button"][data-sort-direction="desc"]::after {
    content: "\2193";
    color: var(--brand);
}

thead th[role="button"]:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: -2px;
}

tfoot td {
    background: var(--soft-bg);
    border-top: 2px solid var(--brand);
    color: var(--ink);
    font-weight: 800;
}

tr.payment-row-paid td {
    background: #edf8f0;
}

tr.payment-row-partial td {
    background: #fff8e8;
}

tr.payment-row-unpaid td {
    background: #fff0f0;
}

tr.employee-row-inactive td {
    background: #f4f5f4;
    color: #6b746d;
}

.report-tools {
    margin-bottom: 16px;
}

.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
    font-size: 13px;
    flex-wrap: wrap;
}

.pagination-bar div {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pagination-bar button {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 12px;
}

.pagination-bar button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

@media (max-width: 1100px) {
    .metrics,
    .grid.two,
    .grid.three,
    .wide-form {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 20;
        display: none;
        width: 100%;
        height: 100%;
        min-height: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: rgba(16, 45, 36, 0.38);
    }

    .sidebar-open .sidebar-backdrop {
        display: block;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 30;
        width: min(280px, 82vw);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    .sidebar-open .sidebar {
        width: min(280px, 82vw);
        transform: translateX(0);
    }

    .brand span,
    .sidebar a span,
    .sidebar-collapsed .brand span,
    .sidebar-collapsed .sidebar a span {
        opacity: 1;
        pointer-events: auto;
    }

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

    .sidebar-collapsed .main {
        margin-left: 0;
    }

    .topbar {
        margin: -16px -16px 16px;
    }

    .topbar-strip {
        align-items: center;
        flex-wrap: wrap;
        min-height: auto;
        padding: 12px 14px;
    }

    .title-row,
    .panel-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .title-row {
        min-height: auto;
        padding: 22px 16px;
    }

    .topbar h1 {
        font-size: 29px;
    }

    .topbar-actions {
        flex: 1 1 auto;
        justify-content: space-between;
        gap: 8px;
    }

    .topbar-chip {
        min-width: 0;
        padding-inline: 10px;
    }

    .date-chip {
        display: none;
    }

    .date-filter-menu,
    .filter-date-link {
        width: 100%;
    }

    .filter-date-link {
        justify-content: center;
    }

    .date-filter-panel {
        left: 0;
        right: auto;
        width: min(260px, calc(100vw - 32px));
    }

    .metrics,
    .grid.two,
    .grid.three,
    .wide-form {
        grid-template-columns: 1fr;
    }

    .profile-menu div {
        left: auto;
        right: 0;
    }

    .table-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .table-toolbar label {
        min-width: 0;
    }
}

@media print {
    .sidebar,
    .topbar,
    .report-tools,
    .table-actions,
    .table-toolbar,
    .pagination-bar,
    .date-filter-menu,
    button,
    .button {
        display: none;
    }

    .main {
        margin: 0;
        padding: 0;
    }

    .app-footer {
        display: none;
    }

    .panel {
        box-shadow: none;
        break-inside: avoid;
    }
}
