:root {
    --bg: #f4f7f3;
    --ink: #17221d;
    --muted: #69766e;
    --line: #dfe7dd;
    --panel: rgba(255, 255, 255, .88);
    --green: #26734d;
    --gold: #c78a18;
    --blue: #3268b8;
    --red: #c04747;
    --shadow: 0 18px 55px rgba(25, 44, 31, .12);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(38, 115, 77, .18), transparent 34rem),
        linear-gradient(120deg, #f7faf3 0%, #eef5f1 54%, #f8f1df 100%);
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.lift {
    animation: liftIn .45s ease both;
}

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

.auth-body {
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(420px, 100%);
    padding: 34px;
    border: 1px solid rgba(255,255,255,.7);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.brand-mark, .side-brand span {
    display: inline-grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    color: white;
    font-weight: 800;
    background: linear-gradient(135deg, var(--green), var(--gold));
    box-shadow: 0 12px 30px rgba(38, 115, 77, .24);
}

.auth-card h1 { margin: 18px 0 8px; font-size: 2rem; }
.auth-card p, .eyebrow { color: var(--muted); }
.stack { display: grid; gap: 16px; margin-top: 24px; }

label {
    display: grid;
    gap: 7px;
    color: #38483f;
    font-weight: 650;
    font-size: .9rem;
}

input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    background: rgba(255,255,255,.92);
    color: var(--ink);
    outline: none;
    transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}

textarea { min-height: 86px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    border-color: rgba(38, 115, 77, .55);
    box-shadow: 0 0 0 4px rgba(38, 115, 77, .11);
}

.btn, button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 0;
    border-radius: 8px;
    padding: 10px 16px;
    cursor: pointer;
    font-weight: 750;
    transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.btn:hover, button:hover { transform: translateY(-1px); }
.primary { color: white; background: linear-gradient(135deg, var(--green), #1d5d88); box-shadow: 0 12px 24px rgba(38, 115, 77, .24); }
.ghost { background: #eef4ef; color: var(--green); }
.light { background: rgba(255,255,255,.86); color: var(--green); }
.small-link { color: var(--green); font-weight: 700; font-size: .9rem; }

.alert {
    margin: 14px 0;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
    font-weight: 650;
}
.alert.success { color: var(--green); background: #edf8f1; border-color: #cbe8d5; }
.alert.danger { color: var(--red); background: #fff1f1; border-color: #f2cccc; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 270px;
    padding: 22px 16px;
    background: rgba(19, 32, 26, .94);
    color: #f7fff9;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 12px 0 40px rgba(16, 26, 21, .22);
    transition: transform .28s ease;
    z-index: 10;
}

.side-brand {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.side-brand strong { font-size: 1.05rem; }
.sidebar nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .24) transparent;
}

.sidebar nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .22);
    border-radius: 99px;
}

.sidebar nav::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, .36);
}

.sidebar nav p {
    margin: 20px 2px 8px;
    padding: 9px 11px;
    border-radius: 8px;
    color: #fff8e5;
    background: linear-gradient(135deg, rgba(199, 138, 24, .34), rgba(38, 115, 77, .26));
    border: 1px solid rgba(255, 255, 255, .1);
    text-transform: uppercase;
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: 0;
}

.sidebar a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    margin: 3px 0;
    padding: 9px 11px;
    border-radius: 8px;
    color: #dce9df;
    transition: background .2s ease, transform .2s ease, color .2s ease;
}
.sidebar a:hover, .sidebar a.active {
    color: white;
    background: rgba(255,255,255,.12);
    transform: translateX(3px);
}

.nav-icon {
    display: inline-grid;
    place-items: center;
    flex: 0 0 26px;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    color: #fff5d8;
    background: rgba(255, 255, 255, .1);
    transition: background .2s ease, color .2s ease, transform .2s ease;
}

.nav-icon svg {
    width: 17px;
    height: 17px;
    fill: currentColor;
}

.sidebar a:hover .nav-icon,
.sidebar a.active .nav-icon {
    color: white;
    background: rgba(199, 138, 24, .42);
    transform: scale(1.04);
}

.mobile-menu {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 20;
    width: 44px;
    padding: 0;
    color: white;
    background: var(--green);
}

.app {
    margin-left: 270px;
    padding: 24px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
    padding: 18px 20px;
    border: 1px solid rgba(255,255,255,.75);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
}
.topbar h1 { margin: 2px 0 0; font-size: 1.55rem; }
.top-actions { display: flex; align-items: center; gap: 12px; color: var(--muted); font-weight: 700; }

.hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    min-height: 176px;
    margin-bottom: 18px;
    padding: 30px;
    border-radius: 8px;
    color: white;
    background:
        linear-gradient(110deg, rgba(19, 54, 39, .92), rgba(32, 98, 69, .76)),
        url("https://images.unsplash.com/photo-1536304993881-ff6e9eefa2a6?auto=format&fit=crop&w=1400&q=80") center/cover;
    box-shadow: var(--shadow);
}
.hero h1 { margin: 0 0 6px; font-size: clamp(2rem, 5vw, 4.2rem); line-height: 1; }
.hero p { margin: 0; color: rgba(255,255,255,.86); font-weight: 700; }

.stats, .report-cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat {
    position: relative;
    overflow: hidden;
    min-height: 112px;
    padding: 18px;
    border: 1px solid rgba(255,255,255,.75);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}
.stat::after {
    content: "";
    position: absolute;
    right: -28px;
    bottom: -28px;
    width: 86px;
    height: 86px;
    border-radius: 50%;
    background: currentColor;
    opacity: .12;
}
.stat span { display: block; color: var(--muted); font-weight: 750; }
.stat strong { display: block; margin-top: 14px; font-size: 1.7rem; }
.stat.green { color: var(--green); }
.stat.gold { color: var(--gold); }
.stat.blue { color: var(--blue); }
.stat.red { color: var(--red); }

.panel {
    margin-bottom: 18px;
    padding: 18px;
    border: 1px solid rgba(255,255,255,.75);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 16px; font-size: 1.18rem; }
.narrow { max-width: 760px; }

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

.section-title-row h2 {
    margin: 0;
}

.table-search {
    width: min(300px, 100%);
    min-height: 40px;
    padding: 9px 12px;
}

.grid {
    display: grid;
    gap: 18px;
}
.grid.two { grid-template-columns: minmax(280px, .85fr) minmax(420px, 1.25fr); align-items: start; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}
.form-grid h2, .form-grid .span, .form-grid button { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }

.permission-box {
    display: grid;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fbf8;
}

.permission-all {
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--green);
    background: #edf8f1;
    font-weight: 850;
}

.permission-group {
    display: grid;
    gap: 9px;
}

.permission-group h3 {
    margin: 0;
    padding: 8px 10px;
    border-radius: 8px;
    color: #fff8e5;
    background: linear-gradient(135deg, var(--green), var(--gold));
    font-size: .88rem;
}

.permission-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.permission-grid .check {
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    font-size: .86rem;
}

.toolbar {
    display: flex;
    gap: 10px;
    align-items: end;
    margin-bottom: 16px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 680px;
}
th, td {
    padding: 12px 13px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}
th {
    color: #415248;
    background: #f4f8f4;
    font-size: .84rem;
    text-transform: uppercase;
}
tr:hover td { background: #fbfdfb; }
.total td { font-weight: 850; background: #f8faf8; }
.actions {
    display: flex;
    gap: 8px;
    align-items: center;
    white-space: nowrap;
}
.actions a, .actions button {
    min-height: 30px;
    padding: 6px 9px;
    color: var(--green);
    background: #edf6f0;
    font-size: .82rem;
}
.actions button { color: var(--red); background: #fff0f0; }

.quick-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 12px;
}
.quick-grid a {
    padding: 18px;
    border-radius: 8px;
    background: #f7fbf7;
    border: 1px solid var(--line);
    font-weight: 850;
    transition: transform .18s ease, border-color .18s ease;
}
.quick-grid a:hover { transform: translateY(-2px); border-color: rgba(38, 115, 77, .45); }

.invoice-stack {
    display: grid;
    gap: 18px;
}

.invoice-form {
    display: grid;
    gap: 14px;
}

.invoice-lines {
    display: grid;
    gap: 9px;
}

.line-head,
.invoice-line {
    display: grid;
    grid-template-columns: minmax(150px, 1.5fr) minmax(76px, .6fr) minmax(86px, .7fr) minmax(72px, .55fr) minmax(100px, .8fr) 42px;
    gap: 9px;
    align-items: center;
}

.line-head {
    color: var(--muted);
    font-size: .78rem;
    font-weight: 850;
    text-transform: uppercase;
}

.invoice-line .amount {
    background: #f4f8f4;
    font-weight: 800;
}

.remove-line {
    min-height: 42px;
    padding: 0;
    color: var(--red);
    background: #fff0f0;
}

.totals-grid {
    align-items: end;
}

.invoice-total {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 14px;
    border-radius: 8px;
    color: var(--green);
    background: #edf8f1;
    font-size: 1.15rem;
    font-weight: 850;
}

.invoice-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 16px;
}

.invoice-view {
    background: white;
}

.consume-form {
    display: grid;
    gap: 14px;
}

.consume-lines {
    display: grid;
    gap: 9px;
}

.consume-head,
.consume-line {
    display: grid;
    grid-template-columns: minmax(180px, 1.5fr) minmax(90px, .7fr) minmax(90px, .7fr) minmax(110px, .8fr) 42px;
    gap: 9px;
    align-items: center;
}

.consume-head {
    color: var(--muted);
    font-size: .78rem;
    font-weight: 850;
    text-transform: uppercase;
}

.consume-line .amount {
    background: #f4f8f4;
    font-weight: 800;
}

.remove-consume-line {
    min-height: 42px;
    padding: 0;
    color: var(--red);
    background: #fff0f0;
}

.consume-total {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 14px;
    border-radius: 8px;
    color: var(--green);
    background: #edf8f1;
    font-size: 1.15rem;
    font-weight: 850;
}

@media (max-width: 980px) {
    .mobile-menu { display: inline-flex; }
    .sidebar { transform: translateX(-103%); }
    body.menu-open .sidebar { transform: translateX(0); }
    .app { margin-left: 0; padding: 72px 14px 18px; }
    .topbar, .hero { align-items: flex-start; flex-direction: column; }
    .grid.two, .stats, .report-cards, .quick-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
    .auth-card { padding: 22px; }
    .form-grid { grid-template-columns: 1fr; }
    .top-actions, .toolbar { width: 100%; flex-direction: column; align-items: stretch; }
    .hero { padding: 22px; }
    .stat strong { font-size: 1.35rem; }
    .line-head { display: none; }
    .consume-head { display: none; }
    .invoice-line { grid-template-columns: 1fr 1fr; }
    .consume-line { grid-template-columns: 1fr 1fr; }
    .invoice-line select:first-child,
    .invoice-line input:first-child,
    .consume-line select:first-child,
    .consume-line input:first-child { grid-column: 1 / -1; }
    .remove-line { width: 100%; }
}
