:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --border: #e4e7ec;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #15803d;
  --danger: #dc2626;
  --warning: #d97706;
  --shadow-sm: 0 4px 14px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 12px 30px rgba(15, 23, 42, 0.09);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

body,
input,
select,
button {
  -webkit-font-smoothing: antialiased;
}

header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(17, 24, 39, 0.96);
  color: white;
  padding: 16px 22px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.05);
  backdrop-filter: blur(12px);
}

header h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 28px);
  font-weight: 800;
  letter-spacing: -0.02em;
}

header p {
  margin: 4px 0 0;
  color: #cbd5e1;
  font-size: 14px;
}

main {
  width: min(1180px, calc(100% - 24px));
  margin: 28px auto 50px;
}

section {
  background: var(--surface);
  padding: 22px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 38px);
  line-height: 1.15;
  letter-spacing: -0.03em;
}

h2 {
  font-size: clamp(20px, 3vw, 26px);
  margin-bottom: 16px;
}

h3 {
  font-size: 18px;
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  font-size: 14px;
  color: #344054;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 11px 13px;
  border: 1px solid #d0d5dd;
  border-radius: 10px;
  background: white;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input:focus,
select:focus {
  border-color: #84adff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.10);
}

input[readonly] {
  background: #f8fafc;
  color: #475467;
}

button {
  appearance: none;
  border: none;
  border-radius: 10px;
  min-height: 44px;
  padding: 11px 16px;
  background: var(--primary);
  color: white;
  font-size: 15px;
  font-weight: 750;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.18);
}

button:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.25);
  outline-offset: 2px;
}

form {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 14px 18px;
  align-items: center;
}

form button {
  grid-column: 1 / -1;
}

#cancelEditButton {
  background: #475467;
  box-shadow: none;
}

#cancelEditButton:hover {
  background: #344054;
}

#generatePdf,
#clearInventoryFilter,
#exportHistoryPdf,
#clearHistory,
#addInvoiceItem,
#generateInvoicePdf {
  margin-top: 8px;
}

#clearInventoryFilter,
#clearHistory {
  background: #475467;
  box-shadow: none;
}

#clearInventoryFilter:hover,
#clearHistory:hover {
  background: #344054;
}

#generateInvoicePdf {
  background: #15803d;
  box-shadow: 0 4px 12px rgba(21, 128, 61, 0.18);
}

#generateInvoicePdf:hover {
  background: #166534;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 14px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid #eef2f6;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  background: #f8fafc;
  color: #475467;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td {
  font-size: 14px;
}

tbody tr:hover {
  background: #fbfdff;
}

tbody tr:last-child td {
  border-bottom: none;
}

td button {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 13px;
  box-shadow: none;
}

strong {
  color: #111827;
}

.inventory-search {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) minmax(260px, 2fr);
  gap: 14px;
  align-items: end;
  margin: 18px 0 10px;
}

.search-option,
.search-box {
  min-width: 0;
}

#dateSearchBox {
  display: grid !important;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

#dateSearchBox[style*="display: none"] {
  display: none !important;
}

/* =========================
   DASHBOARD
========================= */

.dashboard-page {
  min-height: auto;
  padding: 24px 0 6px;
  background: transparent;
  border: none;
  box-shadow: none;
}

.dashboard-header {
  text-align: left;
  margin-bottom: 24px;
}

.dashboard-header h1 {
  margin-bottom: 6px;
}

.dashboard-header p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.dashboard-card {
  min-height: 180px;
  padding: 24px 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  color: var(--text);
  text-align: left;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
}

.dashboard-card:hover {
  background: #ffffff;
  border-color: #cbd5e1;
  box-shadow: var(--shadow-md);
  transform: translateY(-3px);
}

.dashboard-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 16px;
  border-radius: 14px;
  background: var(--primary-soft);
  font-size: 28px;
}

.dashboard-card h2 {
  margin: 0 0 5px;
  color: var(--text);
  font-size: 21px;
}

.dashboard-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* =========================
   SECCIONES
========================= */

.app-section {
  display: none;
  min-height: auto;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.app-section > h1 {
  margin: 4px 0 20px;
}

.btn-volver {
  margin-bottom: 18px;
  background: #111827;
  box-shadow: none;
}

.btn-volver:hover {
  background: #0f172a;
}

/* =========================
   RESUMEN
========================= */

.resumen-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.resumen-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.resumen-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.resumen-card strong {
  color: var(--text);
  font-size: clamp(24px, 4vw, 30px);
  letter-spacing: -0.03em;
}

/* =========================
   FACTURAS
========================= */

.invoice-header-fields {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(260px, 1.2fr);
  gap: 16px;
}

.invoice-product-results {
  display: none;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: white;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  max-height: 320px;
  overflow-y: auto;
}

.invoice-product-option {
  width: 100%;
  min-height: auto;
  border-radius: 0;
  background: white;
  color: var(--text);
  box-shadow: none;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 15px;
  text-align: left;
  border-bottom: 1px solid #eef2f6;
}

.invoice-product-option:hover {
  background: #f8fafc;
  color: var(--text);
  transform: none;
}

.invoice-product-option:last-child {
  border-bottom: none;
}

.invoice-product-option span {
  color: var(--muted);
  font-size: 13px;
}

#selectedInvoiceProduct {
  margin-top: 16px;
  padding: 18px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid var(--border);
}

#selectedInvoiceProduct p {
  margin-bottom: 6px;
}

#invoiceTotal {
  font-size: 1.25em;
}

/* =========================
   HISTORIAL / LOG
========================= */

#historial > p,
#log > p {
  color: var(--muted);
}

/* =========================
   TABLET
========================= */

@media (max-width: 900px) {
  main {
    width: min(100% - 18px, 1000px);
    margin-top: 20px;
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .resumen-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  form {
    grid-template-columns: 150px minmax(0, 1fr);
  }

  .inventory-search {
    grid-template-columns: 1fr;
  }

  .invoice-header-fields {
    grid-template-columns: 1fr;
  }

  section {
    padding: 18px;
  }
}

/* =========================
   CELULAR
========================= */

@media (max-width: 640px) {
  header {
    padding: 14px 16px;
  }

  main {
    width: calc(100% - 12px);
    margin: 12px auto 28px;
  }

  section {
    padding: 15px;
    margin-bottom: 14px;
    border-radius: 16px;
  }

  .dashboard-page {
    padding-top: 8px;
  }

  .dashboard-header {
    margin-bottom: 16px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .dashboard-card {
    min-height: 145px;
    padding: 17px 14px;
    border-radius: 15px;
  }

  .dashboard-icon {
    width: 44px;
    height: 44px;
    font-size: 24px;
    margin-bottom: 12px;
    border-radius: 12px;
  }

  .dashboard-card h2 {
    font-size: 17px;
  }

  .dashboard-card p {
    font-size: 12px;
    line-height: 1.35;
  }

  form {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  form label {
    margin-top: 6px;
  }

  form button {
    grid-column: auto;
  }

  input,
  select,
  button {
    font-size: 16px;
  }

  .inventory-search,
  .invoice-header-fields,
  .resumen-grid {
    grid-template-columns: 1fr;
  }

  #dateSearchBox {
    grid-template-columns: 1fr;
  }

  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    border-radius: 12px;
  }

  th,
  td {
    padding: 10px 12px;
  }

  .app-section > h1 {
    margin-top: 0;
  }

  .btn-volver {
    width: auto;
  }

  #generatePdf,
  #clearInventoryFilter,
  #exportHistoryPdf,
  #clearHistory,
  #generateInvoicePdf {
    width: 100%;
  }

  #selectedInvoiceProduct {
    padding: 14px;
  }
}

/* =========================
   PANTALLAS MUY PEQUEÑAS
========================= */

@media (max-width: 420px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-card {
    min-height: 118px;
  }

  .dashboard-card p {
    display: block;
  }
}
