:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2430;
  --text-muted: #6b7280;
  --sidebar-bg: #15182b;
  --sidebar-bg-active: #2a2f4d;
  --sidebar-text: #c7cad6;
  --sidebar-text-active: #ffffff;
  --accent: #6366f1;
  --accent-dark: #4f46e5;
  --accent-soft: #eef0ff;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------------- Login ---------------- */
.login-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 20% 20%, #272c52 0%, #11121f 70%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  background: var(--surface);
  padding: 2.25rem 2rem;
  border-radius: 16px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.login-box h1 { font-size: 1.25rem; margin: 0 0 0.1rem 0; letter-spacing: -0.01em; }
.login-box .hint { margin: 0 0 0.4rem 0; }
.login-box button { margin-top: 0.3rem; }

/* ---------------- Layout ---------------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 1.1rem 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem 1.2rem 0.6rem;
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
}
.brand-text { font-weight: 700; font-size: 1.02rem; color: white; letter-spacing: -0.01em; line-height: 1.2; }
.brand-logo { width: 36px; height: 36px; object-fit: contain; background: white; border-radius: 8px; padding: 2px; flex-shrink: 0; }

.nav-group-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6c7190;
  padding: 0.9rem 0.7rem 0.3rem 0.7rem;
  font-weight: 600;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--sidebar-text);
  border: none;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.86rem;
  margin: 1px 0;
}
.tab-btn .icon { font-size: 0.95rem; width: 1.1em; text-align: center; }
.tab-btn:hover { background: #1f2340; color: white; }
.tab-btn.active { background: var(--sidebar-bg-active); color: var(--sidebar-text-active); font-weight: 600; }

.user-box {
  margin-top: auto;
  padding: 0.8rem 0.6rem 0.2rem 0.6rem;
  border-top: 1px solid #262a46;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  color: #d7d9e4;
  font-size: 0.8rem;
}
.user-box button {
  background: #262a46;
  color: #e5e7eb;
  border: none;
  padding: 0.4rem 0.6rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.78rem;
}
.user-box button:hover { background: #333961; }

.content-area {
  flex: 1;
  min-width: 0;
}

main {
  padding: 1.75rem 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

.tab-panel.hidden { display: none; }

h2 { font-size: 1.25rem; margin: 0 0 1rem 0; letter-spacing: -0.01em; }
h3 { font-size: 1rem; margin: 1.5rem 0 0.6rem 0; color: var(--text); }

/* ---------------- Tables / cards ---------------- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  margin-top: 0.75rem;
  font-size: 0.85rem;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
th, td { text-align: left; padding: 0.65rem 0.8rem; border-bottom: 1px solid var(--border); }
th { background: #f8f9fc; color: var(--text-muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfe; }

.inline-form, .row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.inline-form { margin-bottom: 0.5rem; }

.stacked-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1rem;
  background: var(--surface);
  padding: 1.1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

input, select, button {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.85rem;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

button {
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
  cursor: pointer;
  font-weight: 600;
  transition: background 0.12s ease;
}
button:hover { background: var(--accent-dark); }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
button.secondary:hover { background: #f3f4f7; }

.currency-select { max-width: 90px; }

textarea {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
  width: 100%;
}
textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

h4 { font-size: 0.85rem; margin: 0.8rem 0 0.1rem 0; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

label.check { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; flex-wrap: wrap; }
label.field { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.78rem; color: var(--text-muted); font-weight: 600; margin-bottom: 0.5rem; }
label.field input, label.field select { font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.2rem 0.75rem; }
.templates-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0.75rem; }
.options-list { display: flex; flex-direction: column; gap: 0.55rem; }
.stacked-inner { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }
details summary { cursor: pointer; }
.actions { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.actions button { padding: 0.3rem 0.55rem; font-size: 0.78rem; }
td.overdue { color: var(--danger); font-weight: 600; }
#recordatorios-preview:not(:empty) {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
  margin-top: 0.75rem;
}

.line-row { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.3rem; }

/* ---------------- Messages / badges ---------------- */
.msg { padding: 0.65rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.85rem; }
.msg.error { background: var(--danger-soft); color: #991b1b; }
.msg.ok { background: var(--success-soft); color: #166534; }
.msg.hidden { display: none; }
.hint { color: var(--text-muted); font-size: 0.82rem; }

.badge { padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.72rem; font-weight: 600; display: inline-block; }
.badge.BORRADOR { background: var(--warn-soft); color: #92400e; }
.badge.CONTABILIZADA, .badge.CONTABILIZADO { background: #dbeafe; color: #1e3a8a; }
.badge.PENDIENTE { background: var(--danger-soft); color: #991b1b; }
.badge.PARCIAL { background: var(--warn-soft); color: #92400e; }
.badge.PAGADA, .badge.ACEPTADA, .badge.FINALIZADA, .badge.RECIBIDA { background: var(--success-soft); color: #166534; }
.badge.ENVIADA { background: #dbeafe; color: #1e3a8a; }
.badge.RECHAZADA, .badge.ANULADA, .badge.CANCELADA { background: var(--danger-soft); color: #991b1b; }
.badge.CONVERTIDA, .badge.EN_PROGRESO { background: #e5e7eb; color: #374151; }
.badge.ENVIADO { background: var(--success-soft); color: #166534; }
.badge.ERROR { background: var(--danger-soft); color: #991b1b; }
.badge.OMITIDO { background: #e5e7eb; color: #374151; }
.badge.FACTURA, .badge.RECIBO, .badge.RECORDATORIO, .badge.PRUEBA { background: var(--accent-soft); color: var(--accent-dark); }

/* ---------------- Dashboard ---------------- */
.cards { display: flex; gap: 1rem; flex-wrap: wrap; margin: 1rem 0 1.5rem 0; }
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  min-width: 170px;
  flex: 1 1 170px;
  box-shadow: var(--shadow);
}
.card .label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.card .value { font-size: 1.5rem; font-weight: 700; margin-top: 0.3rem; letter-spacing: -0.01em; }
.card.positive .value { color: var(--success); }
.card.negative .value { color: var(--danger); }

#dashboard-chart, #conciliacion-detail, #proyecto-detail {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
}
.chart-bar-row { display: flex; align-items: center; gap: 0.6rem; margin: 0.4rem 0; }
.chart-bar-label { width: 70px; font-size: 0.78rem; color: var(--text-muted); }
.chart-bar-track { flex: 1; background: var(--bg); border-radius: 5px; overflow: hidden; height: 16px; }
.chart-bar-fill { background: linear-gradient(90deg, var(--accent), #8b5cf6); height: 100%; border-radius: 5px; }
.chart-bar-value { width: 100px; text-align: right; font-size: 0.78rem; font-weight: 600; }

tr.total-row td { font-weight: 700; border-top: 2px solid var(--border); }

/* ---------------- Punto de venta ---------------- */
.pos-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(340px, 1fr); gap: 1rem; align-items: start; }
.pos-left, .pos-right { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.pos-right { display: flex; flex-direction: column; gap: 0.6rem; position: sticky; top: 1rem; }
#pos-search { width: 100%; font-size: 1rem; padding: 0.7rem 0.8rem; }
.pos-products { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.5rem; margin-top: 0.75rem; max-height: 60vh; overflow-y: auto; }
.pos-product { background: var(--bg); color: var(--text); border: 1px solid var(--border); text-align: left; padding: 0.6rem; font-weight: 500; display: flex; flex-direction: column; gap: 0.2rem; min-height: 78px; }
.pos-product:hover { background: var(--accent-soft); border-color: var(--accent); }
.pos-product .price { font-weight: 700; color: var(--accent-dark); }
.pos-product .stock { font-size: 0.72rem; color: var(--text-muted); }
.pos-cart { margin-top: 0; box-shadow: none; border: 1px solid var(--border); }
.pos-cart td, .pos-cart th { padding: 0.4rem 0.5rem; }
.pos-cart input { width: 64px; padding: 0.3rem; }
.pos-totals div, .pos-change { display: flex; justify-content: space-between; padding: 0.15rem 0; }
.pos-total { font-size: 1.4rem; font-weight: 700; border-top: 2px solid var(--border); padding-top: 0.4rem !important; }
.pos-pay { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.pos-pay input { font-size: 1rem; width: 100%; min-width: 0; }
.pos-pay label.field { min-width: 0; }
.pos-change { font-size: 1.15rem; font-weight: 700; color: var(--success); }
.pos-change.owed { color: var(--danger); }
.badge.alert { background: var(--warn-soft); color: #92400e; }
.badge.ok { background: var(--success-soft); color: #166534; }
.warnings { background: var(--warn-soft); color: #92400e; border-radius: var(--radius); padding: 0.7rem 1rem; margin-top: 0.75rem; font-size: 0.85rem; }

.nomina-sub.active-sub { background: var(--accent); color: white; border-color: var(--accent); }
#nomina-detail:not(:empty) { margin-top: 1rem; }
#nomina-detail input { width: 95px; padding: 0.3rem 0.4rem; }
.badge.ACEPTADO, .badge.ACEPTADO_CONDICIONAL { background: var(--success-soft); color: #166534; }
.badge.RECHAZADO { background: var(--danger-soft); color: #991b1b; }
.badge.EN_PROCESO, .badge.PENDIENTE_ECF { background: #dbeafe; color: #1e3a8a; }
.badge.REGULAR, .badge.REGALIA { background: var(--accent-soft); color: var(--accent-dark); }

/* ---------------- Responsive ---------------- */
@media (max-width: 880px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; flex-wrap: wrap; }
  .sidebar-brand { padding-bottom: 0.5rem; }
  .nav-group-label { display: none; }
  .user-box { margin-top: 0; border-top: none; flex-direction: row; }
  main { padding: 1.1rem; }
  .pos-layout { grid-template-columns: 1fr; }
  .pos-right { position: static; }
}
