/* ===================================================
   MisMáquinas — Estilos principales
   =================================================== */

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

:root {
  --bg-primary:    #ffffff;
  --bg-secondary:  #f5f5f3;
  --bg-tertiary:   #eeede9;
  --text-primary:  #1a1a18;
  --text-secondary:#6b6b66;
  --text-hint:     #a0a09b;
  --border:        rgba(0,0,0,0.10);
  --border-med:    rgba(0,0,0,0.18);
  --blue:          #185FA5;
  --blue-light:    #E6F1FB;
  --blue-dark:     #0C447C;
  --green:         #3B6D11;
  --green-light:   #EAF3DE;
  --red:           #A32D2D;
  --red-light:     #FCEBEB;
  --amber:         #854F0B;
  --amber-light:   #FAEEDA;
  --purple:        #534AB7;
  --purple-light:  #EEEDFE;
  --radius-sm:     6px;
  --radius-md:     8px;
  --radius-lg:     12px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:     0 4px 16px rgba(0,0,0,0.10);
}

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

/* ---- Tipografía ---- */
h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 18px; font-weight: 500; }
h3 { font-size: 15px; font-weight: 500; }
p  { line-height: 1.6; }

/* ---- Layout ---- */
.container { max-width: 1100px; margin: 0 auto; padding: 0 1rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }

@media (max-width: 700px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ---- Cards ---- */
.card {
  background: var(--bg-primary);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
}
.card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 1rem;
}
.metric-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 1rem;
}
.metric-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.metric-value {
  font-size: 22px;
  font-weight: 600;
}

/* ---- Navbar ---- */
.navbar {
  background: var(--bg-primary);
  border-bottom: 0.5px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.navbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 54px;
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
}
.navbar-brand .icon {
  width: 32px; height: 32px;
  background: var(--blue-light);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
}
.nav-btn {
  background: transparent;
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.nav-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }
.nav-btn.active { background: var(--bg-secondary); color: var(--text-primary); }
.navbar-user {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.user-chip {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  padding: 4px 10px;
  border-radius: 20px;
  width: 100%;
  text-align: center;
}

/* ---- Buttons ---- */
button {
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border-radius: var(--radius-md);
  padding: 8px 16px;
  border: 0.5px solid var(--border-med);
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  font-weight: 500;
}
button:hover { background: var(--bg-secondary); }
button:active { transform: scale(0.98); }

button.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
button.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }

button.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
button.btn-danger:hover { background: #791F1F; }

button.btn-success { background: var(--green); color: #fff; border-color: var(--green); }
button.btn-success:hover { background: #27500A; }

button.btn-sm { font-size: 12px; padding: 5px 10px; }
button.btn-full { width: 100%; }
button.btn-icon { padding: 6px 8px; font-size: 14px; }

/* ---- Inputs & Forms ---- */
input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 0.5px solid var(--border-med);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  width: 100%;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(24,95,165,0.10);
}
textarea { resize: vertical; min-height: 70px; }

.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* ---- Badges ---- */
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.badge-info    { background: var(--blue-light);   color: var(--blue-dark); }
.badge-success { background: var(--green-light);  color: var(--green); }
.badge-warn    { background: var(--amber-light);  color: var(--amber); }
.badge-danger  { background: var(--red-light);    color: var(--red); }
.badge-purple  { background: var(--purple-light); color: var(--purple); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: left;
  padding: 8px 12px;
  border-bottom: 0.5px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
td {
  padding: 9px 12px;
  border-bottom: 0.5px solid var(--border);
  color: var(--text-primary);
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-secondary); }

/* ---- Alerts ---- */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 12px;
}
.alert-danger  { background: var(--red-light);   color: var(--red); }
.alert-success { background: var(--green-light); color: var(--green); }
.alert-info    { background: var(--blue-light);  color: var(--blue-dark); }

/* ---- Divider ---- */
hr { border: none; border-top: 0.5px solid var(--border); margin: 1rem 0; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.40);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  padding: 1.5rem;
  width: 100%; max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close {
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--text-secondary);
  padding: 2px 6px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { background: var(--bg-secondary); }

/* ---- Login page ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  padding: 2rem;
}
.login-box { width: 100%; max-width: 360px; }
.login-logo {
  text-align: center;
  position: relative;
  z-index: 1;
  margin-bottom: 0;
}
.login-logo .logo-icon {
  width: clamp(160px, 55vw, 290px);
  height: clamp(160px, 55vw, 290px);
  border-radius: 24px;
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto -50px;
  overflow: hidden;
  filter: drop-shadow(0 8px 24px rgba(0,0,0,0.18));
}
.login-logo .logo-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.login-logo h1 { font-size: 22px; margin-bottom: 4px; }
.login-logo p  { font-size: 13px; color: var(--text-secondary); }
.login-box .card { padding-top: 68px; }
.login-hint {
  font-size: 11px;
  color: var(--text-hint);
  text-align: center;
  margin-top: 12px;
  line-height: 1.6;
}

/* ---- Dashboard ---- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}
.page-title { font-size: 16px; font-weight: 600; margin: 0; }

.machine-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 0.5px solid var(--border);
}
.machine-row:last-child { border-bottom: none; }

/* ---- Machine details dropdown ---- */
.machine-details { border-bottom: 0.5px solid var(--border); }
.machine-details:last-child { border-bottom: none; }
.machine-details summary.machine-row { border-bottom: none; cursor: pointer; user-select: none; }
.machine-details summary::-webkit-details-marker { display: none; }
.machine-details summary { list-style: none; }
.machine-details-chevron { font-size: 14px; color: var(--text-secondary); transition: transform 0.2s; display: inline-block; }
.machine-details[open] .machine-details-chevron { transform: rotate(180deg); }
.machine-income-list { padding: 2px 0 8px 12px; }
.machine-income-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  padding: 3px 4px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}
.machine-income-row:hover { background: var(--bg-secondary); }
.machine-income-row span:last-child { color: var(--blue); font-weight: 600; }

/* ---- Selector de imagen de máquina ---- */
.img-picker-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}
.img-picker-tile:hover {
  border-color: var(--blue);
}
.img-picker-tile.img-picker-selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.income-preview {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.income-preview-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}

/* ---- Liquidación ---- */
.liquidacion-table td { padding: 10px 12px; }
.liquidacion-total {
  background: var(--bg-secondary);
  font-weight: 600;
}
.comp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 640px) {
  .comp-grid { grid-template-columns: 1fr; }
}
.comp-prev-card { opacity: 0.8; }
.delta-up   { color: var(--green); font-size: 11px; margin-left: 4px; font-weight: 600; }
.delta-down { color: var(--red);   font-size: 11px; margin-left: 4px; font-weight: 600; }

/* ---- Toasts ---- */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
}
.toast {
  background: var(--text-primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
}
@keyframes slideIn {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ---- Utility ---- */
.text-blue   { color: var(--blue); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-amber  { color: var(--amber); }
.text-purple { color: var(--purple); }
.text-muted  { color: var(--text-secondary); }
.text-right  { text-align: right; }
.font-600    { font-weight: 600; }
.font-500    { font-weight: 500; }
.mt-1  { margin-top: 0.5rem; }
.mt-2  { margin-top: 1rem; }
.mt-3  { margin-top: 1.5rem; }
.mb-1  { margin-bottom: 0.5rem; }
.mb-2  { margin-bottom: 1rem; }
.mb-3  { margin-bottom: 1.5rem; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 12px; }
.flex  { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center  { display: flex; justify-content: center; align-items: center; }
.flex-end     { display: flex; justify-content: flex-end; align-items: center; }
.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 3rem 1rem;
  font-size: 13px;
}
.empty-state .icon { font-size: 32px; margin-bottom: 8px; }

/* ===================================================
   Mejoras UI — v2
   =================================================== */

/* --- Navbar: active mejorado --- */
.nav-btn.active {
  background: var(--blue-light);
  color: var(--blue);
}
.nav-btn-label { /* se oculta en móvil */ }
@media (max-width: 600px) {
  .nav-btn-label { display: none; }
  .nav-btn       { padding: 6px 9px; font-size: 17px; }
}

/* --- Metric cards con acento de color --- */
.metric-card { position: relative; padding-top: 14px; }
.mc-blue   { border-top: 3px solid var(--blue); }
.mc-red    { border-top: 3px solid var(--red); }
.mc-green  { border-top: 3px solid var(--green); }
.mc-purple { border-top: 3px solid var(--purple); }
.metric-icon { font-size: 17px; margin-bottom: 5px; line-height: 1; }
.metric-value { font-size: 20px; }

/* --- Status dot --- */
.status-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
  position: relative; top: -1px;
  flex-shrink: 0;
}
.dot-activa {
  background: var(--green);
  animation: dotPulse 2.4s ease-in-out infinite;
}
.dot-mantenimiento { background: var(--amber); }
.dot-inactiva      { background: #b0b0a8; }
@keyframes dotPulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(59,109,17,0.22); }
  50%       { box-shadow: 0 0 0 5px rgba(59,109,17,0);    }
}

/* --- Modal: animación de entrada --- */
.modal {
  animation: modalSlideIn 0.22s cubic-bezier(0.34, 1.5, 0.64, 1);
}
@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)     scale(1);    }
}

/* --- Toast mejorado con icono --- */
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 200px;
  max-width: 320px;
}
.toast-icon { font-size: 15px; flex-shrink: 0; }
.toast-success { background: #2e6b0e !important; }
.toast-error   { background: #b83030 !important; }
.toast-info    { background: var(--blue) !important; }

/* --- Period tabs --- */
.period-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 3px;
  border: 0.5px solid var(--border);
}
.period-tab {
  background: transparent;
  border: none;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 5px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}
.period-tab:hover  { color: var(--text-primary); }
.period-tab.active {
  background: var(--bg-primary);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* --- Confirm dialog --- */
.confirm-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 400;
  padding: 1rem;
  animation: fadeIn 0.14s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.confirm-box {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  padding: 2rem 1.75rem 1.5rem;
  width: 100%; max-width: 340px;
  text-align: center;
  box-shadow: var(--shadow-md);
  animation: modalSlideIn 0.22s ease;
}
.confirm-box .warn-icon { font-size: 36px; margin-bottom: 12px; }
.confirm-box h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.confirm-box p  { font-size: 13px; color: var(--text-secondary); margin-bottom: 1.5rem; line-height: 1.55; }
.confirm-actions { display: flex; gap: 8px; justify-content: center; }

/* --- View fade-in --- */
.view-fade {
  animation: viewFade 0.18s ease;
}
@keyframes viewFade {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- Scrollbar fino --- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.18); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.28); }

/* --- Machine row hover --- */
.machine-row { transition: background 0.1s; border-radius: var(--radius-sm); }
.machine-row:hover { background: var(--bg-secondary); }

/* --- File upload zone --- */
.file-upload-zone {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1.5px dashed var(--border-med);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--bg-secondary);
  user-select: none;
}
.file-upload-zone:hover {
  border-color: var(--blue);
  background: var(--blue-light);
}
.file-upload-zone--selected {
  border-color: var(--green);
  background: var(--green-light);
}
.file-upload-icon { font-size: 18px; flex-shrink: 0; }
.file-upload-text { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-upload-zone--selected .file-upload-text { color: var(--green); font-weight: 500; }

/* --- Receipt link in expenses table --- */
.receipt-link { font-size: 18px; text-decoration: none; cursor: pointer; transition: opacity 0.15s; }
.receipt-link:hover { opacity: 0.7; }
.receipt-none { font-size: 13px; color: var(--text-hint); }
