/* ============================================================
   Eximet · Sistema de Gestión de Chatarra
   Hoja de estilos principal
   ============================================================ */

:root {
  --bg-base:       #f1f5f9;
  --bg-sidebar:    #ffffff;
  --bg-card:       #ffffff;
  --bg-input:      #f8fafc;
  --bg-hover:      #f1f5f9;
  --border:        #e2e8f0;
  --border-light:  #cbd5e1;

  --accent:        #d97706;
  --accent-dim:    #92400e;
  --accent-light:  #f59e0b;
  --accent-glow:   rgba(217,119,6,.12);

  --text-1:        #0f172a;
  --text-2:        #475569;
  --text-3:        #94a3b8;

  --green:         #16a34a;
  --green-bg:      rgba(22,163,74,.08);
  --red:           #dc2626;
  --red-bg:        rgba(220,38,38,.08);
  --blue:          #2563eb;
  --blue-bg:       rgba(37,99,235,.08);
  --yellow:        #d97706;

  --sidebar-w:     252px;
  --header-h:      60px;
  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 4px 24px rgba(0,0,0,.4);
  --transition:    .18s ease;
}

/* ─── Reset ──────────────────────────────────────────────── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  background: var(--bg-base);
  color: var(--text-1);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-light); }
img { display: block; max-width: 100%; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
table { border-collapse: collapse; width: 100%; }

/* ─── Layout ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  box-shadow: 1px 0 0 var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.main-wrap {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
  padding: 28px 32px;
}

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo .logo-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 16px var(--accent-glow);
}

.sidebar-logo .logo-text {
  display: flex; flex-direction: column;
  line-height: 1.2;
}
.sidebar-logo .logo-text strong {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: .5px;
}
.sidebar-logo .logo-text span {
  font-size: .72rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 10px;
}

.nav-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-3);
  padding: 8px 10px 4px;
  margin-top: 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: .88rem;
  font-weight: 500;
  transition: var(--transition);
  margin-bottom: 2px;
  cursor: pointer;
}

.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .75; }
.nav-link:hover { background: var(--bg-hover); color: var(--text-1); }
.nav-link:hover svg { opacity: 1; }
.nav-link.active {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(217,119,6,.2);
}
.nav-link.active svg { opacity: 1; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: .75rem;
  color: var(--text-3);
}

/* ─── Topbar ─────────────────────────────────────────────── */
.topbar {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: #ffffff;
  position: sticky; top: 0; z-index: 50;
}

.topbar-title h1 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-1);
}
.topbar-title p {
  font-size: .75rem;
  color: var(--text-3);
  line-height: 1;
}

.topbar-actions { display: flex; gap: 10px; align-items: center; }

/* ─── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.card-sm { padding: 16px 20px; }
.card-title {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-3);
  margin-bottom: 4px;
}

/* ─── KPI Cards ──────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}
.kpi-card:hover { border-color: var(--border-light); transform: translateY(-1px); }

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--kpi-color, var(--accent));
}

.kpi-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-3);
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-1);
  line-height: 1;
}

.kpi-sub {
  font-size: .78rem;
  color: var(--text-3);
}

.kpi-icon {
  position: absolute;
  top: 18px; right: 18px;
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.04);
  font-size: 18px;
}

/* ─── Grid layout helpers ────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.row { display: flex; gap: 20px; flex-wrap: wrap; }
.col { flex: 1; min-width: 0; }

/* ─── Section ────────────────────────────────────────────── */
.section { margin-bottom: 28px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text-1);
}
.section-sub {
  font-size: .78rem;
  color: var(--text-3);
  margin-top: 2px;
}

/* ─── Table ──────────────────────────────────────────────── */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table { width: 100%; }

.data-table thead tr {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  padding: 11px 16px;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-3);
  text-align: left;
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  font-size: .875rem;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f8fafc; }

.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table th.num { text-align: right; }

.data-table td.positive { color: var(--green); font-weight: 600; }
.data-table td.negative { color: var(--red); font-weight: 600; }
.data-table td.bold { color: var(--text-1); font-weight: 600; }

/* ─── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .3px;
  white-space: nowrap;
}

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--accent);
  color: #000;
}
.btn-primary:hover { background: var(--accent-light); color: #000; }

.btn-outline {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border-light);
}
.btn-outline:hover { background: var(--bg-hover); color: var(--text-1); border-color: var(--text-3); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-1); }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(239,68,68,.2);
}
.btn-danger:hover { background: rgba(239,68,68,.2); }

.btn-success {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid rgba(34,197,94,.2);
}
.btn-success:hover { background: rgba(34,197,94,.2); }

.btn-sm { padding: 5px 11px; font-size: .78rem; }
.btn-lg { padding: 11px 22px; font-size: .95rem; }
.btn-icon { padding: 7px; }

/* ─── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.form-hint {
  font-size: .75rem;
  color: var(--text-3);
  margin-top: 4px;
}

.form-control {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  color: var(--text-1);
  font-size: .88rem;
  transition: var(--transition);
  outline: none;
  -webkit-appearance: none;
}
.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-control::placeholder { color: var(--text-3); }
.form-control:disabled { opacity: .5; cursor: not-allowed; }

select.form-control {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.input-group {
  display: flex;
  gap: 8px;
}
.input-group .form-control { flex: 1; }

.input-addon {
  display: flex; align-items: center;
  padding: 0 12px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-3);
  font-size: .85rem;
  white-space: nowrap;
}

/* ─── Form grid ──────────────────────────────────────────── */
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ─── Stat rows ──────────────────────────────────────────── */
.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.stat-row:last-child { border-bottom: none; }
.stat-row-label { font-size: .85rem; color: var(--text-2); }
.stat-row-value { font-size: .9rem; font-weight: 600; color: var(--text-1); font-variant-numeric: tabular-nums; }

/* ─── Progress bar ───────────────────────────────────────── */
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width .4s ease;
}

/* ─── Alerts ─────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  margin-bottom: 16px;
  border: 1px solid;
}
.alert-success { background: var(--green-bg); color: var(--green); border-color: rgba(34,197,94,.2); }
.alert-danger   { background: var(--red-bg);   color: var(--red);   border-color: rgba(239,68,68,.2); }
.alert-info     { background: var(--blue-bg);  color: var(--blue);  border-color: rgba(59,130,246,.2); }
.alert-warning  { background: rgba(245,158,11,.1); color: var(--yellow); border-color: rgba(245,158,11,.2); }

/* ─── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(3px);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: modalIn .2s ease;
}

.modal-lg { max-width: 720px; }

@keyframes modalIn {
  from { opacity: 0; transform: scale(.96) translateY(-8px); }
  to   { opacity: 1; transform: none; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-3); padding: 4px;
  border-radius: 4px;
  transition: var(--transition);
}
.modal-close:hover { color: var(--text-1); background: var(--bg-hover); }

.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ─── Divider ────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ─── Empty state ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: .9rem; }

/* ─── Tabs ───────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab-btn {
  padding: 9px 18px;
  background: none;
  border: none;
  color: var(--text-3);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: var(--transition);
}
.tab-btn:hover { color: var(--text-2); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ─── Calculator specific ────────────────────────────────── */
.calc-result-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.calc-main-result {
  text-align: center;
  padding: 20px;
}

.calc-result-label { font-size: .8rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .7px; }
.calc-result-big {
  font-size: 2.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin: 6px 0;
}
.calc-result-big.positive { color: var(--green); }
.calc-result-big.negative { color: var(--red); }
.calc-result-sub { font-size: .85rem; color: var(--text-3); }

/* ─── Chart container ────────────────────────────────────── */
.chart-container {
  position: relative;
  height: 260px;
}
.chart-container-sm { height: 180px; }

/* ─── Material legend ────────────────────────────────────── */
.mat-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.mat-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  color: var(--text-2);
}
.mat-legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ─── Flujo timeline ─────────────────────────────────────── */
.timeline { list-style: none; position: relative; padding-left: 24px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 7px; top: 0; bottom: 0;
  width: 2px;
  background: var(--border);
}
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-item::before {
  content: '';
  position: absolute;
  left: -20px; top: 6px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-base);
}
.timeline-date { font-size: .75rem; color: var(--text-3); margin-bottom: 4px; }
.timeline-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: .85rem;
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
  .main-wrap { margin-left: 0; }
  .main-content { padding: 20px 16px; }
  .topbar { padding: 0 16px; }
  .form-grid-2, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

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

/* ─── Utility ────────────────────────────────────────────── */
.text-green  { color: var(--green)  !important; }
.text-red    { color: var(--red)    !important; }
.text-accent { color: var(--accent) !important; }
.text-muted  { color: var(--text-3) !important; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.fw-700      { font-weight: 700; }
.mt-4        { margin-top: 4px; }
.mt-8        { margin-top: 8px; }
.mt-16       { margin-top: 16px; }
.mt-24       { margin-top: 24px; }
.mb-8        { margin-bottom: 8px; }
.mb-16       { margin-bottom: 16px; }
.mb-24       { margin-bottom: 24px; }
.flex        { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8       { gap: 8px; }
.gap-12      { gap: 12px; }
.gap-16      { gap: 16px; }
.d-none      { display: none; }
.w-100       { width: 100%; }

/* ─── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ─── Loading spinner ────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Number highlight in forms ─────────────────────────── */
.form-control[type="number"] { text-align: right; }
.result-highlight {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  text-align: right;
  font-variant-numeric: tabular-nums;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
