/* ORIGEN — estilos locales, sin CDN */
:root {
  --green-900: #1a3730;
  --green: #24483D;
  --emerald: #347D63;
  --emerald-50: #e8f2ed;
  --bg: #F5F7F6;
  --gold: #B38A47;
  --gold-50: #f7efe2;
  --ink: #1d2a26;
  --ink-2: #4a5a54;
  --ink-3: #6b7a74;
  --line: #dbe3df;
  --line-2: #eef2f0;
  --white: #fff;
  --red: #a83232;
  --red-50: #fbeaea;
  --amber: #8a5a00;
  --amber-50: #fdf3df;
  --blue: #2d5a88;
  --blue-50: #e8f0f8;
  --radius: 8px;
  --sidebar: 232px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--emerald); }
a:hover { color: var(--green); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--gold); color: #000; padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; color: var(--green); }
h2 { font-size: 16px; margin: 0 0 10px; color: var(--green); }
h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12px; }
.ico { width: 18px; height: 18px; flex: none; }
[hidden] { display: none !important; }

/* Layout */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; transition: grid-template-columns .15s; }
.shell.collapsed { grid-template-columns: 64px 1fr; }
.sidebar { background: var(--green); color: #e8efec; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; overflow-y: auto; z-index: 30; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 14px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand img { border-radius: 50%; background: #fff; flex: none; }
.brand-text strong { display: block; letter-spacing: .28em; font-size: 15px; color: #fff; }
.brand-text span { font-size: 11px; color: var(--gold); letter-spacing: .04em; }
.sidebar nav ul { list-style: none; margin: 8px 0; padding: 0 8px; }
.sidebar nav a { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 6px; color: #d7e2dd; text-decoration: none; font-size: 13.5px; }
.sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar nav a.active { background: var(--emerald); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.collapse-btn { margin: auto 8px 12px; display: flex; gap: 10px; align-items: center; background: transparent; border: 1px solid rgba(255,255,255,.15); color: #cfdcd6; border-radius: 6px; padding: 7px 10px; cursor: pointer; font: inherit; font-size: 12px; }
.shell.collapsed .brand-text, .shell.collapsed .sidebar nav span, .shell.collapsed .collapse-btn span { display: none; }
.shell.collapsed .collapse-btn .ico { transform: rotate(180deg); }
.shell.collapsed .sidebar nav a { justify-content: center; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--white); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.crumb { flex: 1; color: var(--ink-3); font-size: 13px; min-width: 0; }
.user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.uname { font-weight: 600; }
.role-badge { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--emerald-50); color: var(--green); font-weight: 600; }
.role-badge.admin { background: var(--gold-50); color: #6b4e1d; }
.menu-btn { display: none; background: none; border: 0; padding: 6px; cursor: pointer; color: var(--green); }
main { padding: 20px 24px 40px; flex: 1; outline: none; max-width: 1600px; width: 100%; }
.foot { padding: 12px 24px; font-size: 11px; color: var(--ink-3); }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }

/* Page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-3); font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Buttons */
.btn, .btn-ghost, .btn-danger, .btn-gold { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; font-size: 13px; border-radius: 6px; padding: 8px 14px; cursor: pointer; text-decoration: none; border: 1px solid transparent; line-height: 1.2; }
.btn { background: var(--emerald); color: #fff; }
.btn:hover { background: var(--green); color: #fff; }
.btn-gold { background: var(--gold); color: #fff; }
.btn-ghost { background: var(--white); color: var(--green); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--emerald); color: var(--green); }
.btn-danger { background: var(--white); color: var(--red); border-color: #e3c2c2; }
.btn-danger:hover { background: var(--red-50); }
.sm { padding: 5px 10px; font-size: 12px; }
form.inline { display: inline; margin: 0; }

/* Cards */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.grid.k4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.kpi { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .label { font-size: 11.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 21px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; color: var(--ink); }
.kpi .sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.kpi.accent { border-top: 3px solid var(--emerald); }
.kpi.gold { border-top: 3px solid var(--gold); }
.kpi.warn { border-top: 3px solid #c58b2a; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0 10px; }
.section-title h2 { margin: 0; }
.note { background: var(--gold-50); border: 1px solid #ead9bb; color: #5a4419; border-radius: var(--radius); padding: 10px 12px; font-size: 13px; }
.note.info { background: var(--blue-50); border-color: #cddcec; color: #20405f; }

/* Filters */
.filters { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 14px; }
.filters label { display: grid; gap: 3px; font-size: 11.5px; color: var(--ink-3); font-weight: 600; }
.filters .period-label { margin-left: auto; font-size: 12.5px; color: var(--ink-2); align-self: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg a { padding: 7px 10px; font-size: 12.5px; text-decoration: none; color: var(--ink-2); background: var(--white); border-right: 1px solid var(--line); }
.seg a:last-child { border-right: 0; }
.seg a.on { background: var(--green); color: #fff; }

/* Forms */
input, select, textarea { font: inherit; font-size: 13.5px; color: var(--ink); background: #fff; border: 1px solid #c9d4cf; border-radius: 6px; padding: 7px 9px; min-height: 34px; }
input:focus, select:focus, textarea:focus { border-color: var(--emerald); outline: 2px solid rgba(52,125,99,.25); outline-offset: 0; }
textarea { min-height: 70px; resize: vertical; width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 16px; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 11.5px; color: var(--ink-3); font-weight: 400; }
.field.full { grid-column: 1 / -1; }
.field input, .field select { width: 100%; }
.field.err input, .field.err select { border-color: var(--red); }
.field .error { color: var(--red); font-size: 12px; }
.req::after { content: " *"; color: var(--red); }
.form-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.preview-box { background: var(--emerald-50); border: 1px solid #cfe3d9; border-radius: var(--radius); padding: 12px; }
.preview-box dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px 14px; margin: 0; }
.preview-box dt { font-size: 11px; color: var(--ink-3); text-transform: uppercase; }
.preview-box dd { margin: 2px 0 0; font-weight: 650; font-variant-numeric: tabular-nums; font-size: 15px; }
.preview-box dl > div { background: rgba(255,255,255,.6); border-radius: 6px; padding: 6px 8px; }
.preview-box dl > div.hl { background: var(--gold-50); box-shadow: inset 0 0 0 1px #ead9bb; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 6px 10px; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: middle; }
table.data th { background: #f0f4f2; color: var(--ink-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; font-weight: 650; position: sticky; top: 0; white-space: nowrap; }
table.data tbody tr:hover { background: #fafcfb; }
table.data tfoot td { font-weight: 700; background: #f3f7f5; border-top: 2px solid var(--line); }
table.data tr.void td { color: var(--ink-3); text-decoration: line-through; }
table.data td.actions-cell { white-space: nowrap; text-align: right; }
.empty { padding: 28px; text-align: center; color: var(--ink-3); }
.empty strong { display: block; color: var(--ink-2); margin-bottom: 4px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--ink-3); font-size: 12.5px; }
dl.kv dd { margin: 0; }

/* Status pills */
.pill { display: inline-block; font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.pill.pagada { background: var(--emerald-50); color: var(--green); }
.pill.parcial { background: var(--amber-50); color: var(--amber); }
.pill.pendiente { background: var(--blue-50); color: var(--blue); }
.pill.sin_facturar, .pill.sin_operaciones { background: #eceff0; color: #4d5659; }
.pill.anulada, .pill.void { background: var(--red-50); color: var(--red); }
.pill.operativo { background: var(--blue-50); color: var(--blue); }
.pill.equipamiento { background: var(--gold-50); color: #6b4e1d; }
.pill.error { background: var(--red-50); color: var(--red); }
.pill.warning { background: var(--amber-50); color: var(--amber); }
.pill.info { background: var(--blue-50); color: var(--blue); }

/* Flash */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13.5px; border: 1px solid; }
.flash.ok { background: var(--emerald-50); border-color: #bcd9cb; color: var(--green); }
.flash.error { background: var(--red-50); border-color: #ebc4c4; color: #7a1f1f; }

/* Charts */
.chart { width: 100%; min-height: 220px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart text { font-size: 10.5px; fill: var(--ink-3); font-family: var(--font); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.sw-langosta { background: var(--emerald); } .sw-pulpo { background: var(--gold); } .sw-other { background: var(--blue); }
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 110px; gap: 10px; align-items: center; font-size: 12.5px; }
.bar-track { background: var(--line-2); border-radius: 4px; height: 12px; overflow: hidden; }
.bar-track svg { display: block; width: 100%; height: 12px; }

/* Docs */
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.doc { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; overflow: hidden; display: flex; flex-direction: column; }
.doc .thumb { height: 110px; background: var(--line-2); display: flex; align-items: center; justify-content: center; color: var(--ink-3); font-weight: 700; }
.doc .thumb img { width: 100%; height: 110px; object-fit: cover; }
.doc .meta { padding: 6px 8px; font-size: 12px; word-break: break-word; }
.doc .meta a { text-decoration: none; }
.viewer { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; text-align: center; }
.viewer img { max-width: 100%; max-height: 75vh; }
.viewer iframe { width: 100%; height: 78vh; border: 0; }
.thumb-sm { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); vertical-align: middle; }

/* Dialog */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; max-width: 460px; width: calc(100% - 32px); box-shadow: 0 20px 50px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(10,25,20,.45); }
dialog .dlg { padding: 18px; }
dialog h2 { margin-bottom: 6px; }
details.box { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
details.box summary { cursor: pointer; font-weight: 600; color: var(--green); }

/* Login */
body.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #f5f7f6 0%, #e7eeeb 100%); padding: 20px; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: 100%; max-width: 380px; box-shadow: 0 10px 30px rgba(36,72,61,.08); }
.login-card img { display: block; margin: 0 auto 10px; width: 190px; height: auto; }
.login-card h1 { text-align: center; font-size: 15px; color: var(--ink-3); font-weight: 500; margin-bottom: 18px; }
.login-card .field { margin-bottom: 12px; }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; }

/* Responsive */
@media (max-width: 900px) {
  .shell, .shell.collapsed { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .shell.open .sidebar { transform: none; }
  .shell.collapsed .brand-text, .shell.collapsed .sidebar nav span { display: block; }
  .collapse-btn { display: none; }
  .menu-btn { display: inline-flex; }
  main { padding: 14px 12px 32px; }
  .topbar { padding: 8px 12px; }
  .uname, .link-sm { display: none; }
  .bar-row { grid-template-columns: 90px 1fr 90px; }
  .grid.c2 { grid-template-columns: 1fr; }
}
@media print {
  .sidebar, .topbar, .filters, .actions, .foot { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Utilidades (sin estilos inline: CSP style-src 'self') */
.mt0 { margin-top: 0 !important; } .mt10 { margin-top: 10px; } .mt14 { margin-top: 14px; } .mt20 { margin-top: 20px; }
.mb0 { margin-bottom: 0; } .w100 { width: 100%; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.error { color: var(--red); }
