/* ════════════════════════════════════════════════════
   Sistema de Abasto — Comuna de Fighiera
   Tema ORIGINAL (claro/crema · sidebar navy · acento violeta)
   ════════════════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  background: #f5f5f0;
  color: #1a1a1a;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button, input, select, textarea { font-family: inherit; }
img { display: block; max-width: 100%; }

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

.sidebar {
  width: 240px;
  background: #1a1a2e;
  color: #ccc;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
  transition: transform .22s ease;
}

.sidebar-brand {
  padding: 18px 20px 16px;
  border-bottom: 1px solid #2a2a4a;
}
.sidebar-brand .brand-row { display: flex; align-items: center; gap: 10px; }
.sidebar-brand .brand-logo {
  width: 38px; height: 38px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(135deg, #6c63ff, #8b7bff);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 18px;
}
.sidebar-brand .brand-title { font-size: 16px; font-weight: 600; color: #fff; line-height: 1.2; }
.sidebar-brand .brand-sub   { font-size: 13px; color: #4d7deb; margin-top: 1px; }

.sidebar nav { padding: 12px 0; flex: 1; overflow-y: auto; }
.nav-section {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .08em; color: #555; padding: 14px 20px 4px;
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: #aaa; text-decoration: none;
  font-size: 14px; transition: background .15s, color .15s;
  border-left: 3px solid transparent; cursor: pointer;
}
.nav-link:hover { background: #2a2a4a; color: #fff; }
.nav-link.active { background: #2a2a4a; color: #fff; border-left-color: #6c63ff; }
.nav-icon { width: 16px; text-align: center; font-size: 14px; }

.sidebar-foot {
  padding: 14px 20px; border-top: 1px solid #2a2a4a;
  font-size: 12px; color: #777; display: flex; align-items: center; gap: 9px;
}
.sidebar-foot .av {
  width: 28px; height: 28px; border-radius: 50%; background: #2a2a4a;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #8b7bff; font-size: 12px;
}
.sidebar-foot a { margin-left: auto; color: #777; text-decoration: none; }
.sidebar-foot a:hover { color: #fff; }

.main {
  flex: 1; margin-left: 240px;
  display: flex; flex-direction: column; min-width: 0;
}

.topbar {
  background: #fff; border-bottom: 1px solid #e8e8e4;
  padding: 12px 28px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 40;
}
.topbar-title { font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.content { padding: 24px 28px 48px; flex: 1; }

.hamburger { display: none; background: none; border: none; cursor: pointer; font-size: 20px; color: #1a1a2e; padding: 4px; }

/* Modo laboratorio banner */
.lab-badge {
  background: #ffb300; color: #5d4037; font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 4px; display: inline-flex; align-items: center; gap: 4px;
}

/* ── Cards ──────────────────────────────────────────── */
.card { background: #fff; border: 1px solid #e8e8e4; border-radius: 10px; padding: 20px 24px; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid #f0f0ec;
}
.card-title { font-size: 14px; font-weight: 600; }

/* ── Metrics ────────────────────────────────────────── */
.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.metric-card { background: #fff; border: 1px solid #e8e8e4; border-radius: 10px; padding: 16px 20px; transition: box-shadow .15s; }
.metric-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,.05); }
.metric-label { font-size: 12px; color: #888; margin-bottom: 4px; }
.metric-value { font-size: 26px; font-weight: 600; }
.metric-sub { font-size: 11px; color: #aaa; margin-top: 2px; }
.metric-value.danger { color: #dc3545; }
.metric-value.success { color: #198754; }
.metric-value.warning { color: #fd7e14; }

/* ── Buttons ────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; font-size: 13px; border-radius: 7px;
  border: 1px solid #ddd; background: #fff; cursor: pointer;
  text-decoration: none; color: #333; transition: background .15s, opacity .15s; white-space: nowrap;
}
.btn:hover { background: #f5f5f0; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: #6c63ff; border-color: #6c63ff; color: #fff; }
.btn-primary:hover { background: #5a52e0; }
.btn-success { background: #198754; border-color: #198754; color: #fff; }
.btn-success:hover { background: #157347; }
.btn-danger { background: #fff; border-color: #dc3545; color: #dc3545; }
.btn-danger:hover { background: #fff5f5; }
.btn-warning { background: #ffc107; border-color: #ffc107; color: #000; }
.btn-warning:hover { background: #e0a800; }
.btn-navy { background: #1a3a5c; border-color: #1a3a5c; color: #fff; }
.btn-navy:hover { background: #122a44; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Badges ─────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.badge-a { background: #fff0f0; color: #c0392b; }
.badge-b { background: #fff7e6; color: #d68910; }
.badge-c { background: #e8f5e9; color: #1e8449; }
.badge-d { background: #eaf2ff; color: #1a5276; }
.badge-activo { background: #e8f5e9; color: #1e8449; }
.badge-baja { background: #ffeaea; color: #c0392b; }
.badge-deudor { background: #fff3cd; color: #856404; }
.badge-al-dia { background: #e8f5e9; color: #1e8449; }

/* ── Tables ─────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: #888; padding: 8px 12px; text-align: left; border-bottom: 1px solid #f0f0ec; white-space: nowrap;
}
td { padding: 11px 12px; border-bottom: 1px solid #f8f8f5; font-size: 14px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafaf7; }

/* ── Forms ──────────────────────────────────────────── */
.form-grid { display: grid; gap: 14px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 500; color: #555; }
.field input, .field select, .field textarea {
  padding: 8px 11px; border: 1px solid #ddd; border-radius: 7px;
  font-size: 13px; background: #fff; color: #1a1a1a; transition: border-color .15s; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: #6c63ff; }
.field textarea { min-height: 72px; resize: vertical; }

/* ── Search bar ─────────────────────────────────────── */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.search-bar input { flex: 1; min-width: 200px; padding: 8px 12px; border: 1px solid #ddd; border-radius: 7px; font-size: 13px; }
.search-bar input:focus { outline: none; border-color: #6c63ff; }
.search-bar select { padding: 8px 10px; border: 1px solid #ddd; border-radius: 7px; font-size: 13px; }

/* ── Alerts ─────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: 7px; font-size: 13px; margin-bottom: 12px; }
.alert-warning { background: #fff3cd; border: 1px solid #ffc107; color: #856404; }
.alert-danger  { background: #ffeaea; border: 1px solid #dc3545; color: #c0392b; }
.alert-success { background: #e8f5e9; border: 1px solid #198754; color: #1e8449; }
.alert-info    { background: #e8f0ff; border: 1px solid #6c63ff; color: #3d35b0; }

/* ── Modal ──────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 100; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; border-radius: 12px; padding: 24px 28px;
  width: 520px; max-width: 95vw; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 18px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid #f0f0ec; }

/* ── Section label ──────────────────────────────────── */
.section-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: #aaa; margin: 20px 0 10px;
}

/* ── Patente display ────────────────────────────────── */
.patente-display {
  font-family: 'Courier New', monospace; font-size: 18px; font-weight: 600; letter-spacing: .12em;
  background: #f5f5f0; border: 1px solid #ddd; border-radius: 7px; padding: 6px 16px; display: inline-block;
}

/* ── Saldo ──────────────────────────────────────────── */
.saldo-deudor { color: #dc3545; font-weight: 600; }
.saldo-al-dia { color: #198754; font-weight: 600; }

/* ── Ficha rows ─────────────────────────────────────── */
.ficha-row { display: flex; flex-direction: column; gap: 1px; }
.ficha-row .k { font-size: 11px; color: #aaa; text-transform: uppercase; letter-spacing: .04em; }
.ficha-row .v { font-size: 14px; color: #1a1a1a; font-weight: 500; }

/* ── Toast ──────────────────────────────────────────── */
#toast-wrap { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: 9px; font-size: 13px; font-weight: 500; color: #fff;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); display: flex; align-items: center; gap: 8px;
  animation: toastIn .25s ease; min-width: 240px;
}
.toast.success { background: #198754; }
.toast.danger  { background: #dc3545; }
.toast.info    { background: #6c63ff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ── Spinner ────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }

/* ── Login ──────────────────────────────────────────── */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: #f3f4f6; padding: 20px;
}
.login-box {
  background: #fff; padding: 38px 34px; border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,.1); width: 100%; max-width: 400px;
  border-top: 4px solid #6c63ff;
}

/* ── Tabs ───────────────────────────────────────────── */
.tab-btn { padding: 6px 16px; border-radius: 7px; border: 1px solid #ddd; font-size: 13px; cursor: pointer; background: #fff; color: #333; }
.tab-btn.active { background: #1a1a2e; color: #fff; border-color: #1a1a2e; }

/* ── Recibo preview ─────────────────────────────────── */
.recibo {
  background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 24px;
  font-family: 'Courier New', monospace; font-size: 13px; color: #1a1a1a;
}
.recibo .r-head { text-align: center; border-bottom: 2px dashed #ccc; padding-bottom: 12px; margin-bottom: 12px; }
.recibo .r-row { display: flex; justify-content: space-between; padding: 3px 0; }
.recibo .r-total { border-top: 2px dashed #ccc; margin-top: 12px; padding-top: 12px; font-weight: 700; font-size: 15px; }

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: 12px 0 40px rgba(0,0,0,.3); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .hamburger { display: block; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .content { padding: 16px; }
  .metrics-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .topbar { padding: 10px 16px; }
  .detalle-grid { grid-template-columns: 1fr !important; }
}
