/* =========================================================
   VegManage ERP — Design System
   ========================================================= */

/* --- Reset & Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: #f4f6f2;
    color: #203028;
    line-height: 1.6;
}

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

img {
    max-width: 100%;
}

/* --- Forms --- */
input,
select,
textarea {
    width: 100%;
    padding: 11px 14px;
    border-radius: 12px;
    border: 1px solid rgba(32, 48, 40, 0.15);
    background: #fff;
    color: #203028;
    font: inherit;
    font-size: 14px;
    line-height: 1.4;
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: rgba(21, 48, 36, 0.4);
    box-shadow: 0 0 0 3px rgba(21, 48, 36, 0.08);
}

label {
    display: block;
    margin: 0;
}

label > span {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(32, 48, 40, 0.55);
}

/* --- Shell Layout --- */
.erp-shell {
    display: grid;
    grid-template-columns: 250px 1fr;
    min-height: 100vh;
}

/* --- Sidebar --- */
.erp-sidebar {
    background: #153024;
    color: #eff4ec;
    padding: 24px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.erp-sidebar > strong {
    display: block;
    font-size: 15px;
    padding: 0 10px;
}

.erp-sidebar > p {
    font-size: 12px;
    color: rgba(239, 244, 236, 0.5);
    margin: 4px 0 0;
    padding: 0 10px;
}

.erp-sidebar nav {
    display: grid;
    gap: 2px;
    margin-top: 20px;
}

.sidebar-title {
    margin-top: 20px;
    margin-bottom: 4px;
    padding: 0 10px;
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgba(239, 244, 236, 0.45);
    font-weight: 700;
}

.erp-sidebar nav a {
    position: relative;
    padding: 10px 12px 10px 16px;
    border-radius: 10px;
    display: grid;
    gap: 2px;
    font-size: 14px;
    transition: background 0.15s, color 0.15s, transform 0.12s;
}

.erp-sidebar nav a small {
    font-size: 11px;
    color: rgba(239, 244, 236, 0.5);
    font-weight: 400;
}

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

.erp-sidebar nav a.active {
    background: linear-gradient(135deg, rgba(168, 196, 120, 0.35) 0%, rgba(123, 143, 92, 0.2) 100%);
    font-weight: 700;
    color: #ffffff;
    box-shadow: inset 0 0 0 1px rgba(168, 196, 120, 0.35),
                0 6px 14px rgba(0, 0, 0, 0.18);
}

.erp-sidebar nav a.active::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 10px;
    bottom: 10px;
    width: 3px;
    border-radius: 999px;
    background: #c9e27a;
    box-shadow: 0 0 6px rgba(201, 226, 122, 0.7);
}

.erp-sidebar nav a.active small {
    color: rgba(255, 255, 255, 0.82);
}

/* --- Main Content --- */
.erp-main {
    padding: 24px 28px 40px;
    min-width: 0;
}

/* --- Topbar --- */
.erp-topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 6px 0 14px;
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(32, 48, 40, 0.08);
}

.erp-topbar > div:first-child {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-start;
}

.erp-topbar h1 {
    font-size: 1.6rem;
    margin: 2px 0 0;
    font-weight: 800;
    color: #153024;
    letter-spacing: -0.01em;
}

.erp-topbar-breadcrumb {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin: 2px 0 0;
    font-size: 12px;
    color: rgba(32, 48, 40, 0.5);
    font-weight: 500;
}

.erp-topbar-breadcrumb .sep {
    color: rgba(32, 48, 40, 0.25);
}

.erp-topbar-breadcrumb .current {
    color: rgba(21, 48, 36, 0.85);
    font-weight: 700;
}

.erp-topbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 8px;
    font-size: 14px;
    color: rgba(32, 48, 40, 0.7);
}

/* --- Flash --- */
.erp-flash {
    padding: 12px 16px;
    border-radius: 12px;
    margin-top: 16px;
    border: 1px solid rgba(32, 48, 40, 0.1);
    background: #ffffff;
    font-size: 14px;
}

.erp-flash-success {
    border-color: rgba(21, 48, 36, 0.18);
    background: rgba(21, 48, 36, 0.03);
}

.erp-flash-error {
    border-color: rgba(148, 71, 38, 0.22);
    background: rgba(148, 71, 38, 0.03);
}

/* --- Grid Layouts --- */
.page-grid,
.form-grid,
.two-col-grid {
    display: grid;
    gap: 18px 20px;
}

.page-grid {
    grid-template-columns: 1.15fr 0.85fr;
    gap: 20px;
    margin-top: 20px;
}

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

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

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.report-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 16px;
    margin-top: 20px;
}

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

/* --- Cards & Panels --- */
.metric-card,
.panel {
    background: #fff;
    border: 1px solid rgba(32, 48, 40, 0.08);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 2px 12px rgba(32, 48, 40, 0.04);
}

.metric-card {
    display: grid;
    gap: 4px;
}

.metric-value {
    font-size: 1.75rem;
    font-weight: 800;
    margin-top: 6px;
    line-height: 1.2;
}

.metric-card p {
    margin: 0;
    font-size: 13px;
    color: rgba(32, 48, 40, 0.6);
}

/* --- Toolbar --- */
.toolbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.muted {
    color: rgba(32, 48, 40, 0.55);
    font-size: 14px;
    margin: 4px 0 0;
}

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

.inline-form input,
.inline-form select {
    flex: 1 1 160px;
}

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

/* --- Checkbox --- */
.checkbox-field {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px dashed rgba(32, 48, 40, 0.18);
    background: rgba(123, 143, 92, 0.05);
    align-self: end;
    min-height: 44px;
    margin: 0;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.checkbox-field:hover {
    background: rgba(123, 143, 92, 0.1);
    border-color: rgba(32, 48, 40, 0.3);
}

.checkbox-field input[type='checkbox'] {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: #153024;
}

.checkbox-field span {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: #203028;
    text-transform: none;
    letter-spacing: 0;
}

/* --- Status Chips & Pills --- */
.status-chip {
    display: inline-flex;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(123, 143, 92, 0.12);
    color: #244233;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(21, 48, 36, 0.12) 0%, rgba(123, 143, 92, 0.18) 100%);
    color: #153024;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border: 1px solid rgba(21, 48, 36, 0.12);
}

.pill::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: #7b8f5c;
    box-shadow: 0 0 0 2px rgba(123, 143, 92, 0.2);
}

/* --- Tables --- */
.table-wrap {
    overflow-x: auto;
    margin-top: 4px;
}

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

th {
    padding: 10px 12px;
    border-bottom: 2px solid rgba(32, 48, 40, 0.1);
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    color: rgba(32, 48, 40, 0.55);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(32, 48, 40, 0.06);
    text-align: left;
    vertical-align: middle;
}

tbody tr:hover {
    background: rgba(32, 48, 40, 0.02);
}

td small {
    display: block;
    font-size: 12px;
    color: rgba(32, 48, 40, 0.5);
    margin-top: 2px;
}

/* --- Auth Pages --- */
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #153024 0%, #2d5b3f 50%, #7b8f5c 100%);
}

.auth-card {
    width: min(480px, calc(100% - 32px));
    background: rgba(255, 255, 255, 0.97);
    border-radius: 20px;
    padding: 32px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.auth-card h1 {
    margin: 12px 0 6px;
    font-size: 1.35rem;
}

.field {
    margin-bottom: 14px;
}

/* --- Buttons --- */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 999px;
    background: #153024;
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.12s, transform 0.1s;
}

.button:hover {
    background: #1d4030;
    transform: translateY(-1px);
}

.button.secondary {
    background: #944726;
}

.button.secondary:hover {
    background: #a85530;
}

.button.ghost {
    background: transparent;
    color: #153024;
    border: 1px solid rgba(32, 48, 40, 0.14);
}

.button.ghost:hover {
    background: rgba(32, 48, 40, 0.04);
}

/* --- Panel H2 consistency --- */
.panel > .pill + h2,
.panel > span + h2 {
    margin-top: 10px;
}

.panel > h2 + form,
.panel > h2 + .table-wrap,
.panel > p + form,
.panel > p + .table-wrap {
    margin-top: 18px;
}

.panel h2 {
    font-size: 1.15rem;
    margin: 0;
    font-weight: 700;
    color: #153024;
    letter-spacing: -0.01em;
}

.panel > p {
    margin: 6px 0 0;
    font-size: 14px;
    line-height: 1.6;
    color: rgba(32, 48, 40, 0.65);
}

.panel .toolbar > div > .pill + h2 {
    margin-top: 8px;
}

.panel .toolbar > div > h2 + .muted {
    margin-top: 4px;
}

/* --- Page grid form panels --- */
.page-grid > .panel .two-col-grid,
.page-grid > aside .two-col-grid {
    gap: 18px 20px;
}

.page-grid > aside .stack {
    gap: 20px;
}

/* --- Responsive --- */
@media (max-width: 1280px) {
    .page-grid > .panel .two-col-grid,
    .page-grid > aside .two-col-grid {
        grid-template-columns: 1fr;
        gap: 18px;
    }
}

/* --- Mobile sidebar toggle button (hidden on desktop) --- */
.erp-sidebar-toggle {
    display: none;
}

@media (max-width: 1024px) {
    .erp-shell {
        grid-template-columns: 1fr;
    }

    /* Sidebar becomes a fixed overlay drawer */
    .erp-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 270px;
        height: 100vh;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        overflow-y: auto;
    }

    .erp-sidebar.is-open {
        transform: translateX(0);
    }

    /* Backdrop overlay */
    .erp-sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 99;
    }

    .erp-sidebar-backdrop.is-visible {
        display: block;
    }

    /* Toggle button visible on mobile */
    .erp-sidebar-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border-radius: 12px;
        border: 1px solid rgba(32, 48, 40, 0.14);
        background: #fff;
        color: #153024;
        cursor: pointer;
        padding: 0;
        flex-shrink: 0;
    }

    .erp-sidebar-toggle span,
    .erp-sidebar-toggle::before,
    .erp-sidebar-toggle::after {
        content: '';
        position: absolute;
        display: block;
        width: 18px;
        height: 2px;
        border-radius: 2px;
        background: currentColor;
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    .erp-sidebar-toggle {
        position: relative;
    }

    .erp-sidebar-toggle::before { transform: translateY(-5px); }
    .erp-sidebar-toggle::after  { transform: translateY(5px); }

    .metric-grid,
    .report-grid,
    .page-grid,
    .form-grid,
    .two-col-grid {
        grid-template-columns: 1fr;
    }

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

@media (max-width: 640px) {
    .erp-main {
        padding: 16px;
    }

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