:root {
    color-scheme: light;
    --paper: #f5f6f2;
    --surface: #ffffff;
    --ink: #222a26;
    --muted: #68736d;
    --line: #dfe4df;
    --green: #176b50;
    --green-dark: #104b39;
    --green-pale: #e7f2eb;
    --rust: #a14f34;
    --rust-pale: #f8ece7;
    --gold: #a27621;
    --gold-pale: #f7f0dc;
    --shadow: 0 14px 40px rgba(25, 43, 33, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 15px/1.5 "DM Sans", "Segoe UI", sans-serif;
}

a { color: var(--green); text-decoration: none; }
a:hover { color: var(--green-dark); }
button, input, select { font: inherit; }
button, a, input, select { outline-color: var(--green); }

.topbar {
    min-height: 76px;
    display: flex;
    align-items: center;
    gap: 42px;
    padding: 10px max(28px, calc((100vw - 1360px) / 2));
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); font-weight: 700; }
.brand img { width: 66px; height: 42px; object-fit: cover; object-position: center; border-radius: 3px; }
.brand > span { font-size: 16px; line-height: 1.2; }
.brand small, .user-menu small { display: block; color: var(--muted); font-size: 11px; font-weight: 500; }
.topnav { display: flex; min-width: 0; align-self: stretch; align-items: center; gap: 18px; overflow-x: auto; white-space: nowrap; }
.topnav a { display: flex; flex: 0 0 auto; align-items: center; height: 100%; color: var(--muted); border-bottom: 2px solid transparent; font-size: 12px; font-weight: 600; }
.topnav a.active { color: var(--green-dark); border-bottom-color: var(--green); }
.user-menu { display: flex; align-items: center; gap: 14px; margin-left: auto; font-size: 13px; font-weight: 600; }
.user-menu small { text-align: right; }
.logout { display: grid; width: 36px; height: 36px; place-items: center; color: var(--ink); border: 1px solid var(--line); border-radius: 50%; font-size: 19px; }
.logout:hover { background: var(--green-pale); }

.page-shell { width: min(1280px, calc(100% - 56px)); margin: 24px auto 80px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.page-heading h1, .login-panel h1 { margin: 3px 0 8px; font: 600 36px/1.12 "Newsreader", Georgia, serif; letter-spacing: 0; }
.eyebrow { margin: 0 0 8px; color: var(--green); font-size: 10px; font-weight: 700; letter-spacing: 0; }
.muted { color: var(--muted); }
.page-heading .muted { margin: 0; }
.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; gap: 10px; padding: 0 16px; border: 1px solid transparent; border-radius: 4px; font-weight: 700; cursor: pointer; transition: background-color .16s ease, border-color .16s ease; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button.primary { color: #fff; background: var(--green); }
.button.primary:hover:not(:disabled) { background: var(--green-dark); }
.button.secondary { color: var(--ink); background: #fff; border-color: var(--line); }
.button.secondary:hover:not(:disabled) { background: var(--paper); border-color: #b8c2bb; }
.button.danger { color: #fff; background: var(--rust); }
.button.danger:hover { background: #823d28; }
.surface { background: var(--surface); border: 1px solid var(--line); border-radius: 5px; box-shadow: var(--shadow); }
.notice { margin: 0 0 18px; padding: 12px 15px; border: 1px solid #d7dfd8; border-radius: 4px; background: #eef3ed; color: #34483c; font-size: 13px; }
.notice.error { border-color: #ebc9bc; background: var(--rust-pale); color: #713820; }
.notice.success { border-color: #c6ddcf; background: var(--green-pale); color: var(--green-dark); }
.notice code { font-size: 12px; }

.filters { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 14px; padding-bottom: 2px; }
.filters a { flex: 0 0 auto; padding: 8px 12px; color: var(--muted); border: 1px solid transparent; border-radius: 4px; font-size: 12px; font-weight: 600; }
.filters a:hover { color: var(--ink); background: #fff; }
.filters a.selected { color: var(--green-dark); border-color: #c6d8ca; background: var(--green-pale); }
.master-tabs { display: flex; gap: 7px; overflow-x: auto; margin: 0 0 16px; white-space: nowrap; }
.master-tabs a { flex: 0 0 auto; padding: 8px 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; background: var(--surface); font-size: 12px; font-weight: 600; }
.master-tabs a.selected { color: var(--green-dark); border-color: #c6d8ca; background: var(--green-pale); }
.admin-section { padding: 28px 0; border-bottom: 1px solid var(--line); scroll-margin-top: 24px; }
.admin-page-heading { align-items: center; }
.admin-section-nav { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.admin-section-nav a { flex: 0 0 auto; padding: 8px 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; background: var(--surface); font-size: 12px; font-weight: 600; }
.admin-section-nav a:hover, .admin-section-nav a.selected { color: var(--green-dark); border-color: #c6d8ca; background: var(--green-pale); }
.admin-section > .section-heading { margin-bottom: 14px; }
.admin-section > .section-heading h2 { margin: 0; font-size: 18px; }
.admin-editor { margin-bottom: 14px; }
.admin-table { border: 1px solid var(--line); border-radius: 4px; background: var(--surface); }
.admin-table table { min-width: 680px; }
.user-table table { min-width: 980px; }
.user-table select, .user-table input { width: 150px; min-height: 36px; padding: 6px 8px; }
.user-table input[type="password"] { width: 160px; }
.user-active-toggle { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.user-active-toggle input { width: 18px; min-height: 18px; margin: 0; padding: 0; accent-color: var(--green); }
.user-save-status { display: block; max-width: 160px; margin-top: 4px; color: var(--muted); font-size: 11px; }
.user-save-status.is-error { color: #913f2c; }
.master-form { margin-bottom: 16px; }
.master-actions { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.master-actions form { margin: 0; }
.button.compact { min-height: 32px; padding: 0 10px; font-size: 11px; }
.table-surface { overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 12px 14px; color: var(--muted); background: #f8f9f7; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; font-size: 10px; font-weight: 700; letter-spacing: 0; text-transform: uppercase; }
td { padding: 14px; border-bottom: 1px solid #edf0ed; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfa; }
.numeric { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.order-number { color: var(--green-dark); font-weight: 700; }
.table-link { display: inline-flex; gap: 8px; align-items: center; font-weight: 700; white-space: nowrap; }
.status { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 3px; color: #46564a; background: #edf0eb; font-size: 10px; font-weight: 700; white-space: nowrap; }
.status-pending_finance { color: #805c15; background: var(--gold-pale); }
.status-pending_approval { color: #7d492f; background: #f8e9df; }
.status-approved { color: #176b50; background: #e3f1e9; }
.status-rejected { color: #913f2c; background: #f8e7e2; }
.status-closed { color: #4f5d57; background: #e9edeb; }
.empty-state { padding: 48px 16px; color: var(--muted); text-align: center; }

.dataTables_wrapper { padding: 12px 14px; color: var(--muted); font-size: 12px; }
.dataTables_wrapper table.dataTable thead .sorting,
.dataTables_wrapper table.dataTable thead .sorting_asc,
.dataTables_wrapper table.dataTable thead .sorting_desc,
.dataTables_wrapper table.dataTable thead .sorting_asc_disabled,
.dataTables_wrapper table.dataTable thead .sorting_desc_disabled { background-image: none !important; }
.dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter { margin-bottom: 12px; color: var(--muted); }
.dataTables_wrapper .dataTables_length select, .dataTables_wrapper .dataTables_filter input { min-height: 34px; margin-left: 6px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 3px; background: #fff; color: var(--ink); }
.dataTables_wrapper .dataTables_filter input { width: min(220px, 55vw); }
.dataTables_wrapper .dataTables_info { padding-top: 14px; }
.dataTables_wrapper .dataTables_paginate { padding-top: 8px; }
.dataTables_wrapper .dataTables_paginate .paginate_button { margin-left: 3px; padding: 5px 9px; border: 1px solid transparent !important; border-radius: 3px; color: var(--ink) !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current { border-color: #c6d8ca !important; background: var(--green-pale) !important; color: var(--green-dark) !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button:hover { border-color: var(--line) !important; background: var(--paper) !important; color: var(--green-dark) !important; }

.back-link { display: inline-flex; min-height: 40px; align-items: center; gap: 6px; margin-bottom: 12px; padding: 0 16px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); background: #fff; font-size: 15px; font-weight: 700; transition: background-color .16s ease, border-color .16s ease; }
.back-link:hover { color: var(--green); background: var(--paper); border-color: #b8c2bb; }
.detail-heading { align-items: center; }
.detail-heading h1 { max-width: 780px; }
.order-sheet { padding: 26px 30px 30px; }
.sheet-top { display: flex; align-items: center; justify-content: space-between; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.sheet-top > div { display: flex; align-items: baseline; gap: 20px; }
.sheet-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sheet-top strong { font-size: 15px; }
.sheet-top span { color: var(--muted); font-size: 12px; }
.order-meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px 28px; margin: 22px 0 26px; }
.order-meta div { min-width: 0; }
.order-meta dt { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 0; text-transform: uppercase; }
.order-meta dd { margin: 4px 0 0; font-size: 13px; overflow-wrap: anywhere; }
.order-sheet table th { background: transparent; }
.totals { width: min(330px, 100%); margin: 20px 0 24px auto; }
.totals div { display: flex; justify-content: space-between; gap: 18px; padding: 7px 0; color: var(--muted); font-size: 13px; }
.totals strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.totals .grand-total { margin-top: 5px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--ink); font-size: 16px; font-weight: 700; }
.totals .grand-total strong { color: var(--green-dark); font-size: 19px; }
.review-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 20px 0; border-top: 1px solid var(--line); }
.reject-form { display: flex; flex: 1 1 420px; gap: 8px; }
.reject-form input { flex: 1; min-width: 120px; }
.timeline { margin-top: 8px; padding-top: 20px; border-top: 1px solid var(--line); }
.timeline h2, .form-section h2, .catalog-panel h2 { margin: 0 0 16px; font-size: 14px; font-weight: 700; }
.timeline-row { position: relative; display: flex; gap: 12px; padding: 0 0 18px; }
.timeline-dot { flex: 0 0 9px; width: 9px; height: 9px; margin-top: 6px; border: 2px solid var(--green); border-radius: 50%; background: white; }
.timeline-row strong, .timeline-row span { display: block; }
.timeline-row strong { font-size: 12px; }
.timeline-row span, .timeline-row p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }

.order-form { padding: 26px 30px; }
.form-section { padding: 0 0 25px; margin-bottom: 24px; border-bottom: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 18px; }
label { display: flex; flex-direction: column; gap: 6px; color: #45524a; font-size: 12px; font-weight: 600; }
.form-grid .wide { grid-column: span 3; }
input, select { width: 100%; min-height: 40px; padding: 8px 10px; color: var(--ink); border: 1px solid #cfd7d0; border-radius: 3px; background: #fff; }
input:focus, select:focus { border-color: var(--green); outline: 2px solid rgba(23, 107, 80, .12); }
input::placeholder { color: #9aa39c; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-heading h2 { margin: 0; }
.line-head, .line-row { display: grid; grid-template-columns: 120px minmax(200px, 1fr) 170px 38px; align-items: center; gap: 10px; }
.line-head { padding: 0 0 8px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.line-row { margin-bottom: 9px; }
.icon-button { width: 36px; height: 36px; color: var(--rust); border: 1px solid var(--line); border-radius: 3px; background: #fff; font-size: 22px; line-height: 1; cursor: pointer; }
.icon-button:hover { border-color: #dfb9aa; background: var(--rust-pale); }
.form-hint { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.check-row { display: flex; flex-direction: row; align-items: center; gap: 9px; margin: 11px 0; font-size: 13px; }
.check-row input { width: 17px; min-height: 17px; height: 17px; margin: 0; accent-color: var(--green); }
.form-footer { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.form-footer .back-link { margin: 0; }
.catalog-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.catalog-panel { padding: 20px; }
.catalog-panel h2 { margin-bottom: 12px; }
.catalog-form { display: flex; flex-wrap: wrap; gap: 8px; }
.catalog-form input { flex: 1 1 150px; min-width: 100px; }
.catalog-form .button { min-height: 40px; }
.catalog-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 0; padding: 0; list-style: none; }
.catalog-list li { padding: 5px 8px; color: #45524a; border: 1px solid var(--line); border-radius: 3px; font-size: 11px; }
.catalog-list li.muted { border-color: transparent; }
.user-form { margin-bottom: 16px; }
.users-table { overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

.login-shell { display: grid; min-height: 100vh; grid-template-columns: minmax(390px, .8fr) 1.2fr; background: var(--surface); }
.login-panel { display: flex; flex-direction: column; justify-content: center; width: min(410px, calc(100% - 64px)); margin: 0 auto; padding: 48px 0; }
.login-panel .brand { margin-bottom: 72px; }
.login-panel .brand img { width: 78px; height: 52px; }
.login-panel h1 { margin-bottom: 8px; font-size: 42px; }
.login-panel > .muted { margin: 0 0 26px; font-size: 13px; }
.stack-form { display: grid; gap: 15px; }
.stack-form .button { margin-top: 7px; }
.login-foot { margin-top: 38px; color: var(--muted); font-size: 10px; }
.login-aside { position: relative; min-height: 100vh; overflow: hidden; background: #35463a; }
.login-aside::after { position: absolute; inset: 0; background: linear-gradient(0deg, rgba(17, 37, 27, .72), transparent 58%); content: ""; }
.login-aside > img { width: 100%; height: 100%; position: absolute; object-fit: cover; object-position: center; }
.login-aside > div { position: absolute; z-index: 1; right: 42px; bottom: 38px; left: 42px; display: flex; justify-content: space-between; color: #fff; font-size: 11px; font-weight: 700; letter-spacing: 0; }

@media (max-width: 900px) {
    .topbar { gap: 18px; padding-right: 24px; padding-left: 24px; }
    .page-shell { width: calc(100% - 40px); margin-top: 20px; }
    .order-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
    .topbar { min-height: 66px; flex-wrap: wrap; gap: 0 14px; padding: 8px 16px; }
    .brand img { width: 52px; height: 34px; }
    .brand > span { font-size: 14px; }
    .topnav { order: 3; width: 100%; height: 40px; gap: 18px; }
    .topnav a { font-size: 12px; }
    .user-menu { gap: 8px; font-size: 11px; }
    .user-menu small { font-size: 10px; }
    .logout { width: 32px; height: 32px; }
    .page-shell { width: calc(100% - 28px); margin: 16px auto 48px; }
    .page-heading { align-items: flex-start; flex-direction: column; gap: 15px; margin-bottom: 20px; }
    .admin-page-heading { align-items: flex-start; }
    .admin-section-nav { justify-content: flex-start; }
    .page-heading h1 { font-size: 31px; }
    .page-heading > .button { width: 100%; }
    .filters { margin-right: -14px; }
    .filters a { padding: 7px 9px; font-size: 11px; }
    .master-tabs { margin-right: -14px; }
    .master-tabs a { padding: 7px 9px; font-size: 11px; }
    .dataTables_wrapper { padding: 10px 8px; }
    .dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter { float: none; width: 100%; text-align: left; }
    .dataTables_wrapper .dataTables_filter input { width: min(200px, 52vw); }
    .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate { float: none; text-align: left; }
    .order-sheet, .order-form { padding: 18px 15px; }
    .sheet-top { align-items: flex-start; gap: 12px; }
    .sheet-top > div { flex-direction: column; gap: 2px; }
    .sheet-top .button { min-height: 36px; padding: 0 9px; font-size: 11px; }
    .order-meta { gap: 15px 12px; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .wide { grid-column: auto; }
    .line-head { display: none; }
    .line-row { grid-template-columns: 1fr 38px; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
    .line-row input:nth-child(1) { grid-column: 1; }
    .line-row input:nth-child(2) { grid-column: 1; }
    .line-row input:nth-child(3) { grid-column: 1; }
    .line-row .icon-button { grid-column: 2; grid-row: 1 / span 3; }
    .section-heading { align-items: flex-start; }
    .section-heading .button { min-height: 36px; padding: 0 10px; font-size: 11px; }
    .form-footer { align-items: stretch; flex-direction: column-reverse; }
    .form-footer .back-link { text-align: center; }
    .reject-form { flex-basis: 100%; }
    .catalog-grid { grid-template-columns: 1fr; }
    .login-shell { display: block; min-height: 100vh; }
    .login-panel { width: min(410px, calc(100% - 36px)); min-height: 100vh; padding: 30px 0; }
    .login-panel .brand { margin-bottom: 60px; }
    .login-panel h1 { font-size: 37px; }
    .login-aside { display: none; }
}

@media print {
    body { background: #fff; }
    .topbar, .no-print, .back-link, .notice.success { display: none !important; }
    .page-shell { width: 100%; margin: 0; }
    .surface { border: 0; box-shadow: none; }
    .order-sheet { padding: 0; }
    .detail-heading { margin-bottom: 14px; }
    .detail-heading h1 { font-size: 24px; }
    .order-meta { grid-template-columns: repeat(3, 1fr); }
    th { background: transparent; }
}
/* Formulario enviado: evita un segundo clic mientras el servidor responde. */
.is-busy {
    opacity: 0.6;
    pointer-events: none;
    cursor: progress;
}
