:root {
  --bg: radial-gradient(circle at top right, #fef1dc 0%, #f3f8ff 55%, #edf4ff 100%);
  --card: #ffffffde;
  --ink: #172535;
  --accent: #0d6f65;
  --accent-2: #ef9f39;
  --line: #d6e1ec;
  --muted: #59708a;
  --shadow: 0 12px 28px #0a172e1a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  color: var(--ink);
  background: var(--bg);
}
main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.login-card {
  margin-top: 6vh;
}
.brand {
  display: flex;
  justify-content: center;
}
.brand-logo-frame {
  width: 100%;
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid #d8e6f3;
  background: #fff;
}
.brand-logo {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center 44%;
}
.brand-login {
  margin-bottom: 12px;
}
.brand-logo-frame-login {
  max-width: 360px;
  aspect-ratio: 16 / 9;
}
.brand-sidebar {
  margin: 4px 0 10px;
}
.brand-logo-frame-sidebar {
  max-width: 200px;
  aspect-ratio: 16 / 9;
}
.app-shell {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 16px;
  align-items: start;
}
.sidebar {
  position: sticky;
  top: 16px;
  transition: padding 0.25s ease, min-height 0.25s ease;
}
.menu-toggle {
  width: 100%;
  border: 1px solid var(--line);
  background: #f3f8ff;
  color: var(--ink);
  font-weight: 700;
  margin-bottom: 10px;
}
.small {
  font-size: 13px;
  margin-bottom: 10px;
}
.tabs {
  display: grid;
  gap: 8px;
}
.tabs button {
  border: 1px solid var(--line);
  background: #fff;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  font-weight: 600;
}
.tabs .active {
  background: linear-gradient(135deg, #0d6f65 0%, #0ea082 100%);
  color: #fff;
  border-color: #0d6f65;
}

.app-shell.menu-collapsed {
  grid-template-columns: 76px 1fr;
}

.app-shell.menu-collapsed .sidebar {
  padding: 10px;
}

.app-shell.menu-collapsed .sidebar .brand,
.app-shell.menu-collapsed .sidebar #userBar,
.app-shell.menu-collapsed .sidebar .tabs {
  display: none;
}

.app-shell.menu-collapsed .menu-toggle {
  margin: 0;
  padding: 10px 6px;
}
.content-area {
  display: grid;
  gap: 14px;
}
.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
.kpi {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(150deg, #ffffff 0%, #f4f9ff 100%);
}
.kpi span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}
.kpi strong {
  font-size: 24px;
  line-height: 1;
}
.ingreso-toolbar {
  display: grid;
  grid-template-columns: 1.3fr 1.3fr auto auto;
  gap: 8px;
  margin-bottom: 10px;
}
.egreso-toolbar {
  display: grid;
  grid-template-columns: 1.3fr 1.3fr auto auto;
  gap: 8px;
  margin-bottom: 10px;
}
.excel-wrap {
  max-height: 56vh;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.grid-input {
  width: 100%;
  border: 1px solid #d4dfeb;
  border-radius: 8px;
  padding: 7px;
  font-size: 13px;
  background: #fff;
}
.btn-remove-row {
  border: 1px solid #f4c6c6;
  background: #fff4f4;
  color: #a03636;
  border-radius: 8px;
  padding: 7px 9px;
}
.readonly-cell {
  background: #f4f8fd;
  color: #36506b;
}
.status-chip {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.status-ok {
  background: #e8f8f3;
  color: #0f7f5e;
}
.status-error {
  background: #ffecec;
  color: #ae3f3f;
}
.status-idle {
  background: #edf3fa;
  color: #50657c;
}
form {
  display: grid;
  gap: 9px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
input, select, button {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
}
button { cursor: pointer; }
button[type='submit'] {
  background: var(--accent);
  color: white;
  border: none;
}
.row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.scan-btn {
  width: 60px;
  background: var(--accent-2);
  color: #fff;
  border: none;
}
.table-wrap { overflow: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border-bottom: 1px solid var(--line); padding: 9px; text-align: left; white-space: nowrap; }
th { background: #edf4fb; position: sticky; top: 0; }
.table-wrap table tr:hover td { background: #f8fbff; }
.hidden, .tab { display: none; }
.tab.active { display: block; }
.modal {
  position: fixed;
  inset: 0;
  background: #0008;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal.hidden {
  display: none;
}
.modal-content {
  background: #fff;
  width: min(520px, 100%);
  border-radius: 14px;
  padding: 14px;
}
.muted { color: var(--muted); font-size: 14px; }

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #172535;
  color: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  z-index: 999;
  box-shadow: var(--shadow);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .app-shell.menu-collapsed {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
  }
  .menu-toggle {
    display: none;
  }
  .brand-logo-frame-sidebar {
    max-width: 180px;
  }
  .tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .tabs button {
    text-align: center;
    padding: 8px;
    font-size: 13px;
  }
  .ingreso-toolbar {
    grid-template-columns: 1fr;
  }
  .egreso-toolbar {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page { size: letter landscape; margin: 10mm; }
}

/* Capacitor: durante escaneo nativo (community plugin) se transparenta el webview */
body.scanner-active { background: transparent !important; }
body.scanner-active > *:not(#scannerModal) { visibility: hidden; }
