*,*::before,*::after { box-sizing: border-box; }
:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --danger: #f87171;
  --ok: #34d399;
  --border: #334155;
}
html,body { margin:0; padding:0; height:100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

/* ------- Layout app ------- */
.app {
  max-width: 900px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex; flex-direction: column;
}
.topbar {
  display:flex; align-items:center; justify-content:space-between;
  padding: 14px 16px; background: var(--panel); border-bottom:1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 16px; margin: 0; }
.topbar .actions { display:flex; gap:8px; }
.icon-btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
.icon-btn.primary { background: var(--accent); color: #0f172a; border-color: var(--accent); font-weight: 600; }
.icon-btn.danger { color: var(--danger); }

.tabs {
  display:flex; gap: 4px; padding: 10px 16px; overflow-x:auto; background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.tabs button {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; white-space: nowrap;
}
.tabs button.active { color: var(--text); background: var(--panel-2); border-color: var(--panel-2); }

.view { padding: 12px 14px 90px; }

/* ------- Login ------- */
.login {
  min-height: 100vh; display:flex; flex-direction:column; align-items:center; justify-content:center;
  padding: 24px;
}
.login h1 { font-size: 20px; margin-bottom: 4px; }
.login p { color: var(--muted); margin: 0 0 24px; }
.pin-display {
  display:flex; gap: 10px; margin-bottom: 20px;
}
.pin-dot {
  width: 16px; height: 16px; border-radius: 50%; border:2px solid var(--border);
}
.pin-dot.filled { background: var(--accent); border-color: var(--accent); }
.keypad {
  display: grid; grid-template-columns: repeat(3, 68px); gap: 12px;
}
.keypad button {
  width: 68px; height: 68px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font-size: 22px;
}
.keypad button:active { background: var(--panel-2); }
.keypad button.wide { background: transparent; border-color: transparent; font-size: 16px; }
.error-msg { color: var(--danger); margin-top: 16px; min-height: 18px; font-size: 13px; }

/* ------- Calendario semanal ------- */
.week-list { display:flex; flex-direction:column; gap: 8px; }
.day-row {
  background: var(--panel); border:1px solid var(--border); border-radius: 10px;
  padding: 10px 12px;
}
.day-row .date { display:flex; justify-content:space-between; align-items:center; margin-bottom: 6px; }
.day-row .date strong { font-size: 14px; }
.day-row .date .num { color: var(--muted); font-size: 12px; }
.day-row.today .date strong { color: var(--accent); }
.shift-chip {
  display:flex; align-items:center; gap: 8px;
  background: var(--panel-2); border-radius: 6px; padding: 6px 8px; margin-top: 4px;
  font-size: 13px;
}
.shift-chip .swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.shift-chip .time { color: var(--muted); font-size: 12px; margin-left:auto; }
.shift-chip.empty { color: var(--muted); font-style: italic; background: transparent; padding-left: 0; }
.day-row button.add {
  margin-top: 8px; width:100%; background: transparent; color: var(--accent);
  border: 1px dashed var(--border); border-radius: 6px; padding: 6px; font-size: 13px;
}

/* ------- Mes / Trimestre grid ------- */
.month-grid-wrapper { margin-bottom: 16px; }
.month-grid-wrapper h3 { margin: 8px 4px; font-size: 14px; color: var(--muted); }
.month-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px;
}
.dow {
  text-align:center; font-size: 10px; color: var(--muted); padding: 4px 0;
}
.cell {
  aspect-ratio: 1; background: var(--panel); border: 1px solid var(--border); border-radius: 5px;
  padding: 3px; font-size: 10px; display:flex; flex-direction: column; gap: 2px;
  min-height: 40px; position: relative;
}
.cell.out { opacity: 0.25; }
.cell.today { outline: 2px solid var(--accent); }
.cell .num { color: var(--muted); font-size: 10px; }
.cell .bars { display:flex; flex-direction: column; gap: 1px; flex:1; }
.cell .bar { height: 4px; border-radius: 2px; }

/* ------- Modal ------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 50;
  display:flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--panel); color: var(--text); width: 100%; max-width: 540px;
  border-radius: 16px 16px 0 0; padding: 16px; max-height: 85vh; overflow-y: auto;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 16px; max-height: 80vh; }
}
.modal h2 { margin: 0 0 12px; font-size: 16px; }
.modal .row { display:flex; gap: 10px; margin-bottom: 10px; }
.modal label { display:block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.modal input[type=text], .modal input[type=time], .modal input[type=date],
.modal input[type=password], .modal select, .modal textarea {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; font-size: 14px;
}
.modal textarea { min-height: 72px; resize: vertical; }
.modal input[type=color] { width: 60px; height: 40px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); padding: 0; }
.modal .actions { display:flex; gap: 8px; justify-content:flex-end; margin-top: 14px; }
.modal .actions button { min-width: 90px; }

.field { flex: 1; }

/* ------- Tipos turno ------- */
.type-list { display:flex; flex-direction: column; gap: 8px; }
.type-row {
  display:flex; align-items:center; gap: 10px;
  background: var(--panel); border:1px solid var(--border); border-radius: 8px; padding: 10px;
}
.type-row .swatch { width: 24px; height: 24px; border-radius: 5px; flex-shrink: 0; }
.type-row .info { flex: 1; }
.type-row .info .name { font-size: 14px; }
.type-row .info .time { font-size: 12px; color: var(--muted); }
.type-row .btns { display: flex; gap: 6px; }

/* ------- Utilidades ------- */
.stack { display:flex; flex-direction: column; gap: 10px; }
.inline { display:flex; gap: 8px; align-items:center; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 13px; }
.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); color: var(--text); padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--border); z-index: 100; font-size: 13px;
}
.toast.err { border-color: var(--danger); color: var(--danger); }
.toast.ok { border-color: var(--ok); color: var(--ok); }
