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

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

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --muted-light: #94a3b8;
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-light: #ede9fe;
  --primary-hover: #4338ca;
  --green: #059669;
  --green-light: #d1fae5;
  --yellow: #d97706;
  --yellow-light: #fef3c7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --blue: #2563eb;
  --blue-light: #dbeafe;
  --purple: #7c3aed;
  --orange: #ea580c;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.07), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.06), 0 10px 25px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1), 0 30px 60px rgba(0,0,0,0.08);
  --sidebar-bg: #1e1b4b;
  --sidebar-surface: rgba(255,255,255,0.06);
  --sidebar-active: rgba(255,255,255,0.14);
  --sidebar-hover: rgba(255,255,255,0.09);
  --sidebar-text: rgba(255,255,255,0.9);
  --sidebar-muted: rgba(255,255,255,0.5);
  --sidebar-border: rgba(255,255,255,0.08);
  --transition: 0.18s cubic-bezier(0.4,0,0.2,1);
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ══ LAYOUT ══════════════════════════════════════════════════════════════ */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ══ SIDEBAR ═════════════════════════════════════════════════════════════ */
#sidebar {
  width: 230px; min-width: 230px;
  background: var(--sidebar-bg);
  background-image: linear-gradient(160deg, #1e1b4b 0%, #2d1f6e 50%, #1a1035 100%);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
  border-right: 1px solid rgba(0,0,0,0.2);
}

#sidebar-logo {
  padding: 22px 18px 18px;
  font-size: 15px; font-weight: 800;
  letter-spacing: -0.02em;
  border-bottom: 1px solid var(--sidebar-border);
  line-height: 1.3;
  background: rgba(0,0,0,0.15);
}
#sidebar-logo span {
  display: block; font-size: 10.5px; font-weight: 400;
  opacity: 0.5; margin-top: 3px; letter-spacing: 0.02em;
}

nav { flex: 1; padding: 10px 8px; }

.nav-section-label {
  font-size: 9.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--sidebar-muted);
  padding: 14px 10px 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; cursor: pointer;
  font-size: 13.5px; font-weight: 500;
  border-radius: 8px; margin-bottom: 2px;
  transition: background var(--transition), color var(--transition);
  color: rgba(255,255,255,0.72);
}
.nav-item:hover {
  background: var(--sidebar-hover);
  color: rgba(255,255,255,0.95);
}
.nav-item.active {
  background: var(--sidebar-active);
  color: #fff; font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
}
.nav-item .nav-icon {
  font-size: 15px; width: 20px; text-align: center;
  opacity: 0.85; flex-shrink: 0;
}
.nav-item.active .nav-icon { opacity: 1; }

/* Sidebar bottom accent */
#sidebar::after {
  content: ''; display: block; height: 1px;
  background: var(--sidebar-border);
  margin: 0 12px 12px;
}

/* ══ MAIN ════════════════════════════════════════════════════════════════ */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

#topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 1px 0 var(--border), 0 2px 8px rgba(0,0,0,0.04);
  position: relative; z-index: 10;
}
#topbar h1 {
  font-size: 17px; font-weight: 700;
  color: var(--text); letter-spacing: -0.01em;
}
#topbar span { font-size: 12px; color: var(--muted); }

#content { flex: 1; overflow-y: auto; padding: 28px; }

/* ══ TAB PANELS ══════════════════════════════════════════════════════════ */
.tab-panel.hidden { display: none; }
.tab-panel { display: block; }

/* ══ DASHBOARD ═══════════════════════════════════════════════════════════ */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-header h2 { font-size: 15px; font-weight: 700; }

#dash-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px; margin-top: 16px;
}

.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
  border-top: 3px solid var(--border);
  transition: box-shadow var(--transition), transform var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.card-blue   { border-top-color: var(--blue); }
.card-green  { border-top-color: var(--green); }
.card-yellow { border-top-color: var(--yellow); }
.card-red    { border-top-color: var(--red); }
.card-value  { font-size: 24px; font-weight: 800; margin-bottom: 4px; letter-spacing: -0.02em; }
.card-label  { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ══ TABLES ══════════════════════════════════════════════════════════════ */
.table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
th {
  background: var(--surface-2);
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); padding: 11px 16px;
  text-align: left; border-bottom: 1px solid var(--border);
}
td { padding: 11px 16px; border-bottom: 1px solid var(--border-light); vertical-align: middle; color: var(--text-2); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbff; }
.empty-state { text-align: center; color: var(--muted); padding: 40px !important; font-size: 13px; }

/* ══ BADGES ══════════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.01em;
  line-height: 1.4;
}
.badge-green  { background: var(--green-light);  color: #065f46; }
.badge-yellow { background: var(--yellow-light); color: #92400e; }
.badge-red    { background: var(--red-light);    color: #991b1b; }
.badge-blue   { background: var(--blue-light);   color: #1e40af; }
.badge-gray   { background: #f1f5f9; color: var(--muted); }

/* ══ BUTTONS ═════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  font-size: 13px; font-weight: 600;
  font-family: inherit;
  transition: all var(--transition);
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: var(--primary); color: #fff;
  box-shadow: 0 2px 8px rgba(79,70,229,0.35);
}
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 4px 14px rgba(79,70,229,0.4); }
.btn-danger {
  background: var(--red); color: #fff;
  box-shadow: 0 2px 8px rgba(220,38,38,0.3);
}
.btn-danger:hover { background: #b91c1c; box-shadow: 0 4px 14px rgba(220,38,38,0.4); }
.btn-ghost {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--surface-2); border-color: #cbd5e1; }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: var(--radius-sm); }

/* ══ FORMS ═══════════════════════════════════════════════════════════════ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-2); letter-spacing: 0.01em; }
.form-group input, .form-group select, .form-group textarea {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px; color: var(--text);
  background: var(--surface); font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}
.form-group.full { grid-column: 1 / -1; }

/* ══ MODAL ═══════════════════════════════════════════════════════════════ */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.55);
  z-index: 100; backdrop-filter: blur(4px);
}
#app-modal {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 101; background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 95%; max-width: 780px; max-height: 92vh;
  display: flex; flex-direction: column;
  border: 1px solid var(--border);
}
#app-modal.hidden { display: none; }
#modal-overlay.hidden { display: none; }
#modal-header {
  padding: 20px 26px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
#modal-title { font-size: 16px; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
#modal-body  { padding: 26px; overflow-y: auto; flex: 1; }
#modal-footer {
  padding: 16px 26px;
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
#modal-footer .btn { padding: 9px 24px; font-size: 13.5px; }

/* ══ GUIDE ITEMS ═════════════════════════════════════════════════════════ */
.guide-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px; overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition), border-color var(--transition);
}
.guide-item:hover { box-shadow: var(--shadow-md); border-color: #cbd5e1; }

.item-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 16px;
  background: linear-gradient(to right, #f8fafc, #f1f5f9);
  border-bottom: 1px solid var(--border);
}
.item-num {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .07em;
}
.item-header-right { display: flex; align-items: center; gap: 8px; }
.btn-item-del {
  width: 26px; height: 26px; border-radius: 50%; border: none;
  background: var(--red-light); color: var(--red); cursor: pointer;
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.btn-item-del:hover { background: var(--red); color: #fff; transform: scale(1.1); }

/* Via selector */
.via-select {
  padding: 4px 28px 4px 10px;
  border-radius: 20px; border: 1.5px solid #d1d5db;
  font-size: 12px; font-weight: 600; cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7280'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
  transition: all var(--transition); font-family: inherit;
}
.via-unica { background-color: #d1fae5; border-color: #6ee7b7; color: #065f46; }
.via-mesma { background-color: #fef3c7; border-color: #fcd34d; color: #92400e; }
.via-none  { background-color: #f1f5f9; border-color: var(--border); color: var(--muted); }

/* Calc row */
.item-body { padding: 16px; }
.calc-row {
  display: flex; align-items: flex-end; gap: 8px; margin-top: 14px;
  background: var(--surface-2); border-radius: var(--radius);
  padding: 14px 16px; border: 1px solid var(--border);
}
.calc-field { display: flex; flex-direction: column; gap: 4px; }
.calc-field label {
  font-size: 10px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing:.05em; white-space: nowrap;
}
.calc-field input {
  padding: 8px 10px; border: 1.5px solid var(--border); border-radius: 7px;
  font-size: 13px; font-weight: 600; color: var(--text); background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.calc-field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.12); }
.calc-field.wide input { width: 130px; }
.calc-field.narrow input { width: 68px; }
.calc-op { font-size: 18px; font-weight: 300; color: #cbd5e1; padding-bottom: 7px; flex-shrink: 0; align-self: flex-end; }
.result-box { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 14px; border-radius: 8px; flex-shrink: 0; min-width: 95px; }
.result-box label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing:.05em; }
.result-box .val { font-size: 15px; font-weight: 700; }
.result-bruto { background: #f1f5f9; }
.result-bruto label { color: var(--muted-light); }
.result-bruto .val  { color: var(--text-2); }
.result-final { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); box-shadow: 0 4px 12px rgba(79,70,229,0.3); }
.result-final label { color: rgba(255,255,255,0.7); }
.result-final .val  { color: #fff; font-size: 16px; }
.result-arrow { font-size: 18px; color: #e2e8f0; align-self: flex-end; padding-bottom: 9px; }

/* Extra fields */
.item-extra { display: flex; gap: 10px; padding: 12px 16px 16px; flex-wrap: wrap; border-top: 1px solid var(--border-light); background: #fafbff; }
.item-extra .form-group { margin: 0; min-width: 150px; flex: 1; }
.item-extra .form-group label { font-size: 11px; }

/* Guide total row */
.guide-total-row {
  display: flex; align-items: center; justify-content: flex-end; gap: 14px;
  margin-top: 18px; padding: 14px 18px;
  background: var(--primary-light);
  border-radius: var(--radius); border: 1.5px solid #c4b5fd;
}
.guide-total-row label { font-size: 13px; font-weight: 600; color: var(--primary); }
.guide-total-row input {
  width: 160px; padding: 9px 14px;
  border: 2px solid var(--primary);
  border-radius: 8px; font-size: 17px; font-weight: 700;
  color: var(--primary); text-align: right; background: #fff;
  font-family: inherit;
}
.guide-total-row input:focus { outline: none; box-shadow: 0 0 0 3px rgba(79,70,229,0.2); }

/* ══ TOAST ═══════════════════════════════════════════════════════════════ */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 11px 18px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; font-family: inherit;
  box-shadow: var(--shadow-md); animation: toastIn 0.25s cubic-bezier(0.34,1.56,0.64,1);
  max-width: 320px; line-height: 1.4;
}
.toast-success { background: #059669; color: #fff; }
.toast-error   { background: var(--red); color: #fff; }
.toast-info    { background: var(--primary); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* ══ MISC ════════════════════════════════════════════════════════════════ */
.coming-soon { padding: 60px; text-align: center; color: var(--muted); font-size: 15px; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar input[type="text"] {
  padding: 8px 12px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 13px; flex: 1;
  min-width: 160px; font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.toolbar input[type="text"]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.comp-select {
  padding: 8px 12px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 13px; font-family: inherit;
  background: var(--surface);
}
.panel {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px; margin-bottom: 20px;
  border: 1px solid var(--border);
}

/* ══ ALERT BANNERS ═══════════════════════════════════════════════════════ */
.alert-banner {
  padding: 11px 18px; border-radius: var(--radius);
  margin-bottom: 12px; font-size: 13px; font-weight: 500;
  border: 1px solid transparent;
}
.alert-red    { background: var(--red-light);    color: #991b1b; border-color: #fca5a5; }
.alert-yellow { background: var(--yellow-light); color: #92400e; border-color: #fcd34d; }

/* ══ FINANCIAL PANEL ═════════════════════════════════════════════════════ */
.chart-title {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 12px;
}
@media (max-width: 1100px) { #fin-charts-grid { grid-template-columns: 1fr !important; } }

/* ══ PDF IMPORT ══════════════════════════════════════════════════════════ */
.pdf-preview-table { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.pdf-row { display: flex; align-items: flex-start; gap: 12px; padding: 9px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.pdf-row:last-child { border-bottom: none; }
.pdf-label { font-weight: 600; color: var(--muted); font-size: 12px; min-width: 160px; padding-top: 1px; }
.pdf-ok   { color: var(--green); font-weight: 600; }
.pdf-warn { color: var(--yellow); font-weight: 600; }

/* ══ DASHBOARD COMPONENTS ════════════════════════════════════════════════ */
.dash-header {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 22px; margin-bottom: 26px;
  border-bottom: 1.5px solid var(--border);
  flex-wrap: wrap; gap: 14px;
}
.dash-header-left { display: flex; flex-direction: column; gap: 4px; }
.dash-title { font-size: 24px; font-weight: 800; color: var(--text); letter-spacing: -0.03em; }
.dash-subtitle { font-size: 13px; color: var(--muted); }
.dash-header-right { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.dash-comp-wrap { display: flex; flex-direction: column; gap: 4px; }
.dash-comp-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.dash-comp-select {
  padding: 8px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 13px;
  color: var(--text); background: var(--surface);
  cursor: pointer; transition: border-color var(--transition), box-shadow var(--transition);
  min-width: 200px; font-family: inherit; font-weight: 500;
}
.dash-comp-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }

.dash-section { margin-bottom: 30px; }
.dash-section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted-light);
  padding-bottom: 10px; margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

/* Primary metric cards */
.dash-grid-primary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.metric-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}
.metric-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: #cbd5e1; }
.metric-icon { font-size: 20px; margin-bottom: 10px; line-height: 1; }
.metric-value { font-size: 22px; font-weight: 800; margin-bottom: 3px; line-height: 1.2; letter-spacing: -0.02em; }
.metric-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 2px; }
.metric-subtitle { font-size: 11px; color: var(--muted); }

/* Secondary stat cards */
.dash-grid-secondary { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 5px;
  transition: box-shadow var(--transition), transform var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-icon { font-size: 16px; line-height: 1; }
.stat-value { font-size: 23px; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.stat-label { font-size: 11px; color: var(--muted); font-weight: 500; }

/* Charts grid */
.dash-charts-grid { display: grid; grid-template-columns: 1fr 420px; gap: 16px; align-items: start; }
.dash-charts-col { display: flex; flex-direction: column; gap: 16px; }
.chart-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow); border: 1px solid var(--border);
}
.chart-wrap    { position: relative; height: 240px; }
.chart-wrap-sm { position: relative; height: 160px; }

/* Alerts */
.dash-alerts { display: flex; flex-direction: column; gap: 8px; }
.dash-alert {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  border: 1px solid transparent;
  transition: all var(--transition); cursor: default;
}
.dash-alert:hover { transform: translateX(2px); }
.dash-alert-icon { font-size: 15px; flex-shrink: 0; }
.dash-alert-msg  { flex: 1; }
.dash-alert-link { font-size: 12px; font-weight: 700; margin-left: auto; flex-shrink: 0; opacity: 0.65; }
.dash-alert-yellow { background: var(--yellow-light); color: #78350f; border-color: #fcd34d; }
.dash-alert-red    { background: var(--red-light);    color: #991b1b; border-color: #fca5a5; }
.dash-alert-blue   { background: var(--blue-light);   color: #1e40af; border-color: #93c5fd; }
.dash-alert-ok     { background: var(--green-light);  color: #064e3b; border-color: #6ee7b7; }

/* ══ FILTER PANEL (estilo shadcn/Radix) ══════════════════════════════════ */
.filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 24px;
  display: flex; flex-direction: column; gap: 14px;
}
.filter-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; }
.filter-group { display: flex; flex-direction: column; gap: 5px; }
.filter-label {
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted-light);
}
.filter-controls { display: flex; align-items: center; gap: 6px; }
.filter-controls .sep { font-size: 11px; color: var(--muted-light); }

/* Segmented control (estilo Radix Toggle Group) */
.seg-control {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px; gap: 2px;
}
.seg-btn {
  padding: 7px 14px;
  border: none; background: transparent;
  border-radius: 6px;
  font-size: 12.5px; font-weight: 600;
  color: var(--muted); cursor: pointer;
  transition: all var(--transition);
  font-family: inherit; white-space: nowrap;
}
.seg-btn:hover { color: var(--text-2); }
.seg-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(16,24,40,.1), 0 0 0 1px var(--border);
}

/* Filter chips (toggle pills) */
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 12px; font-weight: 600;
  color: var(--muted); cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
  user-select: none; white-space: nowrap;
}
.filter-chip:hover { border-color: #cbd5e1; color: var(--text-2); }
.filter-chip:has(input:checked) {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}
.filter-chip input { display: none; }

/* ══ FIN STATS (estilo DaisyUI stats) ════════════════════════════════════ */
.fin-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 28px;
}
.fin-stat {
  padding: 18px 22px;
  display: flex; flex-direction: column; gap: 5px;
  border-right: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
}
.fin-stat:hover { background: #fafbff; }
.fin-stat:nth-child(5n) { border-right: none; }
.fin-stat:nth-last-child(-n+5) { border-bottom: none; }
.fin-stat-title {
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.fin-stat-value { font-size: 21px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
.fin-stat-desc  { font-size: 10.5px; color: var(--muted-light); }

@media (max-width: 1280px) {
  .fin-stats { grid-template-columns: repeat(4, 1fr); }
  .fin-stat:nth-child(5n) { border-right: 1px solid var(--border-light); }
  .fin-stat:nth-child(4n) { border-right: none; }
  .fin-stat:nth-last-child(-n+5) { border-bottom: 1px solid var(--border-light); }
  .fin-stat:nth-last-child(-n+2) { border-bottom: none; }
}
@media (max-width: 900px) {
  .fin-stats { grid-template-columns: repeat(2, 1fr); }
  .fin-stat:nth-child(4n) { border-right: 1px solid var(--border-light); }
  .fin-stat:nth-child(2n) { border-right: none; }
}

/* ══ TABLE FOOT (totais) ═════════════════════════════════════════════════ */
tfoot td {
  background: var(--surface-2);
  font-weight: 700; color: var(--text);
  border-top: 2px solid var(--border);
  padding: 11px 16px;
}
tfoot tr:hover td { background: var(--surface-2); }

/* ══ MODO VISUALIZAÇÃO (snapshot publicado) ══════════════════════════════ */
/* Esconde todas as ações por padrão e reexibe apenas botões de visualização */
body.viewer-mode .btn { display: none !important; }
body.viewer-mode .btn[onclick*="renderDashboard"],
body.viewer-mode .btn[onclick*="generateReport"],
body.viewer-mode .btn[onclick*="exportReportCSV"],
body.viewer-mode .btn[onclick*="printReport"],
body.viewer-mode .btn[onclick*="clearFinFilters"],
body.viewer-mode #modal-cancel-btn { display: inline-flex !important; }

/* Abas exclusivas do administrador */
body.viewer-mode .nav-item[data-tab="backup"],
body.viewer-mode .nav-item[data-tab="import"],
body.viewer-mode .nav-item[data-tab="tasks"] { display: none !important; }

/* Seleção de guias para montar lote (ação de administrador) */
body.viewer-mode .guide-chk,
body.viewer-mode #guide-sel-all { visibility: hidden !important; }
body.viewer-mode #guide-sel-bar { display: none !important; }

/* Tela de senha do modo visualização */
#viewer-pass-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: linear-gradient(160deg, #1e1b4b 0%, #2d1f6e 50%, #1a1035 100%);
  display: flex; align-items: center; justify-content: center;
}
.vpass-card {
  background: #fff; border-radius: 16px; padding: 36px 32px;
  width: 92%; max-width: 360px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.vpass-logo { font-size: 20px; font-weight: 800; color: #1e1b4b; letter-spacing: -.02em; }
.vpass-sub  { font-size: 12.5px; color: #64748b; margin: 4px 0 22px; }
.vpass-card input {
  width: 100%; padding: 12px 14px; border: 1.5px solid #e2e8f0; border-radius: 8px;
  font-size: 15px; font-family: inherit; margin-bottom: 12px;
}
.vpass-card input:focus { outline: none; border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.vpass-card button {
  width: 100%; padding: 12px; background: #4f46e5; color: #fff; border: none;
  border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: background .15s;
}
.vpass-card button:hover:not(:disabled) { background: #4338ca; }
.vpass-card button:disabled { opacity: .6; cursor: default; }
#vpass-error { font-size: 12.5px; color: #dc2626; margin-top: 10px; min-height: 16px; }

/* Selo do modo visualização no topo */
#viewer-badge {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600; color: #1e40af;
  background: #eff6ff; border: 1px solid #93c5fd;
  padding: 5px 12px; border-radius: 20px;
}

/* ══ MOBILE — MODO VISUALIZAÇÃO ══════════════════════════════════════════ */
#mobile-menu-btn {
  display: none;
  background: none; border: none; cursor: pointer;
  font-size: 24px; padding: 6px 10px; color: var(--text-primary);
  line-height: 1; flex-shrink: 0;
}
#sidebar-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,0.5);
}

@media (max-width: 768px) {
  /* Mostra botão hamburguer */
  body.viewer-mode #mobile-menu-btn { display: flex; align-items: center; }

  /* Sidebar desliza da esquerda */
  body.viewer-mode #sidebar {
    position: fixed; top: 0; left: -280px; height: 100%;
    width: 270px; z-index: 100;
    transition: left 0.25s ease;
    box-shadow: none;
    overflow-y: auto;
  }
  body.viewer-mode.sidebar-open #sidebar {
    left: 0;
    box-shadow: 6px 0 30px rgba(0,0,0,0.4);
  }
  body.viewer-mode.sidebar-open #sidebar-overlay { display: block; }

  /* Nav items — garante que texto apareça */
  body.viewer-mode #sidebar .nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 13px 16px; font-size: 15px;
  }
  body.viewer-mode #sidebar .nav-item span:last-child {
    display: inline !important; opacity: 1 !important;
  }
  body.viewer-mode #sidebar .nav-icon { font-size: 18px; }

  /* Logo do sidebar no mobile */
  body.viewer-mode #sidebar-logo { padding: 24px 18px 18px; font-size: 16px; }

  /* Main ocupa tela toda */
  body.viewer-mode #app { flex-direction: row; }
  body.viewer-mode #main { margin-left: 0; width: 100%; min-width: 0; }

  /* Topbar compacto */
  body.viewer-mode #topbar {
    gap: 8px; padding: 0 12px; min-height: 52px;
  }
  body.viewer-mode #topbar-title { font-size: 16px; }

  /* Badge menor — só ícone + "Modo visualização", sem data */
  body.viewer-mode #viewer-badge {
    font-size: 11px; padding: 4px 8px;
    white-space: nowrap; overflow: hidden;
    max-width: 180px; text-overflow: ellipsis;
  }

  /* Cards em 2 colunas */
  body.viewer-mode .dash-grid-primary,
  body.viewer-mode .fin-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  /* Padding do conteúdo */
  body.viewer-mode #content { padding: 12px; }
}

/* ══ SCROLLBAR ═══════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 5px; }
::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 5px; border: 2px solid #f1f5f9; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }

#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); }
#sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* ══ RESPONSIVE ══════════════════════════════════════════════════════════ */
@media (max-width: 1280px) {
  .dash-grid-primary  { grid-template-columns: repeat(4, 1fr); }
  .dash-charts-grid   { grid-template-columns: 1fr; }
  .dash-charts-col    { flex-direction: row; }
  .dash-charts-col .chart-card { flex: 1; }
}
@media (max-width: 1024px) {
  .dash-grid-primary   { grid-template-columns: repeat(2, 1fr); }
  .dash-grid-secondary { grid-template-columns: repeat(3, 1fr); }
  .dash-charts-col     { flex-direction: column; }
}
@media (max-width: 768px) {
  #sidebar { width: 60px; min-width: 60px; }
  #sidebar-logo { font-size: 0; padding: 14px 0; text-align: center; }
  #sidebar-logo span { display: none; }
  .nav-item { padding: 10px; justify-content: center; }
  .nav-item span:not(.nav-icon) { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .dash-grid-primary   { grid-template-columns: 1fr 1fr; }
  .dash-grid-secondary { grid-template-columns: 1fr 1fr; }
  .dash-header         { flex-direction: column; align-items: flex-start; }
  #content { padding: 16px; }
}
