/* ===== IVAI — Calculadora de IVA Técnico ===== */

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

:root {
  --sidebar-bg: #1e2a3a;
  --sidebar-active: #16a34a;
  --sidebar-hover: #263548;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --green-border: #bbf7d0;
  --yellow: #ca8a04;
  --yellow-bg: #fefce8;
  --yellow-border: #fde68a;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --radius: 8px;
  --sidebar-w: 220px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid #2d3d52;
}

.sidebar-logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
}

.sidebar-logo span {
  font-size: 11px;
  color: #94a3b8;
  display: block;
  margin-top: 2px;
  line-height: 1.4;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  cursor: pointer;
  border-radius: 0;
  transition: background .15s;
  color: #94a3b8;
  font-size: 14px;
  font-weight: 500;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-item.active { background: rgba(22,163,74,.15); color: #4ade80; border-left: 3px solid var(--sidebar-active); padding-left: 17px; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid #2d3d52;
  font-size: 11px;
  color: #475569;
}

/* ===== MAIN CONTENT ===== */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.topbar-file {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-file .dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; display: inline-block; }
.topbar-file .dot.loaded { background: var(--green); }

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

/* ===== SECTIONS ===== */
.section { display: none; }
.section.active { display: block; }

/* ===== CARDS ===== */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.card-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.card-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.card.green { border-color: var(--green-border); background: var(--green-bg); }
.card.green .card-value { color: var(--green); }
.card.yellow { border-color: var(--yellow-border); background: var(--yellow-bg); }
.card.yellow .card-value { color: var(--yellow); }
.card.red { border-color: var(--red-border); background: var(--red-bg); }
.card.red .card-value { color: var(--red); }
.card.highlight { border-color: #bfdbfe; background: #eff6ff; }
.card.highlight .card-value { color: var(--primary); }

/* ===== SEMÁFORO ===== */
.semaforo-block {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.semaforo-icon {
  font-size: 36px;
  line-height: 1;
  flex-shrink: 0;
}

.semaforo-body { flex: 1; }
.semaforo-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.semaforo-desc { font-size: 13px; color: var(--text-muted); line-height: 1.6; }

.semaforo-block.green { border-color: var(--green-border); background: var(--green-bg); }
.semaforo-block.green .semaforo-title { color: var(--green); }
.semaforo-block.yellow { border-color: var(--yellow-border); background: var(--yellow-bg); }
.semaforo-block.yellow .semaforo-title { color: var(--yellow); }
.semaforo-block.red { border-color: var(--red-border); background: var(--red-bg); }
.semaforo-block.red .semaforo-title { color: var(--red); }

/* ===== PANELS / SECTIONS ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.panel-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-header {
  margin-bottom: 24px;
}

.section-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.section-header p {
  color: var(--text-muted);
  margin-top: 4px;
  font-size: 13px;
}

/* ===== TABLES ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  background: #f8fafc;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.data-table .highlight-row td { font-weight: 700; background: #f8fafc; }
.data-table .total-row td { font-weight: 700; border-top: 2px solid var(--border); background: #f1f5f9; }

/* ===== FORMS / INPUTS ===== */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

input[type="number"], input[type="text"], select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s;
  font-family: inherit;
}

input[type="number"]:focus, input[type="text"]:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ===== DROPZONE ===== */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: #fafafa;
}

.dropzone:hover, .dropzone.drag-over {
  border-color: var(--primary);
  background: #eff6ff;
}

.dropzone.loaded {
  border-color: var(--green);
  background: var(--green-bg);
}

.dropzone-icon { font-size: 32px; margin-bottom: 8px; }
.dropzone-title { font-size: 14px; font-weight: 600; color: var(--text); }
.dropzone-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.dropzone input[type="file"] { display: none; }

.file-loaded-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--green);
  font-weight: 600;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
  font-family: inherit;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 20px;
}

/* ===== ALERTS / WARNINGS ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.alert-warn { background: var(--yellow-bg); border: 1px solid var(--yellow-border); color: #92400e; }
.alert-error { background: var(--red-bg); border: 1px solid var(--red-border); color: #991b1b; }
.alert-success { background: var(--green-bg); border: 1px solid var(--green-border); color: #14532d; }
.alert-info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }
.alert-icon { flex-shrink: 0; font-size: 16px; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
}

.badge-green { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); border: 1px solid var(--yellow-border); }
.badge-red { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); }
.badge-blue { background: #eff6ff; color: var(--primary); border: 1px solid #bfdbfe; }

/* ===== STEPS (wizard) ===== */
.steps {
  display: flex;
  gap: 0;
  margin-bottom: 28px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.step {
  flex: 1;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  border-right: 1px solid var(--border);
  font-size: 13px;
}

.step:last-child { border-right: none; }
.step.active { background: #eff6ff; }
.step.done { background: var(--green-bg); }

.step-num {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  background: #e2e8f0; color: var(--text-muted);
  flex-shrink: 0;
}

.step.active .step-num { background: var(--primary); color: #fff; }
.step.done .step-num { background: var(--green); color: #fff; }
.step-label { font-weight: 500; color: var(--text-muted); }
.step.active .step-label { color: var(--primary); font-weight: 600; }
.step.done .step-label { color: var(--green); }

/* ===== HISTORIAL ===== */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filter-bar .form-group { margin-bottom: 0; }
.filter-bar select, .filter-bar input { width: auto; min-width: 130px; }

.expandable-row { cursor: pointer; }
.expandable-row:hover td { background: #f0f9ff !important; }
.row-detail { display: none; background: #f8fafc; }
.row-detail.open { display: table-row; }
.row-detail td { padding: 16px; }
.row-detail-inner { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ===== COMPARACION ===== */
.compare-section { margin-top: 24px; }
.compare-selector { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 20px; }
.compare-selector .form-group { margin-bottom: 0; }

.delta-pos { color: var(--green); font-weight: 600; }
.delta-neg { color: var(--red); font-weight: 600; }
.delta-neu { color: var(--text-muted); }

/* ===== IVA TECNICO DETAIL ===== */
.iva-breakdown {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0;
}

.iva-row {
  display: contents;
}

.iva-row > * {
  padding: 8px 12px;
  border-bottom: 1px solid #f1f5f9;
}

.iva-row.total > * {
  font-weight: 700;
  border-top: 2px solid var(--border);
  border-bottom: none;
  background: #f8fafc;
}

/* ===== OVERLAY ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.85);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay.hidden { display: none; }

.overlay-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 40px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,.3);
}

.overlay-box h2 { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.overlay-box p { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }

.overlay-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  margin-bottom: 16px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.overlay-dropzone:hover { border-color: var(--primary); background: #eff6ff; }
.overlay-dropzone input { display: none; }
.overlay-dropzone-icon { font-size: 40px; margin-bottom: 12px; }
.overlay-dropzone-title { font-size: 15px; font-weight: 600; }
.overlay-dropzone-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.overlay-skip { font-size: 13px; color: var(--text-muted); cursor: pointer; text-decoration: underline; }
.overlay-skip:hover { color: var(--text); }

/* ===== LOADING SPINNER ===== */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin-right: 6px;
}

.spinner-dark {
  border-color: rgba(37,99,235,.2);
  border-top-color: var(--primary);
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 14px; max-width: 380px; margin: 0 auto 24px; }

/* ===== PREVIEW RESULT (periodo) ===== */
.preview-result {
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 24px;
  background: #eff6ff;
}

.preview-result-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== DIVIDERS ===== */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ===== GOOGLE DRIVE UI ===== */
.sidebar-drive {
  padding: 12px 16px;
  border-top: 1px solid #2d3d52;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.drive-btn-connect {
  background: transparent;
  color: #94a3b8;
  border: 1px solid #3d5068;
  width: 100%;
  justify-content: center;
  font-size: 12px;
}

.drive-btn-connect:hover {
  background: #263548;
  color: #e2e8f0;
  border-color: #4a6080;
}

.drive-btn-connected {
  background: rgba(22,163,74,.15);
  color: #4ade80;
  border: 1px solid rgba(22,163,74,.3);
  width: 100%;
  justify-content: center;
  font-size: 12px;
  cursor: default;
}

.drive-btn-connected:hover {
  background: rgba(220,38,38,.15);
  color: #f87171;
  border-color: rgba(220,38,38,.3);
  cursor: pointer;
}

.drive-status-text {
  font-size: 10px;
  color: #475569;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== TOAST NOTIFICATIONS ===== */
.drive-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 380px;
  animation: slideIn .2s ease;
}

@keyframes slideIn {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.toast-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.toast-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.toast-warn    { background: #fefce8; color: #92400e; border: 1px solid #fde68a; }
.toast-info    { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* ===== UTILS ===== */
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-small { font-size: 12px; }
.font-bold { font-weight: 700; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
