:root {
    --ink: #17231f;
    --muted: #68746f;
    --line: #dfe6e2;
    --paper: #ffffff;
    --canvas: #f3f6f4;
    --forest: #183f35;
    --forest-2: #23584a;
    --mint: #dbece5;
    --gold: #c99a4b;
    --danger: #a33d46;
    --warning: #fff4d6;
    --shadow: 0 18px 50px rgba(29, 56, 47, .08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); font-family: Inter, "Segoe UI", Tahoma, Arial, sans-serif; font-size: 14px; line-height: 1.6; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, summary, select { cursor: pointer; }
input, select, textarea { width: 100%; min-height: 44px; padding: 10px 12px; color: var(--ink); background: #fff; border: 1px solid #cad5d0; border-radius: 10px; outline: none; transition: border-color .2s, box-shadow .2s; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--forest-2); box-shadow: 0 0 0 3px rgba(35, 88, 74, .12); }
label { display: grid; gap: 6px; color: #34443e; font-size: 13px; font-weight: 650; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(24px, 3vw, 34px); line-height: 1.2; letter-spacing: -.035em; }
h2 { margin-bottom: 4px; font-size: 20px; line-height: 1.3; letter-spacing: -.02em; }
small { display: block; }
.muted { color: var(--muted); }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; direction: ltr; unicode-bidi: isolate; }
.eyebrow { display: block; margin-bottom: 5px; color: #708078; font-size: 10px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }

.portal-shell { display: grid; grid-template-columns: 246px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; width: 246px; height: 100vh; padding: 25px 18px 18px; color: #f5fbf8; background: linear-gradient(160deg, #173c33 0%, #102e27 100%); box-shadow: 8px 0 30px rgba(15, 45, 37, .12); z-index: 20; }
[dir="rtl"] .sidebar { box-shadow: -8px 0 30px rgba(15, 45, 37, .12); }
.brand { display: inline-flex; align-items: center; gap: 12px; }
.brand-mark { display: grid; flex: 0 0 40px; width: 40px; height: 40px; place-items: center; color: #fff; background: linear-gradient(145deg, #b98a42, #dcba77); border-radius: 13px; font-family: Georgia, serif; font-size: 23px; box-shadow: 0 10px 20px rgba(201, 154, 75, .2); }
.brand strong { display: block; font-family: Georgia, serif; font-size: 20px; letter-spacing: .02em; }
.brand small { color: #9eb7ae; font-size: 10px; letter-spacing: .09em; text-transform: uppercase; }
.nav-list { display: grid; gap: 5px; margin: 42px 0 auto; }
.nav-list a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; color: #c9dad4; border-radius: 10px; font-weight: 600; transition: .18s ease; }
.nav-list a:hover { color: #fff; background: rgba(255,255,255,.09); transform: translateX(2px); }
[dir="rtl"] .nav-list a:hover { transform: translateX(-2px); }
.nav-list span { display: grid; width: 23px; height: 23px; place-items: center; color: #d7b875; background: rgba(255,255,255,.06); border-radius: 7px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; margin: 18px 0 12px; padding: 13px 4px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-user strong { display: block; font-size: 13px; }
.sidebar-user small { color: #9eb7ae; font-size: 11px; }
.avatar { display: grid; width: 36px; height: 36px; place-items: center; color: var(--forest); background: var(--mint); border-radius: 50%; font-weight: 800; text-transform: uppercase; }
.main-content { min-width: 0; padding: 30px clamp(22px, 4vw, 58px) 60px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.language-switch { display: flex; gap: 3px; padding: 4px; direction: ltr; background: #e5ebe8; border-radius: 10px; }
.language-switch a { padding: 5px 8px; color: var(--muted); border-radius: 7px; font-size: 10px; font-weight: 800; }
.language-switch a.is-active { color: var(--forest); background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.mobile-toggle { display: none; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 9px 16px; border: 1px solid transparent; border-radius: 10px; font-weight: 750; line-height: 1.2; transition: transform .15s, box-shadow .15s, background .15s; }
.button:hover { transform: translateY(-1px); }
.button-primary { color: #fff; background: var(--forest-2); box-shadow: 0 8px 20px rgba(35, 88, 74, .18); }
.button-primary:hover { background: var(--forest); }
.button-secondary { color: var(--forest); background: #e6efeb; border-color: #d1dfd9; }
.button-ghost { color: inherit; background: transparent; border-color: currentColor; opacity: .85; }
.button-small { min-height: 32px; padding: 6px 10px; font-size: 12px; }
.button-block { width: 100%; }
.icon-button { width: 34px; height: 34px; padding: 0; color: var(--danger); background: #fff1f2; border: 0; border-radius: 9px; font-size: 20px; }

.notice { margin: -8px 0 20px; padding: 12px 15px; border: 1px solid; border-radius: 11px; font-weight: 650; }
.notice-success { color: #235e48; background: #e8f6ef; border-color: #b8dfcd; }
.notice-error { color: #8b3440; background: #fff0f1; border-color: #f1c7cb; }
.panel { margin-bottom: 20px; padding: 22px; background: var(--paper); border: 1px solid rgba(210, 222, 216, .85); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 17px; }
.panel-heading h2 { margin: 0; }
.welcome-card { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 20px; padding: 24px 26px; color: #effaf6; background: linear-gradient(125deg, var(--forest) 0%, #2c6755 100%); border-radius: var(--radius); box-shadow: 0 18px 40px rgba(24, 63, 53, .17); }
.welcome-card h2 { margin: 0 0 5px; color: #fff; font-size: 27px; }
.welcome-card p { margin: 0; color: #c7ddd5; }
.welcome-card .eyebrow { color: #d6b875; }
.welcome-card .button { color: var(--forest); background: #fff; white-space: nowrap; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.metric-grid-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric-card { position: relative; overflow: hidden; min-height: 145px; padding: 20px; background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 10px 30px rgba(29, 56, 47, .06); }
.metric-card::after { content: ""; position: absolute; inset-inline-end: -27px; bottom: -38px; width: 100px; height: 100px; background: var(--mint); border-radius: 50%; opacity: .55; }
.metric-card > span { display: block; color: var(--muted); font-weight: 650; }
.metric-card strong { position: relative; z-index: 1; display: block; margin: 14px 0 3px; font-size: 26px; line-height: 1; }
.metric-card strong small { display: inline; font-size: 15px; }
.metric-card em { color: #849089; font-size: 11px; font-style: normal; }
.metric-accent { color: #fff; background: var(--forest); border-color: var(--forest); }
.metric-accent > span, .metric-accent em { color: #c4d9d1; }
.metric-accent::after { background: #4b806e; }
.text-link { color: var(--forest-2); font-size: 12px; font-weight: 750; }
.count-chip, .stock-pill, .role-pill, .status { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; padding: 4px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.count-chip { color: var(--forest); background: var(--mint); }
.stock-pill { color: #245b49; background: #e5f4ed; }
.stock-pill.is-low { color: #8a611e; background: #fff0c9; }
.role-pill { color: #493d78; background: #efebff; }
.status-completed { color: #27664f; background: #e2f3ea; }
.status-void { color: #993a46; background: #fde8eb; }
.row-warning { background: #fffdf5; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: start; }
th { padding: 10px 12px; color: #708078; border-bottom: 1px solid var(--line); font-size: 10px; letter-spacing: .06em; text-align: start; text-transform: uppercase; white-space: nowrap; }
td { padding: 13px 12px; border-bottom: 1px solid #edf1ef; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background-color: #f8faf9; }
.table-subtitle { color: var(--muted); font-size: 11px; }
.empty-state { padding: 40px; color: var(--muted); text-align: center; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 16px; }
.toolbar p { margin: 0; }
.search-form { display: flex; width: min(560px, 100%); gap: 8px; }
.form-stack { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 18px; }
.form-inline, .date-filter { display: flex; align-items: end; gap: 12px; }
.form-inline label { min-width: min(360px, 100%); }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; }
.create-panel summary { color: var(--forest); font-size: 15px; font-weight: 800; list-style: none; }
.create-panel summary::-webkit-details-marker { display: none; }
.inline-details { position: relative; }
.inline-details > summary { color: var(--forest-2); font-size: 12px; font-weight: 750; list-style: none; }
.inline-details[open] .inline-form { display: grid; position: absolute; inset-inline-end: 0; z-index: 5; width: 260px; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.inline-form { display: inline-flex; align-items: center; gap: 6px; }
.inline-form input { min-height: 35px; }
.permission-note { margin-top: 18px; padding: 16px 18px; color: #4e514c; background: #f8f4ea; border-inline-start: 3px solid var(--gold); border-radius: 10px; }
.permission-note p { margin: 3px 0 0; color: var(--muted); }

.sale-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; align-items: start; }
.sale-line { display: grid; grid-template-columns: minmax(0, 1fr) 115px 34px; gap: 10px; align-items: end; padding: 13px 0; border-bottom: 1px solid var(--line); }
.sale-line:first-child { padding-top: 0; }
.sale-line:last-child { border-bottom: 0; }
.sale-summary { position: sticky; top: 24px; display: grid; gap: 13px; }
.estimated-total { display: flex; align-items: center; justify-content: space-between; margin: 8px 0; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.estimated-total strong { color: var(--forest); font-size: 22px; }
.filter-panel { padding: 16px 20px; }
.integration-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.integration-card { display: grid; gap: 16px; }
.integration-icon { display: grid; width: 46px; height: 46px; place-items: center; color: #fff; background: var(--forest); border-radius: 14px; font-size: 19px; font-weight: 900; }
.integration-card p { margin: 0; color: var(--muted); }
.integration-card dl { margin: 0; }
.integration-card dl div { display: flex; justify-content: space-between; padding: 7px 0; border-top: 1px solid var(--line); }
.integration-card dt { color: var(--muted); }
.integration-card dd { margin: 0; font-weight: 750; }
.endpoint { display: block; padding: 10px; overflow: auto; color: #d8eee5; background: #1d332b; border-radius: 9px; direction: ltr; }
.secret-reveal { margin-bottom: 20px; padding: 18px; color: #493711; background: #fff2cc; border: 1px solid #efd287; border-radius: 14px; }
.secret-reveal p { margin: 4px 0 10px; }
.secret-reveal code { display: block; padding: 10px; overflow-x: auto; background: #fff9e8; border-radius: 8px; direction: ltr; text-align: left; }

.guest-shell { display: grid; min-height: 100vh; padding: 24px; place-items: center; background: radial-gradient(circle at 15% 15%, #dcece6 0, transparent 28%), radial-gradient(circle at 90% 80%, #eee2cb 0, transparent 25%), #f3f6f4; }
.auth-card { width: min(450px, 100%); padding: 35px; background: rgba(255,255,255,.96); border: 1px solid rgba(210,222,216,.9); border-radius: 24px; box-shadow: 0 28px 80px rgba(24,63,53,.14); }
.brand-center { display: flex; justify-content: center; color: var(--forest); margin-bottom: 30px; }
.auth-card .brand small { color: var(--muted); }
.auth-copy { margin-bottom: 22px; text-align: center; }
.auth-copy h1 { margin-bottom: 9px; font-size: 28px; }
.auth-copy p { color: var(--muted); }
.security-note { margin: 18px 0 0; color: var(--muted); font-size: 11px; text-align: center; }
.language-center { width: max-content; margin: 22px auto 0; }

.invoice-page { padding: 30px; background: #e9eeeb; }
.invoice-sheet { width: min(900px, 100%); min-height: 1100px; margin: 0 auto; padding: 50px; background: #fff; box-shadow: var(--shadow); }
.invoice-header, .invoice-title, .invoice-meta { display: flex; justify-content: space-between; gap: 20px; }
.invoice-header { align-items: center; padding-bottom: 28px; border-bottom: 1px solid var(--line); }
.invoice-header .brand { color: var(--forest); }
.invoice-header .brand small { color: var(--muted); }
.invoice-actions { display: flex; gap: 8px; }
.invoice-title { align-items: center; padding: 38px 0 24px; }
.invoice-title h1 { font-family: Consolas, monospace; font-size: 26px; }
.invoice-meta { padding: 18px; background: #f5f8f6; border-radius: 12px; }
.invoice-meta > div { display: grid; }
.invoice-meta span { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.invoice-meta small { color: var(--muted); }
.invoice-table { margin-top: 30px; }
.invoice-totals { width: min(330px, 100%); margin: 30px 0 30px auto; }
[dir="rtl"] .invoice-totals { margin: 30px auto 30px 0; }
.invoice-totals div { display: flex; justify-content: space-between; padding: 7px 0; }
.invoice-totals .grand-total { margin-top: 8px; padding-top: 14px; border-top: 2px solid var(--forest); font-size: 18px; }
.invoice-note { padding: 14px; background: #f7f8f7; border-radius: 9px; }
.invoice-footer { margin-top: 60px; padding-top: 18px; color: var(--muted); border-top: 1px solid var(--line); text-align: center; }

@media (max-width: 1050px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sale-layout { grid-template-columns: 1fr; }
    .sale-summary { position: static; }
}

@media (max-width: 760px) {
    .portal-shell { display: block; }
    .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; transform: translateX(-110%); transition: transform .22s ease; }
    [dir="rtl"] .sidebar { transform: translateX(110%); }
    .sidebar.is-open { transform: translateX(0); }
    .mobile-toggle { position: fixed; display: grid; inset-inline-start: 14px; top: 14px; z-index: 30; width: 42px; height: 42px; place-items: center; color: #fff; background: var(--forest); border: 0; border-radius: 11px; box-shadow: var(--shadow); }
    .main-content { padding: 78px 16px 40px; }
    .topbar { margin-bottom: 22px; }
    .topbar .eyebrow { display: none; }
    .welcome-card { align-items: flex-start; flex-direction: column; }
    .metric-grid, .metric-grid-three, .integration-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .form-inline, .date-filter, .toolbar { align-items: stretch; flex-direction: column; }
    .sale-line { grid-template-columns: 1fr 90px 34px; }
    .invoice-page { padding: 0; }
    .invoice-sheet { min-height: 100vh; padding: 24px 16px; box-shadow: none; }
    .invoice-header, .invoice-title, .invoice-meta { flex-wrap: wrap; }
    .invoice-meta > div { width: calc(50% - 10px); }
}

@media print {
    @page { size: A4; margin: 12mm; }
    body.invoice-page { padding: 0; background: #fff; }
    .invoice-sheet { width: 100%; min-height: 0; padding: 0; box-shadow: none; }
    .invoice-actions { display: none; }
    .invoice-footer { margin-top: 35px; }
}

