@import url('https://fonts.googleapis.com/css2?family=Fira+Sans:wght@300;400;500;600;700&display=swap');

/* ── Tokens ──────────────────────────────────────────────────────── */
:root {
  --chatello-charcoal:    #121619;
  --chatello-gray:        #2A2C2D;
  --chatello-beige:       #DBD2CB;
  --chatello-beige-light: #ECE6E0;
  --chatello-beige-soft:  #F5F1ED;
  --chatello-white:       #FFFFFF;

  --bg:              #F5F1ED;
  --surface:         #FFFFFF;
  --surface-2:       #FAF7F4;
  --border:          #E2DAD2;
  --border-strong:   #C9BFB5;
  --text:            #121619;
  --text-2:          #4A4D50;
  --muted:           #7A7670;

  --ok:      #3E7B4F;  --ok-bg:     #E1EFE4;
  --warn:    #B4781B;  --warn-bg:   #FBEFD8;
  --danger:  #A62A1F;  --danger-bg: #F8E1DD;
  --info:    #4A4D50;  --info-bg:   #ECE6E0;

  --shadow-sm: 0 1px 2px rgba(18, 22, 25, 0.05);
  --shadow:    0 4px 12px rgba(18, 22, 25, 0.08);
  --shadow-lg: 0 12px 32px rgba(18, 22, 25, 0.18);

  --suc-himno-dark: #1B5E20; --suc-himno-light: #E8F5E9; --suc-himno-med: #C8E6C9;
  --suc-carr-dark:  #0D47A1; --suc-carr-light:  #E3F2FD; --suc-carr-med:  #BBDEFB;
  --suc-lomas-dark: #BF360C; --suc-lomas-light: #FBE9E7; --suc-lomas-med: #FFCCBC;
  --suc-prod-dark:  #4A148C; --suc-prod-light:  #F3E5F5; --suc-prod-med:  #E1BEE7;
}

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

body {
  font-family: 'Fira Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

a { color: inherit; text-decoration: none; }

/* ── Layout ──────────────────────────────────────────────────────── */
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  width: 240px;
  background: var(--chatello-charcoal);
  color: var(--chatello-beige);
  padding: 28px 20px 24px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  z-index: 100;
  transition: margin-left 0.2s;
}

.sidebar .brand { margin-bottom: 32px; }
.sidebar .brand img { display: block; }
.sidebar .brand h1 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin: 12px 0 4px;
}
.sidebar .brand .subtitle {
  font-size: 11px;
  color: rgba(219, 210, 203, 0.55);
}

.sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  padding: 11px 14px;
  border-radius: 6px;
  color: rgba(219, 210, 203, 0.78);
  font-weight: 500;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar nav a:hover {
  background: rgba(219, 210, 203, 0.08);
  color: var(--chatello-beige);
}
.sidebar nav a.active {
  background: var(--chatello-beige);
  color: var(--chatello-charcoal);
  font-weight: 600;
}
.sidebar nav .nav-icon { width: 18px; text-align: center; flex-shrink: 0; }

.sidebar .user {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid rgba(219, 210, 203, 0.12);
  font-size: 12px;
}
.sidebar .user strong { display: block; }
.sidebar .user span { color: rgba(219, 210, 203, 0.55); display: block; margin-top: 2px; }

.sidebar .logout-btn {
  margin-top: 12px;
  background: none;
  border: 1px solid rgba(219, 210, 203, 0.2);
  color: rgba(219, 210, 203, 0.6);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  width: 100%;
}
.sidebar .logout-btn:hover {
  background: rgba(219, 210, 203, 0.08);
  color: var(--chatello-beige);
}

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

.main > #page-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 36px 40px 0;
  max-width: 1440px;
}

/* Fixed top sections */
.page-header { flex-shrink: 0; }
.filters { flex-shrink: 0; }
.stats-grid { flex-shrink: 0; }

/* Scrollable area: the card(s) with tables */
.scroll-area {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-bottom: 36px;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 101;
  background: var(--chatello-charcoal);
  color: var(--chatello-beige);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
}

/* ── Page header ─────────────────────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}
.page-header h2 {
  font-size: 22px;
  font-weight: 600;
}

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.card-header {
  padding: 18px 22px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
.card-body { padding: 22px; }

/* ── Stat cards grid ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.stat-card .label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 8px;
}
.stat-card .value {
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-card .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* ── Tables ───────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}
th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: left;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}
td {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:hover { background: var(--chatello-beige-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
table .empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--text); }
.btn-primary { background: var(--chatello-charcoal); color: var(--chatello-beige); border-color: var(--chatello-charcoal); }
.btn-primary:hover { background: #000; }
.btn-success { background: var(--ok); color: white; border-color: var(--ok); }
.btn-success:hover { background: #2f5f3c; }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #8a1f17; }
.btn-sm { padding: 5px 11px; font-size: 12px; }

/* ── Badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge-ok        { background: var(--ok-bg);     color: var(--ok); }
.badge-alta      { background: var(--danger-bg); color: var(--danger); }
.badge-media     { background: var(--warn-bg);   color: var(--warn); }
.badge-baja      { background: var(--info-bg);   color: var(--info); }
.badge-pendiente { background: var(--warn-bg);   color: var(--warn); }

/* Sucursal badges */
.badge-himno { background: var(--suc-himno-light); color: var(--suc-himno-dark); }
.badge-carr  { background: var(--suc-carr-light);  color: var(--suc-carr-dark); }
.badge-lomas { background: var(--suc-lomas-light); color: var(--suc-lomas-dark); }
.badge-prod  { background: var(--suc-prod-light);  color: var(--suc-prod-dark); }

/* ── Forms ────────────────────────────────────────────────────────── */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea {
  padding: 9px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--chatello-charcoal);
  box-shadow: 0 0 0 3px rgba(18, 22, 25, 0.08);
}
label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

/* ── Filters bar ──────────────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 18px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

/* ── Modals ────────────────────────────────────────────────────────── */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(18, 22, 25, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--surface);
  border-radius: 10px;
  padding: 28px;
  max-width: 460px;
  width: calc(100% - 40px);
  box-shadow: var(--shadow-lg);
}
.modal h3 { font-size: 17px; font-weight: 600; margin: 0 0 18px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

/* ── Login ────────────────────────────────────────────────────────── */
body.login-body {
  background: var(--chatello-charcoal);
  height: auto;
  min-height: 100vh;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  padding: 48px 44px 40px;
  border-radius: 10px;
  width: 380px;
  max-width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-card .brand img { display: block; margin: 0 auto 16px; }
.login-card h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
.login-card .sub { font-size: 13px; color: var(--muted); margin-bottom: 28px; }
.login-card form { text-align: left; }
.login-card form label { margin-top: 14px; }
.login-card form label:first-of-type { margin-top: 0; }
.login-card form input { width: 100%; margin-bottom: 4px; }
.login-card .btn { width: 100%; margin-top: 16px; padding: 12px; font-size: 14px; justify-content: center; }
.login-card .error { margin-top: 12px; color: var(--danger); font-size: 12px; text-align: center; min-height: 16px; }

/* ── Sucursal table rows ──────────────────────────────────────────── */
.suc-header-himno { background: var(--suc-himno-dark); color: white; }
.suc-header-carr  { background: var(--suc-carr-dark);  color: white; }
.suc-header-lomas { background: var(--suc-lomas-dark); color: white; }
.suc-header-prod  { background: var(--suc-prod-dark);  color: white; }

.suc-row-himno { background: var(--suc-himno-light); }
.suc-row-carr  { background: var(--suc-carr-light); }
.suc-row-lomas { background: var(--suc-lomas-light); }
.suc-row-prod  { background: var(--suc-prod-light); }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar-toggle { display: block; }
  .layout.sidebar-collapsed .sidebar { margin-left: -240px; }

  .layout:not(.sidebar-collapsed) .main::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(18, 22, 25, 0.4);
    z-index: 99;
  }

  .main { margin-left: 0; padding: 24px 20px; padding-top: 60px; overflow: auto; min-height: 0; min-width: 0; }
  .sidebar { z-index: 100; }

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

  .hide-mobile { display: none; }
}

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