:root {
  --primary-color: #4a90e2;
  --secondary-color: #50e3c2;
  --background-color: #f4f7f6;
  --card-background: #ffffff;
  --text-color: #333;
  --light-text-color: #777;
  --border-radius: 8px;
  --shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; }

body {
  font-family: 'Montserrat', system-ui, sans-serif;
  margin: 0; padding: 0;
  background-color: var(--background-color);
  color: var(--text-color);
  display: flex; justify-content: center; align-items: center;
  min-height: 100vh;
}
body.modo-dashboard { display: block; align-items: stretch; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideInLeft { from { transform: translateX(-50px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideInRight { from { transform: translateX(50px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===================== LOGIN ===================== */
.login-container {
  background: linear-gradient(135deg, var(--primary-color) 0%, #63c8e2 100%);
  padding: 40px; border-radius: var(--border-radius);
  box-shadow: var(--shadow); width: 90%; max-width: 900px;
  display: flex; justify-content: center; align-items: center;
  overflow: hidden; position: relative; animation: fadeIn 1s ease-out;
}
.login-box {
  display: flex; width: 100%; max-width: 800px;
  background-color: var(--card-background);
  border-radius: var(--border-radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15); overflow: hidden;
}
.login-form {
  flex: 1; padding: 50px 40px; display: flex; flex-direction: column;
  justify-content: center; text-align: center; animation: slideInLeft .8s ease-out forwards;
}
.login-form h2 { margin: 0 0 12px; color: var(--primary-color); font-weight: 700; font-size: 1.7em; }
.login-form p { margin: 0 0 26px; color: var(--light-text-color); font-size: .95em; }

.input-group {
  position: relative; margin-bottom: 22px; display: flex; align-items: center;
  border-bottom: 2px solid #ddd; transition: border-bottom-color .3s ease;
}
.input-group:focus-within { border-bottom-color: var(--primary-color); }
.input-group i { position: absolute; left: 8px; font-style: normal; font-size: 1.05em; opacity: .75; }
.input-group input {
  flex-grow: 1; padding: 12px 12px 12px 38px; border: none; background: transparent;
  outline: none; font-family: inherit; font-size: 1em; color: var(--text-color); width: 100%;
}
input::placeholder { color: var(--light-text-color); }

.login-form button {
  background: linear-gradient(90deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  color: #fff; border: none; padding: 14px 25px; border-radius: 5px;
  font-family: inherit; font-weight: 600; font-size: 1.05em; cursor: pointer;
  transition: all .3s ease; margin-top: 6px; box-shadow: 0 5px 15px rgba(74,144,226,.3);
}
.login-form button:hover { box-shadow: 0 8px 20px rgba(74,144,226,.5); transform: translateY(-2px); }
.login-form button:disabled { opacity: .65; cursor: wait; transform: none; }

.error-message {
  color: #e74c3c; font-size: .82em !important; margin-top: 14px !important;
  margin-bottom: 0 !important; min-height: 20px; white-space: pre-wrap; text-align: left;
}
.api-hint { font-size: .68em !important; color: #b0b8c0 !important; margin: 10px 0 0 !important; word-break: break-all; }

.login-image {
  flex: 1; display: flex; justify-content: center; align-items: center;
  background: linear-gradient(160deg, #4a90e2 0%, #3b6fb5 100%);
  animation: slideInRight .8s ease-out forwards;
}
.login-art { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding: 0 30px; position: relative; }
.login-art .bar { width: 26px; border-radius: 6px 6px 0 0; background: rgba(255,255,255,.85); }
.login-art .b1 { height: 45%; } .login-art .b2 { height: 70%; }
.login-art .b3 { height: 55%; background: var(--secondary-color); } .login-art .b4 { height: 92%; }
.login-art p {
  position: absolute; bottom: -42px; left: 0; right: 0; text-align: center;
  color: rgba(255,255,255,.9); font-size: .8em; letter-spacing: .5px; margin: 0;
}

/* ===================== DASHBOARD ===================== */
.dashboard-container {
  width: 100%; min-height: 100vh; display: flex; flex-direction: column;
  background-color: var(--background-color); animation: fadeIn .8s ease-out forwards;
}
.dashboard-header {
  background-color: var(--card-background); padding: 14px 24px;
  box-shadow: 0 2px 10px rgba(0,0,0,.05); display: flex;
  justify-content: space-between; align-items: center; border-bottom: 1px solid #eee;
  position: sticky; top: 0; z-index: 20;
}
.dashboard-header h1 { margin: 0; color: var(--primary-color); font-size: 1.15em; font-weight: 600; }
.header-actions button {
  background-color: var(--secondary-color); color: #0b4a3f; border: none;
  padding: 9px 15px; border-radius: 5px; font-family: inherit; font-weight: 600;
  font-size: .85em; cursor: pointer; transition: all .25s ease; margin-left: 8px;
}
.header-actions button:hover { filter: brightness(1.06); transform: translateY(-1px); }
#logoutBtn { background-color: #e74c3c; color: #fff; }
#logoutBtn:hover { background-color: #d63021; }

.dashboard-main { flex-grow: 1; overflow-y: auto; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; padding: 18px 24px 6px; }
.kpi { background: #fff; border-radius: 12px; padding: 14px 16px; border: 1px solid #e5e7eb; box-shadow: 0 1px 4px rgba(0,0,0,.04); }
.kpi .v { font-size: 26px; font-weight: 700; color: var(--primary-color); }
.kpi .l { font-size: 11px; color: #666; text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }
.kpi.rojo .v { color: #b91c1c; }

.filtros { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 24px; align-items: center; }
.filtros input, .filtros select {
  padding: 8px 10px; border: 1px solid #ccc; border-radius: 8px;
  font-size: 13px; font-family: inherit; background: #fff;
}
.filtros button {
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--primary-color);
  background: var(--primary-color); color: #fff; cursor: pointer; font-size: 13px; font-family: inherit;
}
.filtros button.sec { background: #fff; color: var(--primary-color); }
.filtros label { font-size: 13px; display: flex; gap: 6px; align-items: center; }

.turno-resumen { display: flex; gap: 12px; padding: 4px 24px 0; flex-wrap: wrap; }
.turno-chip { background: #fff; border: 1px solid #e5e7eb; border-radius: 10px; padding: 10px 16px; font-size: 13px; }
.turno-chip b { font-size: 17px; color: var(--primary-color); }

.heat-wrap { overflow-x: auto; padding: 12px 24px; }
table.heat { border-collapse: collapse; background: #fff; font-size: 11px; min-width: 100%; }
table.heat th, table.heat td { border: 1px solid #eee; padding: 4px 6px; text-align: center; }
table.heat th { background: #fafafa; font-size: 10px; text-transform: uppercase; color: #555; }
table.heat td.fecha { text-align: left; white-space: nowrap; background: #fafafa; font-weight: 600; }
table.heat th.t1 { background: #dbeafe; color: #1e40af; }
table.heat th.t2 { background: #ffedd5; color: #9a3412; }

.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 0 24px; }
@media (max-width: 900px) { .charts { grid-template-columns: 1fr; } }
.chart { background: #fff; border-radius: 12px; padding: 14px; border: 1px solid #e5e7eb; }
.chart h4 { font-size: 13px; margin: 0 0 8px; color: #333; }
.no-charts { padding: 0 24px; color: #a16207; font-size: 13px; }

.detalle-titulo { padding: 18px 24px 8px; font-size: 14px; color: #333; margin: 0; }
.detalle-titulo span { color: #888; font-weight: 400; font-size: 12px; }

.wrap { overflow-x: auto; max-height: 480px; margin: 0 24px 24px; border: 1px solid #e5e7eb; border-radius: 12px; background: #fff; }
.data-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.data-table th, .data-table td { padding: 8px 10px; border-bottom: 1px solid #eee; text-align: left; white-space: nowrap; }
.data-table th { background: #fafafa; font-size: 11px; text-transform: uppercase; color: #555; position: sticky; top: 0; }

.badge { font-size: 11px; padding: 2px 8px; border-radius: 12px; font-weight: 600; }
.ABIERTA { background: #fee2e2; color: #b91c1c; }
.EN { background: #fef9c3; color: #a16207; }
.CERRADA { background: #dcfce7; color: #15803d; }
.FUERA { background: #fee2e2; color: #b91c1c; }
.ENT { background: #dcfce7; color: #15803d; }

.obsbtn { background: none; border: 1px solid #ccc; border-radius: 6px; padding: 3px 8px; cursor: pointer; font-size: 12px; }
.obsbtn:hover { background: #f1f5f9; }

dialog { border: none; border-radius: 12px; padding: 20px; max-width: 420px; width: 92%; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h4 { margin: 0 0 10px; }
dialog textarea { width: 100%; height: 80px; padding: 10px; border: 1px solid #ccc; border-radius: 8px; font-size: 14px; font-family: inherit; }
dialog .botones { display: flex; gap: 10px; margin-top: 12px; }
dialog button { flex: 1; padding: 11px; border-radius: 8px; border: none; cursor: pointer; font-size: 14px; font-family: inherit; }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 768px) {
  .login-box { flex-direction: column; }
  .login-form { order: 2; width: 100%; padding: 32px 24px; }
  .login-image { order: 1; width: 100%; height: 190px; }
  .login-container { padding: 20px; }
  .dashboard-header { flex-direction: column; padding: 12px; gap: 10px; }
  .header-actions { display: flex; flex-wrap: wrap; justify-content: center; }
  .header-actions button { margin: 4px; }
}

/* ===================== IMPRESIÓN ===================== */
@media print {
  .dashboard-header, .filtros, .obsbtn, .heat-wrap, #zonaAnalisis .charts { display: none !important; }
  body { background: #fff; }
  .wrap { max-height: none; border: none; margin: 0; }
}
