:root {
    color-scheme: light;
    --ink: #20231f;
    --muted: #72776f;
    --paper: #f5f6f2;
    --card: #ffffff;
    --line: #e3e6df;
    --green: #315b43;
    --green-dark: #234432;
    --amber: #c98531;
    --red: #a64235;
    font-family: "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-size: 15px;
}

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

.app-shell { min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    width: 250px;
    padding: 26px 18px 18px;
    color: #f7f8f5;
    background: #202c24;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border: 1px solid #c98b45;
    border-radius: 11px;
    color: #f0c080;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: .04em;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: .09em; }
.brand small { margin-top: 4px; color: #bac4bb; font-size: 12px; }

.sidebar nav { margin-top: 42px; }
.nav-link {
    display: block;
    padding: 12px 13px;
    border-radius: 8px;
    color: #dce4dd;
}
.nav-link.active { background: #35463a; color: #fff; }
.sidebar-bottom { display: grid; gap: 7px; margin-top: auto; }
.user-name { font-weight: 650; }
.user-role { margin-bottom: 8px; color: #bac4bb; font-size: 13px; }

.main-content { max-width: 1500px; margin-left: 250px; padding: 36px clamp(22px, 4vw, 58px); }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 28px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(26px, 3vw, 34px); letter-spacing: -.035em; }
h2 { margin-bottom: 0; font-size: 20px; }
.eyebrow { margin-bottom: 8px; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.muted { margin-bottom: 0; color: var(--muted); }
.date-chip { padding: 9px 13px; border: 1px solid var(--line); border-radius: 20px; background: #fff; color: #4d554c; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 9px; }
.header-actions form { margin: 0; }

.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 24px; }
.metric-card, .panel, .login-card { border: 1px solid var(--line); border-radius: 12px; background: var(--card); box-shadow: 0 5px 18px rgb(32 44 36 / 3%); }
.metric-card { display: flex; min-height: 125px; flex-direction: column; justify-content: space-between; padding: 18px; }
.metric-card span { color: var(--muted); font-size: 13px; }
.metric-card strong { font-size: 30px; letter-spacing: -.04em; }
.metric-card small { color: var(--muted); font-size: 11px; }
.metric-finance { border-top: 3px solid var(--green); }
.panel { padding: 22px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 17px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: 12px 10px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
td { padding: 14px 10px; border-bottom: 1px solid #edf0eb; font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
.order-number { color: var(--green-dark); font-weight: 750; white-space: nowrap; }
.status-pill { display: inline-block; padding: 5px 9px; border-radius: 14px; background: #edf0eb; color: #4f594f; font-size: 11px; font-weight: 700; white-space: nowrap; }
.status-en_diagnostico, .status-presupuesto_pendiente, .status-esperando_aprobacion_complementaria { background: #fff3dc; color: #875713; }
.status-en_reparacion { background: #e5f0e8; color: #315b43; }
.status-lista_para_retirar { background: #e4eef7; color: #315e82; }
.status-presupuesto_rechazado, .status-cancelada { background: #fae9e6; color: #8f392e; }
.status-retirada { background: #edf0eb; color: #5a6259; }
.status-active { background: #e5f0e8; color: #315b43; }
.status-inactive { background: #edf0eb; color: #6f756e; }
.empty-state { padding: 32px 12px; color: var(--muted); text-align: center; }
.empty-inline { margin: 0; color: var(--muted); font-size: 13px; }
.text-action, .table-link { color: var(--green); font-weight: 700; }
.text-action:hover, .table-link:hover { text-decoration: underline; }
.text-danger { color: var(--red); }
.row-actions { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.row-actions form { margin: 0; }
.link-button { padding: 0; border: 0; background: transparent; color: var(--green); cursor: pointer; font: inherit; font-weight: 700; }
.link-button:hover { text-decoration: underline; }
.status-low { background: #fff3dc; color: #875713; }
.stock-hint { margin: 0 0 12px; }
.filter-form { display: grid; grid-template-columns: minmax(220px, 1fr) 160px auto; gap: 10px; margin-bottom: 16px; }
.filter-form input, .filter-form select, .field input, .field select, .field textarea { width: 100%; min-height: 42px; padding: 10px 12px; border: 1px solid #cfd5cc; border-radius: 7px; background: #fff; color: var(--ink); }
.filter-form input:focus, .filter-form select:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); outline: 3px solid #315b4320; }
.list-summary { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 20px; color: var(--muted); font-size: 13px; }
.button-secondary { border: 1px solid #d1d8cf; background: #fff; color: var(--ink); }
.button-secondary:hover { border-color: var(--green); color: var(--green); }
.button-danger { background: var(--red); color: #fff; }
.button-danger-quiet { background: #fae9e6; color: #8f392e; }
.button-danger-quiet:hover { background: #f5d8d2; }
.form-panel { max-width: 900px; }
.data-form { display: grid; gap: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { display: grid; align-content: start; gap: 7px; }
.field label { font-size: 13px; font-weight: 700; }
.field-wide { grid-column: 1 / -1; }
.field textarea { resize: vertical; }
.field-error { color: var(--red); }
.error-list { margin: 8px 0 0; padding-left: 20px; }
.checkbox-row { display: flex; align-items: flex-start; gap: 10px; font-size: 13px; font-weight: 650; }
.checkbox-row input { margin-top: 3px; accent-color: var(--green); }
.form-hint { margin: -14px 0 0 25px; color: var(--muted); font-size: 12px; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 4px; }
.form-actions .button-primary { margin-top: 0; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.detail-wide { grid-column: 1 / -1; }
.detail-list { display: grid; gap: 0; margin: 0; }
.detail-list > div { display: grid; grid-template-columns: minmax(140px, .7fr) 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid #edf0eb; }
.detail-list > div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); font-size: 12px; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; font-size: 13px; }
.count-chip { display: inline-grid; min-width: 26px; height: 26px; place-items: center; border-radius: 13px; background: #edf0eb; color: #4f594f; font-size: 12px; font-weight: 700; }
.compact-list { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.compact-list li { display: grid; gap: 5px; padding-bottom: 11px; border-bottom: 1px solid #edf0eb; font-size: 13px; }
.compact-list li:last-child { padding-bottom: 0; border-bottom: 0; }
.compact-list span { color: var(--muted); font-size: 12px; }
.confirmation-panel { max-width: 650px; }
.confirmation-panel > p:first-child { font-size: 17px; }
.confirmation-panel .form-actions { margin-top: 24px; }
.error-page { max-width: 650px; margin: 8vh auto; }
.error-page .button { margin-top: 20px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }

.login-shell { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(circle at top left, #e3ebdf, transparent 42%), var(--paper); }
.login-card { width: min(100%, 420px); padding: 34px; }
.login-brand { margin-bottom: 34px; color: var(--ink); }
.login-brand .brand-mark { color: var(--green); border-color: var(--green); }
.login-brand small { color: var(--muted); }
.login-card h1 { font-size: 25px; }
.login-card > .muted { margin-bottom: 24px; }
.form-stack { display: grid; gap: 10px; }
.form-stack label { margin-top: 6px; font-size: 13px; font-weight: 650; }
.form-stack input { width: 100%; padding: 12px; border: 1px solid #cfd5cc; border-radius: 7px; background: #fff; }
.form-stack input:focus { border-color: var(--green); outline: 3px solid #315b4320; }
.button { display: inline-flex; min-height: 40px; align-items: center; justify-content: center; padding: 9px 13px; border: 0; border-radius: 7px; cursor: pointer; font-weight: 700; }
.button-primary { margin-top: 12px; background: var(--green); color: white; }
.button-primary:hover { background: var(--green-dark); }
.button-quiet { background: #34443a; color: #f7f8f5; }
.button-full { width: 100%; }
.alert { margin-bottom: 18px; padding: 12px 14px; border-radius: 7px; font-size: 13px; }
.alert-error { background: #fae9e6; color: #8f392e; }
.alert-success { background: #e5f0e8; color: #315b43; }
.alert-info { background: #e4eef7; color: #315e82; }

.order-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; align-items: start; gap: 18px; }
.order-main, .order-side { display: grid; gap: 16px; min-width: 0; }
.inline-forms { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.inline-form { display: flex; align-items: end; gap: 9px; }
.inline-form label { font-size: 12px; font-weight: 700; }
.inline-form select, .inline-form input { min-width: 0; min-height: 40px; padding: 9px; border: 1px solid #cfd5cc; border-radius: 7px; background: #fff; }
.inline-form-wrap { flex-wrap: wrap; margin: 16px 0; }
.inline-form-wrap .field { flex: 1 1 210px; }
.task-list { margin-top: 15px; }
.use-part-form { margin-top: 9px; }
.use-part-form .field { flex: 0 1 180px; }
.order-main h3 { margin: 15px 0 10px; font-size: 14px; }
.finalize-form { margin-top: 23px; padding-top: 18px; border-top: 1px solid var(--line); }
.budget-lines { display: grid; gap: 10px; }
.budget-line { display: grid; grid-template-columns: 1fr 1.4fr 1.5fr .7fr .9fr auto; align-items: end; gap: 9px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
.budget-line .field { min-width: 0; }
.budget-line input, .budget-line select { min-width: 0; min-height: 40px; padding: 8px; border: 1px solid #cfd5cc; border-radius: 7px; background: #fff; }
.remove-budget-line { padding: 8px 0; color: var(--red); }
.budget-card { padding: 17px 0; border-top: 1px solid var(--line); }
.budget-card:first-of-type { padding-top: 0; border-top: 0; }
.budget-card header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.budget-card h3 { margin: 0 0 4px; font-size: 15px; }
.budget-card p { margin: 12px 0 0; font-size: 13px; }
.budget-total { margin-top: 10px; text-align: right; }
.decision-form { display: grid; grid-template-columns: 1fr 1fr auto auto; align-items: end; gap: 9px; margin-top: 15px; }
.decision-form .field { min-width: 0; }
.decision-form input { min-width: 0; min-height: 40px; padding: 8px; border: 1px solid #cfd5cc; border-radius: 7px; }
.button-danger-quiet { min-height: 40px; padding: 9px 13px; border: 0; border-radius: 7px; cursor: pointer; font-weight: 700; }
.receipt-document { max-width: 820px; margin: 0 auto; padding: 40px; border: 1px solid var(--line); background: #fff; }
.print-toolbar { display: flex; justify-content: space-between; max-width: 820px; margin: 0 auto 16px; }
.receipt-header { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 20px; border-bottom: 2px solid var(--ink); }
.receipt-brand { font-size: 24px; font-weight: 800; letter-spacing: .1em; }
.receipt-header p { margin: 5px 0 0; color: var(--muted); }
.receipt-number { display: grid; gap: 4px; text-align: right; }
.receipt-number strong { font-size: 20px; }
.receipt-number span { color: var(--muted); font-size: 12px; }
.receipt-notice { margin: 20px 0; padding: 12px; background: #f5f6f2; font-size: 13px; }
.receipt-section { margin: 22px 0; }
.receipt-section h2 { margin-bottom: 10px; font-size: 14px; text-transform: uppercase; }
.receipt-section p { margin: 4px 0; font-size: 13px; }
.receipt-signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 50px; margin-top: 70px; }
.receipt-signatures div { padding-top: 8px; border-top: 1px solid #777; font-size: 12px; text-align: center; }
.receipt-footer { margin: 35px 0 0; color: var(--muted); font-size: 11px; text-align: center; }
.ticket-document { max-width: 900px; margin: 0 auto; padding: 40px; border: 1px solid var(--line); background: #fff; }
.ticket-payment-summary { display: grid; gap: 8px; width: min(100%, 360px); margin: 20px 0 20px auto; }
.ticket-payment-summary > div { display: flex; justify-content: space-between; gap: 15px; font-size: 13px; }
.ticket-balance { padding-top: 10px; border-top: 1px solid var(--ink); font-size: 17px !important; }
.ticket-payment-summary p { margin: 5px 0; color: var(--muted); font-size: 12px; text-align: right; }
.tracking-admin-panel { margin-top: 18px; }
.tracking-controls, .tracking-share { display: grid; justify-items: start; gap: 10px; }
.tracking-share { width: min(100%, 720px); margin-top: 20px; padding: 16px; border: 1px solid var(--line); border-radius: 9px; background: #fafbf8; }
.tracking-share label { font-size: 13px; font-weight: 700; }
.tracking-share input { width: 100%; min-height: 42px; padding: 9px; border: 1px solid #cfd5cc; border-radius: 7px; }
.tracking-draft { display: grid; justify-items: start; gap: 10px; margin-top: 16px; padding: 14px; border-left: 3px solid var(--green); background: #f4f7f1; }
.tracking-page { width: min(100%, 760px); margin: 36px auto; }
.tracking-brand { display: flex; align-items: center; gap: 12px; margin: 0 0 22px 4px; }
.tracking-brand div { display: grid; gap: 3px; }
.tracking-brand strong { letter-spacing: .08em; }
.tracking-brand small { color: var(--muted); }
.tracking-card { padding: 30px; border: 1px solid var(--line); border-radius: 13px; background: #fff; box-shadow: 0 10px 30px rgb(31 45 24 / 7%); }
.tracking-card h1 { margin: 8px 0; font-size: clamp(24px, 5vw, 34px); }
.tracking-machine { color: var(--muted); }
.tracking-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 24px 0; padding: 16px; border-radius: 9px; background: #f5f6f2; }
.tracking-summary div { display: grid; gap: 5px; }
.tracking-summary dt { color: var(--muted); font-size: 12px; }
.tracking-summary dd { margin: 0; font-weight: 700; }
.tracking-timeline { margin-top: 28px; }
.tracking-timeline h2 { font-size: 16px; }
.tracking-timeline ol { display: grid; gap: 0; margin: 16px 0; padding: 0; list-style: none; }
.tracking-timeline li { position: relative; display: flex; gap: 12px; min-height: 58px; }
.tracking-timeline li:not(:last-child)::before { position: absolute; top: 13px; bottom: -2px; left: 5px; width: 2px; background: var(--line); content: ""; }
.tracking-dot { z-index: 1; width: 12px; height: 12px; margin-top: 3px; border: 2px solid var(--green); border-radius: 50%; background: #fff; }
.tracking-timeline li div { display: grid; align-content: start; gap: 4px; }
.tracking-timeline time { color: var(--muted); font-size: 12px; }
.tracking-note, .tracking-footer { color: var(--muted); font-size: 12px; }
.tracking-note { margin: 24px 0 0; padding-top: 14px; border-top: 1px solid var(--line); }
.tracking-footer { margin: 18px 5px; text-align: center; }
.budget-pdf-document { max-width: 900px; margin: 0 auto; padding: 42px; border: 1px solid var(--line); background: #fff; }
.budget-pdf-header { display: flex; justify-content: space-between; gap: 24px; padding-bottom: 22px; border-bottom: 2px solid var(--ink); }
.budget-pdf-header p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.budget-pdf-number { display: grid; gap: 5px; text-align: right; }
.budget-pdf-number strong { font-size: 18px; }
.budget-pdf-number span { color: var(--muted); font-size: 12px; }
.budget-pdf-customer { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin: 24px 0; }
.budget-pdf-customer > div { display: grid; gap: 4px; }
.budget-pdf-customer span { color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.budget-pdf-customer strong { font-size: 13px; }
.budget-pdf-customer small { color: var(--muted); font-size: 11px; }
.budget-pdf-table { margin: 28px 0; }
.budget-pdf-table td { vertical-align: top; }
.budget-pdf-table small { color: var(--muted); }
.budget-pdf-totals { display: grid; gap: 8px; width: min(100%, 360px); margin: 20px 0 20px auto; }
.budget-pdf-totals > div { display: flex; justify-content: space-between; gap: 20px; font-size: 13px; }
.budget-pdf-grand-total { margin-top: 5px; padding-top: 12px; border-top: 1px solid var(--ink); font-size: 17px !important; }
.budget-pdf-notes { margin-top: 22px; }
.budget-pdf-notes h2 { margin-bottom: 7px; font-size: 13px; text-transform: uppercase; }
.budget-pdf-notes p { margin: 0; font-size: 12px; }
.budget-pdf-disclaimer { margin-top: 30px; padding: 12px; background: #f5f6f2; color: #4d554c; font-size: 11px; }
.budget-pdf-signature { display: grid; grid-template-columns: 1fr 1fr; gap: 55px; margin-top: 65px; }
.budget-pdf-signature div { padding-top: 8px; border-top: 1px solid #777; font-size: 11px; text-align: center; }
.debt-reason-field[hidden] { display: none; }
button:disabled { cursor: not-allowed; opacity: .55; }

@media (max-width: 1050px) {
    .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .order-layout { grid-template-columns: minmax(0, 1fr); }
    .order-side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .budget-line { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .decision-form { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 680px) {
    .sidebar { position: static; width: auto; min-height: auto; padding: 14px 18px; }
    .sidebar nav { display: none; }
    .sidebar-bottom { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
    .sidebar-bottom form { margin-left: auto; }
    .sidebar-bottom .button { min-height: 34px; padding: 7px 9px; font-size: 12px; }
    .user-role { margin: 0; }
    .main-content { margin-left: 0; padding: 24px 16px; }
    .page-header { flex-direction: column; }
    .header-actions { flex-wrap: wrap; }
    .row-actions { flex-wrap: wrap; gap: 8px; }
    .date-chip { align-self: flex-start; }
    .metrics-grid { grid-template-columns: 1fr; gap: 10px; }
    .metric-card { min-height: 100px; }
    .panel { padding: 16px 12px; }
    .login-card { padding: 26px 21px; }
    .filter-form { grid-template-columns: 1fr; }
    .form-grid, .detail-grid { grid-template-columns: 1fr; }
    .detail-wide, .field-wide { grid-column: auto; }
    .detail-list > div { grid-template-columns: 110px 1fr; }
    .form-actions { flex-wrap: wrap; }
    .order-side, .inline-forms { grid-template-columns: 1fr; }
    .budget-line, .decision-form { grid-template-columns: 1fr; }
    .receipt-document { padding: 20px 14px; }
    .tracking-card { padding: 22px 17px; }
    .tracking-summary { grid-template-columns: 1fr; }
    .receipt-header { flex-direction: column; }
    .receipt-number { text-align: left; }
    .print-toolbar { flex-wrap: wrap; gap: 8px; }
}

@media print {
    @page { size: A4; margin: 16mm; }
    body { background: #fff; }
    .sidebar, .print-toolbar, .alert, .page-header { display: none !important; }
    .main-content { max-width: none; margin: 0; padding: 0; }
    .receipt-document, .budget-pdf-document, .ticket-document { max-width: none; margin: 0; padding: 0; border: 0; box-shadow: none; }
    .budget-pdf-document { font-size: 11pt; }
    .budget-pdf-table tr { break-inside: avoid; }
}
