:root {
  --paper:       #F1F5FA;
  --plate:       #FFFFFF;
  --ink:         #0B2545;
  --muted:       #5C7999;
  --rule:        #D6E1EF;
  --signal:      #1364DA;
  --signal-deep: #0A3F8F;
  --signal-wash: #E7F0FC;

  --ok:      #0E7C66;
  --warn:    #B7791F;
  --down:    #C2410C;
  --retired: #64748B;

  --sans: 'IBM Plex Sans', system-ui, sans-serif;
  --cond: 'IBM Plex Sans Condensed', 'IBM Plex Sans', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;

  --r: 3px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

.lbl {
  font-family: var(--cond);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* =================== LOGIN =================== */
#login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-plate {
  width: 100%; max-width: 380px; background: var(--plate);
  border: 1px solid var(--rule); border-radius: var(--r); padding: 36px 32px 32px; position: relative;
}
.brand { font-family: var(--cond); font-weight: 700; font-size: 26px; letter-spacing: -.01em; text-transform: uppercase; }
.brand span { color: var(--signal); }
.brand-sub { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 2px; margin-bottom: 28px; }

.field { margin-bottom: 16px; }
.field .lbl { display: block; margin-bottom: 5px; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 8px 10px; background: var(--plate);
  border: 1px solid var(--rule); border-radius: var(--r);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-wash);
}
input.code { font-family: var(--mono); letter-spacing: .3em; text-align: center; font-size: 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border: 1px solid transparent; border-radius: var(--r);
  font-weight: 500; font-size: 13px; transition: background .12s, border-color .12s;
}
.btn-primary { background: var(--signal); color: #fff; }
.btn-primary:hover { background: var(--signal-deep); }
.btn-ghost { background: transparent; border-color: var(--rule); color: var(--ink); }
.btn-ghost:hover { background: var(--paper); }
.btn-danger { background: transparent; border-color: #E9C0AE; color: var(--down); }
.btn-danger:hover { background: #FDF1EC; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.msg { padding: 8px 10px; border-radius: var(--r); font-size: 13px; margin-bottom: 14px; }
.msg-error { background: #FDF1EC; color: var(--down); border: 1px solid #F3D5C7; }
.msg-ok { background: #E9F7F2; color: var(--ok); border: 1px solid #BFE6D8; }

.hint { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--rule); font-size: 12px; color: var(--muted); }
.hint code { font-family: var(--mono); font-size: 11px; color: var(--ink); }

/* =================== APP SHELL =================== */
#app { display: none; min-height: 100vh; flex-direction: column; }
#app.on { display: flex; }

header.top {
  display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 52px;
  background: var(--plate); border-bottom: 1px solid var(--rule); flex-shrink: 0;
}
header.top .brand { font-size: 17px; }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); }
.who b { color: var(--ink); font-weight: 600; }
.rol-tag {
  font-family: var(--mono); font-size: 10px; padding: 2px 6px;
  background: var(--signal-wash); color: var(--signal-deep); border-radius: var(--r);
}
.link { background: none; border: none; color: var(--signal); font-size: 12px; text-decoration: underline; padding: 0; }

.shell { display: flex; flex: 1; min-height: 0; }

/* ---- Navegación lateral por recurso ---- */
nav.side {
  width: 190px; flex-shrink: 0; background: var(--plate); border-right: 1px solid var(--rule);
  padding: 16px 10px; overflow-y: auto;
}
nav.side button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; margin-bottom: 2px;
  background: none; border: none; border-radius: var(--r); font-size: 13.5px; color: var(--ink);
}
nav.side button:hover { background: var(--paper); }
nav.side button[aria-current=true] { background: var(--signal-wash); color: var(--signal-deep); font-weight: 600; }

main.work { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 20px; gap: 14px; overflow-y: auto; }
.view { display: none; flex-direction: column; gap: 14px; flex: 1; min-height: 0; }
.view.on { display: flex; }

.work-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.work-head h1 { font-family: var(--cond); font-size: 22px; text-transform: uppercase; letter-spacing: .01em; }
.count { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.search { flex: 1; max-width: 300px; margin-left: auto; }
.search input { font-size: 13px; }

/* ---- Tabla ---- */
aside.rail { width: 220px; flex-shrink: 0; background: var(--plate); border-right: 1px solid var(--rule); padding: 20px 16px; overflow-y: auto; }
.rail h2 { font-family: var(--cond); font-size: 12px; letter-spacing: .09em; text-transform: uppercase; color: var(--ink); margin-bottom: 14px; }
.rail .field { margin-bottom: 13px; }

.states { display: flex; flex-direction: column; gap: 1px; }
.state-btn {
  display: flex; align-items: center; gap: 8px; padding: 5px 7px; background: none; border: none;
  border-radius: var(--r); text-align: left; font-size: 13px; color: var(--ink); width: 100%;
}
.state-btn:hover { background: var(--paper); }
.state-btn[aria-pressed=true] { background: var(--signal-wash); font-weight: 600; }
.swatch { width: 8px; height: 8px; border-radius: 1px; flex-shrink: 0; display: inline-block; }
.state-btn .n { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--muted); }

.sw-Operativo, .sw-completado, .sw-verificado         { background: var(--ok); }
.sw-En-mantenimiento, .sw-programado, .sw-pendiente   { background: var(--warn); }
.sw-Fuera-de-servicio, .sw-en_progreso, .sw-expirado  { background: var(--down); }
.sw-De-baja, .sw-borrador                             { background: var(--retired); }
.sw-todos { background: var(--rule); }

.table-wrap { flex: 1; background: var(--plate); border: 1px solid var(--rule); border-radius: var(--r); overflow: auto; min-height: 0; }
table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky; top: 0; background: var(--plate); text-align: left; padding: 9px 12px;
  border-bottom: 1px solid var(--rule); font-family: var(--cond); font-size: 11px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted); white-space: nowrap; z-index: 1;
}
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
tbody tr:hover { background: var(--paper); }
tbody tr[aria-selected=true] { background: var(--signal-wash); }
tbody tr:last-child td { border-bottom: none; }

.cell-code { font-family: var(--mono); font-size: 12px; font-weight: 500; white-space: nowrap; }
.cell-name b { font-weight: 600; }
.cell-name small { display: block; color: var(--muted); font-size: 12px; }
.cell-loc { color: var(--muted); font-size: 12px; }
.state-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; white-space: nowrap; }

.row-acts { display: flex; gap: 4px; justify-content: flex-end; }
.icon-btn { padding: 3px 7px; background: none; border: 1px solid transparent; border-radius: var(--r); font-size: 12px; color: var(--muted); }
.icon-btn:hover { border-color: var(--rule); color: var(--ink); background: var(--plate); }
.icon-btn.del:hover { color: var(--down); border-color: #E9C0AE; }

.empty { padding: 56px 24px; text-align: center; }
.empty p { color: var(--muted); margin-bottom: 14px; }

.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
.pager span { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* ---- Placa (detalle) ---- */
.drawer { width: 360px; flex-shrink: 0; background: var(--plate); border-left: 1px solid var(--rule); overflow-y: auto; display: none; }
.drawer.on { display: block; }
.drawer-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--rule); }
.drawer-head .lbl { flex: 1; }
.x-btn { background: none; border: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 6px; }
.x-btn:hover { color: var(--ink); }
.plate-body { padding: 16px; }

.nameplate { position: relative; border: 1.5px solid var(--ink); border-radius: var(--r); padding: 16px 14px 12px; background: var(--paper); }
.nameplate::before, .nameplate::after, .nameplate > .rivet-l, .nameplate > .rivet-r {
  content: ''; position: absolute; width: 4px; height: 4px; border-radius: 50%; background: var(--muted); opacity: .5;
}
.nameplate::before { top: 5px; left: 5px; }
.nameplate::after { top: 5px; right: 5px; }
.nameplate > .rivet-l { bottom: 5px; left: 5px; }
.nameplate > .rivet-r { bottom: 5px; right: 5px; }

.np-brand { font-family: var(--cond); font-size: 19px; font-weight: 700; text-transform: uppercase; line-height: 1.15; }
.np-model { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.np-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 12px; }
.np-grid .full { grid-column: 1 / -1; }
.np-cell .lbl { display: block; font-size: 10px; margin-bottom: 1px; }
.np-cell .v { font-family: var(--mono); font-size: 12.5px; word-break: break-word; }
.np-cell .v.na { color: var(--muted); }
.np-rule { border: none; border-top: 1px solid var(--rule); margin: 12px 0; }

.drawer-sect { margin-top: 22px; }
.drawer-sect > .lbl { display: block; margin-bottom: 9px; }
.hist { display: flex; flex-direction: column; gap: 1px; }
.hist-row { display: flex; align-items: baseline; gap: 9px; padding: 7px 0; border-bottom: 1px solid var(--rule); font-size: 12.5px; }
.hist-row .d { font-family: var(--mono); font-size: 11.5px; color: var(--muted); flex-shrink: 0; }
.hist-row .t { flex: 1; }
.hist-row .s { font-family: var(--cond); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.hist-none { font-size: 12.5px; color: var(--muted); font-style: italic; }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--r); border: 1px solid var(--rule); }

.drawer-acts { display: flex; gap: 8px; margin-top: 22px; flex-wrap: wrap; }
.drawer-acts .btn { flex: 1; }

/* =================== LISTA SIMPLE (catálogos) =================== */
.simple-list { display: flex; flex-direction: column; gap: 1px; background: var(--plate); border: 1px solid var(--rule); border-radius: var(--r); overflow: hidden; }
.simple-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--rule); }
.simple-row:last-child { border-bottom: none; }
.simple-row .t { flex: 1; }
.simple-row .t b { font-weight: 600; }
.simple-row .t small { display: block; color: var(--muted); font-size: 12px; }

/* =================== MODAL =================== */
.veil { position: fixed; inset: 0; background: rgba(11, 37, 69, .35); display: none; place-items: center; padding: 24px; z-index: 50; }
.veil.on { display: grid; }
.modal { background: var(--plate); border-radius: var(--r); width: 100%; max-width: 620px; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(11, 37, 69, .18); }
.modal.narrow { max-width: 420px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--rule); display: flex; align-items: center; }
.modal-head h3 { font-family: var(--cond); font-size: 17px; text-transform: uppercase; flex: 1; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--rule); display: flex; gap: 8px; justify-content: flex-end; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid2 .full { grid-column: 1 / -1; }

fieldset { border: none; margin-bottom: 6px; }
legend {
  font-family: var(--cond); font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--signal-deep);
  padding-bottom: 8px; margin-bottom: 10px; border-bottom: 1px solid var(--rule); width: 100%;
}
.req { color: var(--down); }

.confirm-txt { padding: 20px; font-size: 13.5px; }
.confirm-txt b { font-family: var(--mono); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--ink); color: #fff; padding: 9px 16px; border-radius: var(--r); font-size: 13px;
  z-index: 90; opacity: 0; transition: transform .2s, opacity .2s; pointer-events: none; max-width: 90vw;
}
.toast.on { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.bad { background: var(--down); }

.loading { padding: 40px; text-align: center; color: var(--muted); font-size: 13px; }

.code-display { text-align: center; padding: 18px 0; }
.code-display .big { font-family: var(--mono); font-size: 34px; font-weight: 600; letter-spacing: .3em; color: var(--signal-deep); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  nav.side { width: auto; border-right: none; border-bottom: 1px solid var(--rule); display: flex; overflow-x: auto; gap: 4px; }
  nav.side button { width: auto; white-space: nowrap; }
  aside.rail { width: auto; border-right: none; border-bottom: 1px solid var(--rule); }
  .rail .states { flex-direction: row; flex-wrap: wrap; }
  .state-btn { width: auto; }
  .state-btn .n { margin-left: 4px; }
  .drawer { width: auto; border-left: none; border-top: 1px solid var(--rule); }
  .grid2 { grid-template-columns: 1fr; }
  .search { max-width: none; margin-left: 0; flex-basis: 100%; }
}
