/* ==========================================================================
   ERP - hoja de estilos unica
   ========================================================================== */
:root {
  --bg:        #f4f2ef;
  --surface:   #ffffff;
  --surface-2: #faf8f6;
  --line:      #e3ded8;
  --line-soft: #efeae4;
  --ink:       #23201d;
  --ink-2:     #635b53;
  --ink-3:     #928980;

  --brand:     #7b4b28;
  --brand-2:   #a9683a;
  --brand-ink: #3b2a20;

  --ok:        #1f7a4d;
  --ok-bg:     #e6f4ec;
  --warn:      #9a6410;
  --warn-bg:   #fdf1dc;
  --bad:       #a52b28;
  --bad-bg:    #fbe9e8;
  --info:      #245c8c;
  --info-bg:   #e6eff7;

  --radius:    10px;
  --shadow:    0 1px 2px rgba(35,32,29,.06), 0 4px 14px rgba(35,32,29,.05);
  --sidebar:   232px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1,h2,h3,h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------- arranque -- */
.booting { display: grid; place-items: center; height: 100vh; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- login --- */
/* Dos paneles: la marca a la izquierda, el formulario a la derecha. */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 24px; }

.auth {
  width: 100%; max-width: 900px; background: var(--surface);
  border-radius: 20px; overflow: hidden; box-shadow: 0 24px 70px rgba(35,32,29,.16);
  display: grid; grid-template-columns: 1fr 1fr;
}

.auth .panel {
  background: linear-gradient(150deg, var(--brand-ink) 0%, var(--brand-deep) 100%);
  color: var(--sidebar-on); padding: 44px 38px; display: flex; flex-direction: column;
  position: relative; overflow: hidden;
}
/* Halo del color de la marca, para que el panel no sea un bloque plano. */
.auth .panel::after {
  content: ''; position: absolute; width: 320px; height: 320px; border-radius: 50%;
  background: var(--brand); opacity: .28; filter: blur(70px);
  right: -90px; bottom: -110px;
}
.auth .panel > * { position: relative; z-index: 1; }
.auth .panel .mark { margin-bottom: 26px; }
.auth .panel .mark img { max-height: 46px; max-width: 190px; object-fit: contain; }
.auth .panel h2 { font-size: 26px; line-height: 1.25; letter-spacing: -.02em; margin-bottom: 10px; }
.auth .panel p { font-size: 14px; opacity: .78; margin: 0; line-height: 1.6; }
.auth .panel ul { list-style: none; padding: 0; margin: auto 0 0; font-size: 13.5px; }
.auth .panel li { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; opacity: .9; }
.auth .panel li .t { flex: 1; }
.auth .panel li b { display: block; font-weight: 600; }
.auth .panel li small { opacity: .7; }

.auth .form { padding: 44px 38px; display: flex; flex-direction: column; justify-content: center; }
.auth .form h1 { font-size: 22px; margin-bottom: 4px; }
.auth .form .sub { color: var(--ink-3); font-size: 13.5px; margin: 0 0 24px; }
.auth .form .field { margin-bottom: 15px; }
.auth .form input { padding: 12px 13px; border-radius: 10px; font-size: 15px; }
.auth .form .btn { width: 100%; justify-content: center; padding: 13px; font-size: 15px; margin-top: 6px; }
.auth .form .pie { margin-top: 22px; font-size: 12.5px; color: var(--ink-3); text-align: center; }

@media (max-width: 760px) {
  .auth { grid-template-columns: 1fr; max-width: 440px; }
  .auth .panel { padding: 28px; }
  .auth .panel h2 { font-size: 21px; }
  .auth .panel ul, .auth .panel p { display: none; }
  .auth .panel .mark { margin-bottom: 14px; }
  .auth .form { padding: 28px; }
}

/* --------------------------------------------------------------- layout --- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--brand-ink); color: #e9e2da;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  padding: 18px 18px 14px; display: flex; gap: 10px; align-items: center;
  border-bottom: 1px solid rgba(255,255,255,.09);
}
.sidebar .brand .mark { font-size: 22px; }
.sidebar .brand .name { font-weight: 650; font-size: 14px; line-height: 1.2; }
.sidebar .brand .name small { display: block; font-weight: 400; font-size: 11px; color: #b6a99c; }

.nav { padding: 10px 10px; overflow-y: auto; flex: 1; }
.nav .group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: #9a8b7d; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: #ddd3c9; font-size: 13.5px; text-decoration: none; margin-bottom: 1px;
}
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav a.active { background: var(--brand); color: var(--brand-on); font-weight: 600; }
.nav a .ico { width: 18px; text-align: center; opacity: .95; }
.nav a .pill {
  margin-left: auto; background: rgba(255,255,255,.16); border-radius: 20px;
  padding: 1px 7px; font-size: 11px; font-weight: 600;
}
.nav a.active .pill { background: rgba(0,0,0,.22); }

.sidebar .who {
  border-top: 1px solid rgba(255,255,255,.09); padding: 12px 14px; font-size: 12px;
}
.sidebar .who .n { font-weight: 600; color: #fff; }
.sidebar .who .r { color: #b6a99c; text-transform: capitalize; }
.sidebar .who .acts { margin-top: 8px; display: flex; gap: 8px; }
.sidebar .who a { color: #c9bcae; font-size: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 14px 24px; display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; }
.topbar .sub { color: var(--ink-3); font-size: 12.5px; }
.topbar .spacer { flex: 1; }

.content { padding: 20px 24px 60px; }

/* ---------------------------------------------------------------- cards --- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card > header {
  padding: 15px 18px; border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 10px;
}
.card > header h3 { font-size: 14.5px; }
.card > header .spacer { flex: 1; }
.card .body { padding: 18px; }
.card .body.tight { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.k2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.k3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.k4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 1100px) { .grid.k4 { grid-template-columns: repeat(2,minmax(0,1fr)); }
                             .grid.k3 { grid-template-columns: repeat(1,minmax(0,1fr)); } }
@media (max-width: 780px)  { .grid.k2, .grid.k4 { grid-template-columns: 1fr; }
                             .shell { grid-template-columns: 1fr; }
                             .sidebar { position: static; height: auto; } }

/* ------------------------------------------------------------------ kpi --- */
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 18px; box-shadow: var(--shadow); position: relative;
  display: flex; gap: 13px; align-items: flex-start; transition: box-shadow .15s, transform .15s;
}
/* El icono va en una pastilla del color del estado: da lectura de un vistazo. */
.kpi .ico {
  flex: 0 0 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  font-size: 19px; background: var(--brand-soft); color: var(--brand);
}
.kpi .txt { min-width: 0; flex: 1; }
.kpi .label { font-size: 12px; color: var(--ink-3); font-weight: 500; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 3px; letter-spacing: -.025em;
  line-height: 1.15; }
.kpi .foot { font-size: 12px; color: var(--ink-2); margin-top: 5px; }

.kpi.accent-ok    .ico { background: var(--ok-bg);   color: var(--ok); }
.kpi.accent-bad   .ico { background: var(--bad-bg);  color: var(--bad); }
.kpi.accent-warn  .ico { background: var(--warn-bg); color: var(--warn); }
.kpi.accent-info  .ico { background: var(--info-bg); color: var(--info); }
.kpi.accent-brand .ico { background: var(--brand-soft); color: var(--brand); }

.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { box-shadow: 0 6px 20px rgba(35,32,29,.10); transform: translateY(-1px); }

/* --------------------------------------------------------------- tablas --- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; padding: 9px 12px; background: var(--surface-2);
  border-bottom: 1px solid var(--line); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); white-space: nowrap;
}
table.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr.clickable { cursor: pointer; }
table.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl tfoot td {
  padding: 10px 12px; font-weight: 650; background: var(--surface-2);
  border-top: 2px solid var(--line);
}
table.tbl.compact td, table.tbl.compact th { padding: 6px 10px; }
.empty { padding: 34px 16px; text-align: center; color: var(--ink-3); }
.empty .big { font-size: 30px; display: block; margin-bottom: 8px; opacity: .5; }

/* --------------------------------------------------------------- badges --- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px;
  font-weight: 600; white-space: nowrap; line-height: 1.5;
}
.badge.ok   { background: var(--ok-bg);   color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad  { background: var(--bad-bg);  color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.mute { background: var(--line-soft); color: var(--ink-2); }

/* --------------------------------------------------------------- inputs --- */
.field { margin-bottom: 13px; }
.field > label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.field .hint { font-size: 11.5px; color: var(--ink-3); margin-top: 3px; }

input[type=text], input[type=password], input[type=date], input[type=number],
input[type=email], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); font: inherit; font-size: 13.5px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(169,104,58,.14);
}
input[readonly] { background: var(--surface-2); color: var(--ink-2); }
textarea { resize: vertical; min-height: 62px; }
input.num, td input.num { text-align: right; font-variant-numeric: tabular-nums; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }
.check input { width: auto; margin: 0; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.segmented button {
  border: 0; background: #fff; padding: 7px 14px; font: inherit; font-size: 13px;
  cursor: pointer; color: var(--ink-2); border-right: 1px solid var(--line);
}
.segmented button:last-child { border-right: 0; }
.segmented button.on { background: var(--brand); color: #fff; font-weight: 600; }

/* --------------------------------------------------------------- botones --- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
  font: inherit; font-size: 13.5px; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line-soft); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 14px; }
.toolbar .field { margin-bottom: 0; }
.toolbar .spacer { flex: 1; }
.toolbar .f-sm { width: 150px; }
.toolbar .f-md { width: 210px; }

/* --------------------------------------------------------------- modales --- */
.overlay {
  position: fixed; inset: 0; background: rgba(35,32,29,.45); backdrop-filter: blur(2px);
  display: grid; place-items: start center; padding: 30px 16px; overflow-y: auto; z-index: 100;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px;
  box-shadow: 0 20px 60px rgba(0,0,0,.28); animation: pop .16s ease-out;
}
.modal.wide { max-width: 940px; }
.modal.xwide { max-width: 1180px; }
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } }
.modal > header {
  padding: 16px 20px; border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 10px;
}
.modal > header h3 { font-size: 16px; }
.modal > header .spacer { flex: 1; }
.modal .body { padding: 20px; }
.modal > footer {
  padding: 14px 20px; border-top: 1px solid var(--line-soft);
  display: flex; gap: 8px; justify-content: flex-end; background: var(--surface-2);
  border-radius: 0 0 14px 14px;
}
.modal > footer .spacer { flex: 1; }
.x-close { border: 0; background: transparent; font-size: 20px; line-height: 1; cursor: pointer; color: var(--ink-3); }

/* --------------------------------------------------------------- toasts --- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column;
  gap: 8px; z-index: 200; }
.toast {
  background: var(--brand-ink); color: #fff; padding: 11px 16px; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 13.5px; max-width: 380px;
  animation: slide .18s ease-out;
}
.toast.ok   { background: #1c6b45; }
.toast.bad  { background: #8e2622; }
.toast.warn { background: #8a5a12; max-width: 440px; line-height: 1.45; }
.aviso-punto { color: #b5791d; cursor: help; font-size: 13px; }
.aviso-caja { background: #fdf6e7; border: 1px solid #e6cf9d; color: #6b4a0f;
  border-radius: 8px; padding: 10px 12px; font-size: 12.5px; line-height: 1.5; margin-bottom: 12px; }
.aviso-caja ul { margin: 6px 0 0; padding-left: 18px; }
.aviso-caja li { margin: 3px 0; }
@keyframes slide { from { transform: translateX(16px); opacity: 0; } }

/* --------------------------------------------------------------- charts --- */
.chart { width: 100%; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.legend .it { display: flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }

.bars { display: flex; flex-direction: column; gap: 9px; }
.bars .row { display: grid; grid-template-columns: minmax(90px,1fr) 3fr auto; gap: 10px; align-items: center; font-size: 12.5px; }
.bars .row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.bars .row .track { background: var(--line-soft); border-radius: 5px; height: 16px; overflow: hidden; }
.bars .row .fill { height: 100%; border-radius: 5px; background: var(--brand-2); }
.bars .row .vl { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

/* ------------------------------------------------------------ utilidades --- */
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.mono  { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap{ white-space: nowrap; }
.strong{ font-weight: 650; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
.row-flex { display: flex; gap: 10px; align-items: center; }
.row-flex.wrap { flex-wrap: wrap; }
.mb0 { margin-bottom: 0; }
.mt12 { margin-top: 12px; }
.hr { height: 1px; background: var(--line-soft); margin: 14px 0; }
.notice { padding: 11px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 14px; }
.notice.info { background: var(--info-bg); color: var(--info); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad  { background: var(--bad-bg);  color: var(--bad); }

.dropzone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 26px; text-align: center;
  background: var(--surface-2); cursor: pointer; color: var(--ink-2);
}
.dropzone:hover, .dropzone.over { border-color: var(--brand-2); background: #fdf7f2; }
.dropzone .big { font-size: 30px; display: block; margin-bottom: 6px; }

.totbox { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.totbox .ln { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; }
.totbox .ln.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px;
  font-size: 16px; font-weight: 700; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button {
  border: 0; background: transparent; padding: 9px 14px; font: inherit; font-size: 13.5px;
  cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 650; }

@media print {
  .sidebar, .topbar .btn, .toolbar, .btn { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  .card { break-inside: avoid; box-shadow: none; }
}
