:root {
    --ink: #172a2f;
    --muted: #6d7c7f;
    --paper: #fffdf8;
    --canvas: #f2f4ee;
    --line: #dce2da;
    --primary: #0d6b62;
    --primary-dark: #084f49;
    --accent: #d59645;
    --danger: #a54040;
    --success: #28735a;
    --shadow: 0 14px 38px rgba(31, 52, 52, .08);
    --radius: 16px;
}

* { box-sizing: border-box; }
html { font-family: Tahoma, "Segoe UI", Arial, sans-serif; color: var(--ink); background: var(--canvas); }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 85% 0, rgba(213,150,69,.09), transparent 28rem), var(--canvas); }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; z-index: 30; inset: 0 0 0 auto; width: 260px; overflow-y: auto; padding: 24px 18px; background: #173b3a; color: #fff; box-shadow: -8px 0 30px rgba(0,0,0,.08); }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 22px; color: #fff; border-bottom: 1px solid rgba(255,255,255,.12); }
.sidebar-brand strong { display: block; max-width: 165px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-brand small { display: block; margin-top: 4px; color: #b9cfcb; }
.brand-mark { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 18px; border-radius: 18px; color: #fff; background: linear-gradient(145deg, var(--primary), #159183); font-size: 27px; font-weight: 800; box-shadow: 0 10px 22px rgba(13,107,98,.2); }
.brand-mark.small { flex: 0 0 auto; width: 39px; height: 39px; margin: 0; border-radius: 12px; font-size: 20px; background: var(--accent); box-shadow: none; }
.nav-heading { margin: 24px 12px 8px; color: #92b2ad; font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.nav-link { display: block; margin: 3px 0; padding: 10px 12px; border-radius: 10px; color: #dce9e6; transition: .16s ease; }
.nav-link:hover { color: #fff; background: rgba(255,255,255,.07); }
.nav-link.active { color: #fff; background: rgba(213,150,69,.2); box-shadow: inset -3px 0 var(--accent); }
.main-column { min-height: 100vh; margin-right: 260px; }
.topbar { position: sticky; z-index: 20; top: 0; display: flex; align-items: center; justify-content: space-between; height: 68px; padding: 0 34px; background: rgba(242,244,238,.92); border-bottom: 1px solid rgba(220,226,218,.8); backdrop-filter: blur(12px); }
.user-menu { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 14px; }
.user-menu a { padding-right: 14px; border-right: 1px solid var(--line); color: var(--danger); }
.menu-button { display: none; border: 0; background: transparent; color: var(--ink); font-size: 24px; cursor: pointer; }
.content { width: min(1320px, 100%); margin: 0 auto; padding: 34px; }

.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 22px; margin-bottom: 24px; }
.page-heading h1 { margin: 2px 0 7px; font-size: clamp(25px, 3vw, 38px); line-height: 1.2; }
.page-heading p { margin: 0; color: var(--muted); }
.eyebrow { margin: 0 0 5px !important; color: var(--primary) !important; font-size: 12px; font-weight: 800; letter-spacing: .04em; }
.heading-actions, .form-actions, .actions { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }

.panel { margin-bottom: 22px; padding: 22px; border: 1px solid rgba(220,226,218,.95); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.panel-heading h2 { margin: 0; font-size: 19px; }
.form-panel { max-width: 920px; }
.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; padding: 9px 17px; border: 1px solid transparent; border-radius: 10px; font-weight: 700; cursor: pointer; transition: transform .12s ease, background .12s ease, box-shadow .12s ease; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: #fff; background: var(--primary); box-shadow: 0 7px 18px rgba(13,107,98,.16); }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { color: var(--ink); background: #fff; border-color: var(--line); }
.button.small { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.button.full { width: 100%; }
.text-link { display: block; margin-top: 18px; text-align: center; font-weight: 700; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-grid .span-2 { grid-column: 1 / -1; }
label { display: grid; gap: 7px; color: #34494c; font-size: 14px; font-weight: 700; }
label small { color: var(--muted); font-weight: 400; line-height: 1.7; }
input, select, textarea { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #cfd8d0; border-radius: 9px; outline: none; color: var(--ink); background: #fff; transition: border .15s, box-shadow .15s; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13,107,98,.1); }
input[readonly] { background: #f3f4f0; color: var(--muted); }
.form-actions { margin-top: 22px; }
.check-label { display: flex; align-items: center; align-self: end; min-height: 44px; gap: 9px; }
.check-label input, .permission-card input { width: 18px; min-height: 18px; accent-color: var(--primary); }
.stack-form { display: grid; gap: 16px; }
.stack-form .button { margin-top: 4px; }

.table-wrap { max-width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { padding: 12px; border-bottom: 2px solid var(--line); color: #45595b; text-align: right; white-space: nowrap; }
td { padding: 13px 12px; border-bottom: 1px solid #e7ebe5; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(13,107,98,.025); }
tfoot th { border-top: 2px solid var(--line); border-bottom: 0; color: var(--ink); }
.items-table { min-width: 690px; }
.items-table td { vertical-align: middle; }
.items-table td:first-child { min-width: 300px; }
.items-table small { display: block; min-height: 17px; margin-top: 5px; color: var(--primary); }
.table-link { padding: 0; border: 0; background: none; color: var(--primary); font-weight: 700; cursor: pointer; white-space: nowrap; }
.danger-text { color: var(--danger) !important; }
.positive { color: var(--success); }
.negative { color: var(--danger); }
.inline-form { display: inline-flex; margin: 0; }
.icon-button { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 9px; background: #fff; font-size: 22px; cursor: pointer; }
.badge { display: inline-flex; padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge.active { color: #1f654e; background: #e3f3eb; }
.badge.inactive { color: #8c3e3e; background: #f7e5e2; }
.inactive-row { color: #8a9392; background: #f7f7f4; }
.inactive-row td:not(:last-child) { text-decoration-color: #c7ccca; }
.empty { padding: 34px !important; color: var(--muted); text-align: center; }

.alert { margin-bottom: 18px; padding: 13px 15px; border: 1px solid; border-radius: 10px; line-height: 1.65; }
.alert.success { color: #205d49; border-color: #bedfce; background: #e8f5ee; }
.alert.danger { color: #883636; border-color: #ebc7c2; background: #fbebe8; }
.muted { color: var(--muted); line-height: 1.75; }

.dashboard-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.dashboard-card { display: grid; min-height: 160px; align-content: space-between; gap: 12px; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); background: var(--paper); box-shadow: var(--shadow); transition: .16s ease; }
.dashboard-card:hover { transform: translateY(-3px); border-color: #afcac3; }
.dashboard-card strong { font-size: 19px; }
.dashboard-card span { color: var(--muted); line-height: 1.7; }
.dashboard-card b { color: var(--primary); font-size: 13px; }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 20px; }
.stat-card { display: grid; gap: 10px; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
.stat-card span { color: var(--muted); }
.stat-card strong { color: var(--primary); font-size: clamp(30px, 4vw, 44px); line-height: 1; }
.context-panel { margin-bottom: 20px; }
.compact-filter { padding: 0; border: 0; box-shadow: none; margin: 0; }
.context-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.selected-row { background: #f1f8f6; }

.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(circle at 80% 5%, rgba(213,150,69,.17), transparent 28rem), #edf1eb; }
.auth-card { width: min(430px, 100%); padding: 34px; border: 1px solid rgba(220,226,218,.95); border-radius: 22px; background: var(--paper); box-shadow: 0 24px 60px rgba(23,59,58,.13); }
.auth-card h1 { margin: 4px 0 22px; text-align: center; font-size: 28px; }
.auth-card .eyebrow, .auth-card > .muted { text-align: center; }
.install-card { width: min(560px, 100%); }
.credential-box { display: grid; gap: 7px; margin: 18px 0; padding: 18px; border: 1px dashed var(--accent); border-radius: 12px; text-align: center; background: #fff9ef; }
.credential-box span { color: var(--muted); font-size: 13px; }
.credential-box strong { font-size: 20px; letter-spacing: .05em; }

.filter-bar { display: flex; align-items: end; flex-wrap: wrap; gap: 13px; }
.filter-bar label { min-width: 150px; flex: 1; }
.filter-bar .button { flex: 0 0 auto; }
.permissions-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px; }
.permission-card { display: flex; align-items: center; gap: 10px; padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
.permission-card:has(input:checked) { border-color: #8dbcb2; background: #edf8f4; }
.subsection-title { margin: 26px 0 16px; padding-top: 20px; border-top: 1px solid var(--line); }
.subsection-title h3 { margin: 0; font-size: 17px; }
.checkbox-fieldset { margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 10px; }
.checkbox-fieldset legend { padding: 0 7px; color: #34494c; font-size: 14px; font-weight: 700; }

.movement-form { padding-bottom: 76px; }
.sticky-actions { position: fixed; z-index: 15; right: calc(260px + 34px); bottom: 18px; padding: 10px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,253,248,.94); box-shadow: 0 12px 34px rgba(23,59,58,.13); backdrop-filter: blur(10px); }
.document-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding-bottom: 18px; border-bottom: 2px solid var(--ink); }
.document-header h1 { margin: 3px 0; font-size: 26px; }
.document-number { display: grid; min-width: 155px; gap: 5px; padding: 13px; border-radius: 10px; text-align: center; background: #edf4f1; }
.document-number span { color: var(--muted); font-size: 12px; }
.document-number strong { font-size: 17px; }
.details-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 22px 0; }
.details-grid div { padding: 12px; border: 1px solid var(--line); border-radius: 9px; }
.details-grid .wide { grid-column: 1 / -1; }
.details-grid dt { margin-bottom: 5px; color: var(--muted); font-size: 12px; }
.details-grid dd { margin: 0; font-weight: 700; }
.audit-info { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-top: 20px; color: var(--muted); font-size: 12px; }
.print-meta { display: flex; justify-content: space-between; gap: 18px; margin-top: 34px; padding-top: 12px; border-top: 1px solid var(--line); color: #536365; font-size: 11px; }
.report-section { margin-top: 28px; break-inside: avoid; }
.report-section h2 { margin: 0 0 12px; font-size: 18px; }
.report-section h2 small { color: var(--muted); font-size: 13px; font-weight: 400; }
.opening-row { background: #eef4f1; font-weight: 800; }

.sidebar-backdrop { display: none; position: fixed; z-index: 25; inset: 0; background: rgba(20,35,35,.42); }

@media (max-width: 1050px) {
    .dashboard-grid, .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .permissions-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
    .sidebar { transform: translateX(105%); transition: transform .2s ease; }
    .sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-open .sidebar-backdrop { display: block; }
    .main-column { margin-right: 0; }
    .topbar { padding: 0 18px; }
    .menu-button { display: block; }
    .content { padding: 24px 18px; }
    .sticky-actions { right: 18px; left: 18px; bottom: 10px; justify-content: center; }
    .details-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
    .page-heading { align-items: stretch; flex-direction: column; }
    .page-heading > .button, .heading-actions .button { flex: 1; }
    .heading-actions { width: 100%; }
    .form-grid, .dashboard-grid, .stats-grid, .permissions-grid, .details-grid { grid-template-columns: 1fr; }
    .form-grid .span-2, .details-grid .wide { grid-column: auto; }
    .panel { padding: 16px; border-radius: 13px; }
    .auth-card { padding: 26px 20px; }
    .user-menu span { display: none; }
    .filter-bar { align-items: stretch; flex-direction: column; }
    .filter-bar label, .filter-bar .button { width: 100%; }
    .document-header { align-items: stretch; flex-direction: column; }
    .document-number { min-width: 0; }
}

@media print {
    @page { size: A4; margin: 14mm; }
    html, body { color: #000; background: #fff; }
    .sidebar, .topbar, .no-print, .sidebar-backdrop { display: none !important; }
    .main-column { margin: 0; }
    .content { width: 100%; padding: 0; }
    .panel, .print-document { margin: 0; padding: 0; border: 0; box-shadow: none; background: #fff; }
    .table-wrap { overflow: visible; }
    table { font-size: 11px; }
    th, td { padding: 7px 6px; color: #000; }
    a { color: #000; text-decoration: none; }
    .document-header { margin-bottom: 15px; }
    .details-grid { margin: 12px 0; }
    .details-grid div { padding: 8px; }
    .report-section { margin-top: 18px; }
    .print-meta { break-inside: avoid; }
    .inactive-row { color: #666 !important; background: #eee !important; }
}
