:root {
    --bg: #f4f6f4;
    --card: #ffffff;
    --text: #2c312d;
    --muted: #6a716b;
    --line: #d8ddd8;
    --green: #4a8f22;
    --green-dark: #356b18;
    --danger: #b43f3f;
    --sidebar: #252a25;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--green-dark); text-decoration: none; }
h1, h2, h3, p { margin: 0; }
label { display: block; margin-bottom: 8px; font-weight: 700; color: #465048; }
input, textarea, select {
    width: 100%;
    border: 1px solid #cfd5cf;
    border-radius: 12px;
    padding: 12px 14px;
    font: inherit;
    color: inherit;
    background: #fff;
}
textarea { resize: vertical; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: #4f564f; font-size: 14px; background: #f8faf8; }

/* ── Guest / login ─────────────────────────────────── */
.guest-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #eff4ee 0%, #dfe7dc 100%);
}
.guest-shell { width: min(460px, calc(100vw - 32px)); }
.login-card {
    background: var(--card);
    border-radius: 24px;
    padding: 32px;
    box-shadow: 0 20px 60px rgba(31, 42, 31, 0.12);
}
.login-brand { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.brand-mark {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--green), var(--green-dark));
    color: #fff;
    font-weight: 800;
    display: grid;
    place-items: center;
}
.brand-logo {
    max-width: 148px;
    max-height: 56px;
    object-fit: contain;
    display: block;
}
.brand-logo-login { max-width: 120px; }
.login-hint {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--muted);
}

/* ── App shell ─────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; align-items: flex-start; }

.sidebar {
    width: 260px;
    background: var(--sidebar);
    color: #f1f4f1;
    padding: 28px 22px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 28px;
    flex-shrink: 0;
    align-self: flex-start;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar p, .sidebar span { color: #b7c0b7; }
.sidebar-nav { display: grid; gap: 10px; }
.sidebar-nav a {
    padding: 12px 14px;
    border-radius: 12px;
    color: #dde5dd;
    background: rgba(255,255,255,0.03);
    transition: background 0.15s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.08); }
.sidebar-nav a.is-active { background: rgba(103, 173, 63, 0.25); color: #fff; }
.sidebar-user { display: grid; gap: 6px; font-size: 14px; }
.sidebar-user a { color: #9fdb78; }
.sidebar-footer-note {
    display: grid;
    gap: 10px;
    padding-top: 14px;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-footer-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 13px;
}
.sidebar-footer-actions a,
.sidebar-footer-actions .link-button { color: #9fdb78; }
.developer-trigger {
    padding: 0;
    border: 0;
    background: transparent;
    color: rgba(255,255,255,0.32);
    text-align: left;
    font: inherit;
    cursor: pointer;
}
.developer-trigger:hover { color: rgba(255,255,255,0.58); }

/* ── Content area ──────────────────────────────────── */
.content-area {
    flex: 1;
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}
.page-header p { margin-top: 6px; color: var(--muted); }

.card {
    background: var(--card);
    border-radius: 22px;
    padding: 22px;
    box-shadow: 0 12px 34px rgba(38, 49, 38, 0.08);
}
.form-card { max-width: 920px; }
.stat-card strong { font-size: 36px; margin-top: 8px; display: block; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.section-head p { margin-top: 4px; color: var(--muted); }
.stack-md > * + * { margin-top: 16px; }
.stack-lg > * + * { margin-top: 22px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.full-span { grid-column: 1 / -1; }

/* ── Buttons ───────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 12px;
    padding: 12px 20px;
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    min-height: 46px;
    transition: background 0.15s;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: #eef3ee; color: #374037; }
.btn-secondary:hover { background: #e2ebe2; }
.btn-block { width: 100%; }

/* ── Alerts ────────────────────────────────────────── */
.alert {
    border-radius: 14px;
    padding: 14px 16px;
}
.alert-success { background: #e8f5df; color: #2c5d1c; }
.alert-danger { background: #fdeaea; color: #8c3030; }
.error-list { margin: 0; padding-left: 18px; }

/* ── Tables ────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.link-button {
    padding: 0;
    border: 0;
    background: none;
    color: var(--green-dark);
    font: inherit;
    cursor: pointer;
}
.danger-link { color: var(--danger); }
.muted { color: var(--muted); }
.text-right { text-align: right; }

/* ── Info cards ────────────────────────────────────── */
.info-card {
    background: #f6faf5;
    border: 1px solid #e1e8df;
    border-radius: 16px;
    padding: 18px;
}
.info-card span, .table-note { color: var(--muted); }
.info-card strong { display: block; margin-top: 6px; font-size: 22px; }
.detail-grid { font-size: 15px; }

/* ── Quotation form ────────────────────────────────── */
.quotation-form { max-width: 1120px; }
.item-card {
    border: 1px solid #dde4dd;
    border-radius: 18px;
    padding: 18px;
    background: #fbfdfb;
}
.item-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.item-badge {
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 700;
}
.badge-product { background: #e5f4dd; color: #346d17; }
.badge-custom { background: #edf1ed; color: #526052; }
.is-hidden { display: none; }

.totals-panel {
    margin-left: auto;
    width: min(360px, 100%);
    border-radius: 16px;
    background: #f3f7f2;
    padding: 18px;
    display: grid;
    gap: 12px;
}
.totals-panel div {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.totals-panel strong { font-size: 20px; }

.actions-row { display: flex; flex-wrap: wrap; gap: 12px; }
.align-end-row { align-items: end; }
.page-actions { justify-content: flex-end; }
.status-field { min-width: min(260px, 100%); }
.guest-footer-note {
    margin: 0;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

/* ── Brand assets ──────────────────────────────────── */
.brand-assets-grid { align-items: stretch; }
.brand-asset-card {
    display: grid;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 18px;
    background: #fafcf9;
}
.brand-preview-image {
    max-width: 100%;
    max-height: 140px;
    object-fit: contain;
    border-radius: 14px;
    background: #fff;
    border: 1px solid var(--line);
    padding: 10px;
}
.brand-preview-qr { max-width: 140px; }
.brand-preview-placeholder {
    min-height: 110px;
    display: grid;
    place-items: center;
    border: 1px dashed #c7d0c7;
    border-radius: 14px;
    color: var(--muted);
    background: #fff;
}

/* ── PIN modal ─────────────────────────────────────── */
.pin-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
}
.pin-modal[hidden] { display: none !important; }
.pin-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(20, 24, 20, 0.52);
}
.pin-modal-card {
    position: relative;
    width: min(460px, calc(100vw - 32px));
    background: #fff;
    border-radius: 24px;
    padding: 24px;
    box-shadow: 0 24px 60px rgba(16, 24, 16, 0.24);
}

/* ── Mobile top bar ────────────────────────────────── */
.mobile-topbar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 150;
    height: 60px;
    background: var(--sidebar);
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.mobile-topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
    min-width: 0;
}
.mobile-brand-logo {
    max-width: 110px;
    max-height: 38px;
    object-fit: contain;
    flex-shrink: 0;
}
.mobile-topbar .brand-mark {
    width: 38px; height: 38px;
    font-size: 14px;
    border-radius: 10px;
    flex-shrink: 0;
}
.mobile-topbar-name {
    color: #f1f4f1;
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 10px;
    background: rgba(255,255,255,0.1);
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
}
.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: #f1f4f1;
    border-radius: 2px;
    transition: transform 0.22s, opacity 0.22s;
}
body.nav-open .hamburger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.nav-open .hamburger span:nth-child(2) { opacity: 0; transform: scaleX(0); }
body.nav-open .hamburger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 140;
    background: rgba(0, 0, 0, 0.45);
}
body.nav-open .nav-overlay { display: block; }

.nav-close-btn { display: none; }
.nav-close-btn button {
    width: 36px; height: 36px;
    border: 0;
    background: rgba(255,255,255,0.1);
    border-radius: 8px;
    color: #f1f4f1;
    font-size: 20px;
    cursor: pointer;
    display: grid;
    place-items: center;
    line-height: 1;
}
.nav-close-btn button:hover { background: rgba(255,255,255,0.18); }

/* ── Responsive: tablet / large mobile ─────────────── */
@media (max-width: 900px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ── Responsive: mobile ─────────────────────────────── */
@media (max-width: 768px) {
    /* Mobile top bar visible */
    .mobile-topbar { display: flex; }

    /* Sidebar becomes fixed overlay drawer */
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        width: min(300px, 85vw);
        height: 100vh;
        transform: translateX(-105%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 160;
        align-self: auto;
    }
    body.nav-open .sidebar { transform: translateX(0); }

    /* Show close button inside sidebar */
    .nav-close-btn {
        display: flex;
        justify-content: flex-end;
        margin-bottom: 6px;
    }

    /* Content area: room for fixed topbar */
    .content-area { padding: 76px 16px 32px; gap: 16px; }

    /* Grids collapse */
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

    /* Section headers stack */
    .section-head { flex-direction: column; align-items: flex-start; gap: 10px; }
    .section-head .actions-row { width: 100%; }
    .section-head .actions-row .btn { flex: 1; justify-content: center; }

    /* Page-level primary action → full width */
    .page-actions { justify-content: stretch; }
    .page-actions .btn { width: 100%; justify-content: center; }

    /* Comfortable touch targets */
    .btn { min-height: 48px; font-size: 15px; }

    /* Prevent iOS auto-zoom on inputs */
    input, select, textarea { font-size: 16px; }

    /* Totals panel full width */
    .totals-panel { width: 100%; margin-left: 0; }

    /* Status field full width */
    .status-field { min-width: 100%; }
    .align-end-row { flex-direction: column; align-items: stretch; }
    .align-end-row .btn { width: 100%; }

    /* Info card: smaller total number */
    .info-card strong { font-size: 18px; }

    /* Page header: hide generic subtitle to save space */
    .page-header p { display: none; }

    /* Table: compact rows */
    th, td { padding: 10px 12px; }
    .table-actions { gap: 10px; }
}

/* ── Responsive: small phones ───────────────────────── */
@media (max-width: 480px) {
    .card { padding: 16px; border-radius: 18px; }
    .item-card { padding: 14px; border-radius: 14px; }

    /* Stat cards horizontal on small screens */
    .stat-card { display: flex; align-items: center; justify-content: space-between; }
    .stat-card strong { font-size: 28px; margin-top: 0; }
}
