:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-subtle: #f1f5f9;
  --line: #d8e0ea;
  --line-strong: #b9c5d4;
  --text: #172033;
  --muted: #64748b;
  --navy: #172554;
  --navy-soft: #22356f;
  --indigo: #3730a3;
  --teal: #0f766e;
  --teal-strong: #0d5f59;
  --green: #15803d;
  --green-soft: #dcfce7;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --shadow: 0 16px 36px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 4px 14px rgba(15, 23, 42, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "tnum" 1, "cv02" 1, "cv03" 1, "cv04" 1;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
}

.sidebar {
  background: var(--navy);
  color: #eef6ff;
  padding: 20px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 44px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #14b8a6;
  color: #ffffff;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(20, 184, 166, 0.28);
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #b6c5df;
  font-size: 13px;
}

.tabs {
  display: grid;
  gap: 6px;
}

.tab {
  display: flex;
  align-items: center;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #c8d3e8;
  text-align: left;
  text-decoration: none;
  padding: 0 12px;
  cursor: pointer;
}

.tab:hover,
.tab.active {
  background: var(--navy-soft);
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
  font-weight: 800;
}

h2 {
  font-size: 17px;
  font-weight: 800;
}

#pageMeta {
  min-height: 20px;
  margin: 4px 0 0;
  color: var(--muted);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 18px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.metric {
  padding: 16px;
  border-top: 3px solid transparent;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.metric strong {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.metric.warning strong {
  color: var(--amber);
}

.metric.money strong {
  color: var(--teal);
}

.metric.warning {
  border-top-color: var(--amber);
}

.metric.money {
  border-top-color: var(--teal);
}

.toolbar,
.top-actions,
.field-row {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.language-select {
  width: auto;
  min-width: 58px;
  min-height: 34px;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 800;
  background: #ffffff;
}

/* Top-actions (user chip + idioma + refresh + logout): compacto para no
   robar mas ancho del que necesita. */
.top-actions {
  gap: 6px;
  align-items: center;
}

.top-actions .button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 700;
}

#currentUserChip {
  display: inline-block;
  max-width: 180px;
  padding: 0 4px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar {
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow-soft);
}

.calendar-toolbar {
  align-items: center;
}

.month-title {
  min-width: 180px;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  text-align: center;
}

.split {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.stack {
  display: grid;
  gap: 18px;
}

.calendar-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(300px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.calendar-panel {
  min-width: 0;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.calendar-weekdays {
  gap: 6px;
  padding: 10px 12px 0;
}

.calendar-weekdays span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.calendar-grid {
  gap: 6px;
  padding: 12px;
}

.calendar-empty,
.calendar-day {
  min-height: 98px;
  border-radius: 8px;
}

.calendar-day {
  position: relative;
  display: grid;
  align-content: space-between;
  gap: 5px;
  width: 100%;
  border: 1px solid var(--line);
  padding: 9px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  background: #f8fafc;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.calendar-day:hover {
  border-color: var(--indigo);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.10);
  transform: translateY(-1px);
}

.calendar-day.covered {
  border-color: #86efac;
  background: var(--green-soft);
}

.calendar-day.mine {
  border-color: #93c5fd;
  background: #dbeafe;
}

.calendar-day.mine.colleague-too::after {
  content: "";
  position: absolute;
  inset: 0;
  border-right: 6px solid #86efac;
  border-bottom: 6px solid #86efac;
  border-top: 6px solid transparent;
  border-left: 6px solid transparent;
  border-radius: 0 0 8px 0;
  pointer-events: none;
}

.calendar-day.colleague {
  border-color: #86efac;
  background: var(--green-soft);
}

.calendar-legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 10px;
  font-size: 12px;
}

.legend-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 4px;
}

.legend-mine {
  background: #dbeafe;
  border: 1px solid #93c5fd;
}

.legend-other {
  background: var(--green-soft);
  border: 1px solid #86efac;
}

.calendar-day.uncovered {
  border-color: #fecaca;
  background: var(--red-soft);
}

.calendar-day.not-required {
  background: #f8fafc;
}

.calendar-day.selected {
  outline: 3px solid var(--indigo);
  outline-offset: 0;
}

.calendar-day.today .day-number {
  background: var(--indigo);
  color: #ffffff;
}

.day-number {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.day-status,
.day-count {
  display: block;
  font-size: 12px;
}

.day-status {
  font-weight: 800;
}

.day-count {
  color: var(--muted);
}

.vacation-mark {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.day-detail {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.day-detail h3 {
  margin: 0;
  font-size: 14px;
}

.detail-stat {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-subtle);
}

.detail-stat span {
  color: var(--muted);
  font-size: 12px;
}

.detail-stat strong {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.detail-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.detail-list li {
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.detail-list li span {
  color: var(--muted);
  font-size: 13px;
}

.detail-list .empty-line {
  color: var(--muted);
}

.quick-shift-form,
.quick-shift-empty {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-subtle);
}

.quick-shift-form h3 {
  margin: 0;
}

.quick-shift-empty {
  color: var(--muted);
}

.panel {
  overflow: hidden;
  /* Critico: en CSS Grid, sin min-width:0, el contenido fuerza al track
     a crecer hasta su min-content. Una <table min-width:680px> dentro
     hace que la pagina entera se vuelva mas ancha que el viewport.
     Con min-width:0 el .panel se ajusta al track y el .table-wrap
     se encarga del scroll horizontal por dentro. */
  min-width: 0;
}

/* Misma razon que arriba pero para cualquier hijo de una vista
   (toolbars, metrics, cards). Evita "tener que hacer zoom out". */
.view > * {
  min-width: 0;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.form-panel,
.settings-grid {
  padding: 16px;
}

.form-panel .panel-heading,
.settings-grid .panel-heading {
  padding: 0 0 14px;
  border-bottom: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  min-width: 150px;
}

.field-help {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 9px 10px;
  background: #ffffff;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(55, 48, 163, 0.12);
  outline: 0;
}

input[readonly] {
  background: #f1f5f9;
  color: #475569;
}

textarea {
  resize: vertical;
}

.form-panel {
  display: grid;
  gap: 12px;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkline input {
  width: auto;
}

.button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 13px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.button.primary {
  background: var(--teal);
  color: #ffffff;
}

.button.secondary {
  background: #ffffff;
  border-color: var(--line-strong);
  color: var(--text);
}

.button.danger {
  background: var(--red-soft);
  color: var(--red);
  border-color: #fecaca;
}

.button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.button:hover {
  filter: brightness(0.98);
}

.button.primary:hover {
  background: var(--teal-strong);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  background: #f8fafc;
}

tbody tr:hover {
  background: #f8fafc;
}

td:first-child,
td strong {
  font-weight: 700;
}

tr:last-child td {
  border-bottom: 0;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.badge.ok {
  background: var(--green-soft);
  color: var(--green);
}

.badge.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.off {
  background: #e2e8f0;
  color: #475569;
}

.muted {
  color: var(--muted);
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr);
  gap: 28px;
}

.settings-grid > div {
  display: grid;
  align-content: start;
  gap: 12px;
}

.day-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 10px;
}

.day-grid label {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--text);
  background: #ffffff;
}

.day-grid input {
  width: auto;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  background: var(--navy);
  color: #ffffff;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  z-index: 20;
}

.hidden {
  display: none !important;
}

.portal-view,
.portal-section.active {
  display: grid;
  gap: 18px;
}

.portal-section {
  display: none;
}

.portal-login {
  max-width: 520px;
}

.portal-login .form-panel {
  box-shadow: none;
}

.inline-hours {
  max-width: 120px;
}

/* ======================================================================
   Movil / PWA: layout tipo app nativa.
   - .sidebar pasa a ser BOTTOM TAB BAR fija (con safe-area-inset-bottom).
   - .topbar pasa a APP BAR sticky con titulo centrado, edge-to-edge.
   - Inputs 16px (evita zoom de iOS), tap targets 44px.
   - Tablas con scroll horizontal dentro de .table-wrap (no rompen layout).
   ====================================================================== */

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  /* ---- Bottom tab bar (era el sidebar lateral en desktop) ---- */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    z-index: 100;
    background: var(--surface);
    color: var(--text);
    border-top: 1px solid var(--line);
    border-right: 0;
    padding: 4px 6px max(4px, env(safe-area-inset-bottom));
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.06);
  }

  /* El icono PWA ya identifica la app; dentro estorba y roba sitio. */
  .sidebar .brand {
    display: none;
  }

  .tabs {
    display: flex;
    gap: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    flex: 1 0 auto;
    min-width: 72px;
    justify-content: center;
    min-height: 52px;
    padding: 6px 10px;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    text-align: center;
    font-size: 12px;
    font-weight: 650;
    line-height: 1.15;
    -webkit-tap-highlight-color: transparent;
  }

  .tab:hover {
    background: var(--surface-subtle);
    color: var(--text);
  }

  .tab.active,
  .tab.active:hover {
    background: transparent;
    color: var(--teal);
    font-weight: 800;
  }

  /* ---- App bar (topbar dentro de .main, sticky en lo alto) ---- */
  .main {
    padding: 14px 14px calc(72px + env(safe-area-inset-bottom));
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin: -14px -14px 14px;
    padding: max(12px, env(safe-area-inset-top) + 8px) 14px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    text-align: center;
  }

  .topbar > div:first-child {
    display: grid;
    gap: 2px;
  }

  .topbar h1 {
    font-size: 20px;
    font-weight: 800;
  }

  #pageMeta {
    font-size: 12px;
    min-height: 0;
  }

  .top-actions {
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
  }

  /* ---- Botones / inputs touch-friendly ---- */
  .button {
    min-height: 44px;
    white-space: normal;
    line-height: 1.2;
    padding: 8px 14px;
    -webkit-tap-highlight-color: transparent;
  }

  input,
  select,
  textarea {
    font-size: 16px;     /* iOS Safari no hace zoom al focar con >=16px. */
  }

  label,
  .month-title {
    min-width: 0;
  }

  .language-select {
    min-width: 64px;
  }

  /* ---- Grids internos colapsan a una columna ---- */
  .metrics,
  .split,
  .settings-grid,
  .calendar-layout {
    grid-template-columns: 1fr;
  }

  .metric {
    text-align: center;
    padding: 14px 12px;
  }

  .metric span {
    margin-bottom: 4px;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar > *:not(.button) {
    width: 100%;
  }

  .panel-heading {
    flex-wrap: wrap;
    min-height: 0;
    padding: 12px 14px;
  }

  /* ---- Calendario compacto pero usable ---- */
  .calendar-empty,
  .calendar-day {
    min-height: 72px;
  }

  .calendar-weekdays,
  .calendar-grid {
    gap: 3px;
  }

  .calendar-grid {
    padding: 6px;
  }

  .calendar-day {
    padding: 4px;
    gap: 2px;
  }

  .calendar-weekdays {
    padding: 8px 6px 0;
  }

  .calendar-weekdays span {
    font-size: 10px;
  }

  .day-number {
    width: 22px;
    height: 22px;
    font-size: 13px;
  }

  .day-status,
  .day-count {
    font-size: 10px;
  }

  /* ---- Tablas: ancho natural; el .table-wrap (overflow-x: auto) scrollea ---- */
  table {
    min-width: auto;
  }

  .detail-stat {
    grid-template-columns: 1fr;
    text-align: center;
  }
}

/* Movil compacto: aprieta padding y tamanos. */
@media (max-width: 560px) {
  .main {
    padding: 10px 10px calc(70px + env(safe-area-inset-bottom));
  }

  .topbar {
    margin: -10px -10px 12px;
    padding: max(10px, env(safe-area-inset-top) + 6px) 10px 10px;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .metrics {
    gap: 8px;
  }

  .panel-heading h2 {
    font-size: 15px;
  }

  .tab {
    font-size: 11px;
    min-height: 50px;
  }
}

/* Safe-areas laterales al body en cualquier viewport. El top y bottom los
   gestionan el .topbar sticky y la .sidebar fixed respectivamente,
   por eso aqui solo padding lateral (si lo pongo arriba/abajo se duplica). */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* PWA instalada: desactiva el bounce / pull-to-refresh raro. */
@media (display-mode: standalone) {
  body {
    overscroll-behavior-y: none;
  }
}

