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

:root {
  --accent: #0ea5e9;
  --accent-dark: #0284c7;
  --danger: #ef4444;
  --success: #10b981;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --header-h: 56px;
  --sidebar-w: 260px;
  --week-w: 62px;
  --row-h: 54px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* ─── LOGIN ─── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%); }

.login-card { background: var(--surface); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.12); padding: 48px 40px; width: 380px; max-width: 90vw; text-align: center; }

.login-logo { height: 64px; margin-bottom: 20px; }
.login-card h1 { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 32px; }

.form-group { text-align: left; margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.form-group input { width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 14px; transition: border-color .15s; outline: none; }
.form-group input:focus { border-color: var(--accent); }

.btn-primary { width: 100%; padding: 12px; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; transition: background .15s; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.error-msg { color: var(--danger); font-size: 13px; margin-bottom: 12px; padding: 8px 12px; background: #fef2f2; border-radius: 6px; }

/* ─── APP LAYOUT ─── */
#app { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.app-header { height: var(--header-h); background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 16px; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,.06); }

.header-logo { height: 32px; }
.header-title { font-size: 17px; font-weight: 700; color: var(--text); flex: 1; }
.header-title span { color: var(--accent); }

.year-nav { display: flex; align-items: center; gap: 8px; }
.btn-year { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 14px; color: var(--text); transition: background .1s; }
.btn-year:hover { background: var(--border); }
.year-display { font-weight: 600; min-width: 40px; text-align: center; }

.btn-logout { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 6px 14px; cursor: pointer; font-size: 13px; color: var(--text-muted); transition: all .15s; }
.btn-logout:hover { background: #fef2f2; border-color: var(--danger); color: var(--danger); }

/* ─── MAIN LAYOUT ─── */
.main-layout { display: flex; flex: 1; overflow: hidden; }

/* ─── SIDEBAR ─── */
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0; }

.sidebar-header { padding: 16px 16px 8px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }

.pendientes-list { flex: 1; overflow-y: auto; padding: 0 8px; }

.pendiente-item { padding: 10px 10px; margin-bottom: 4px; border-radius: 8px; cursor: pointer; transition: all .15s; border: 1.5px solid transparent; background: var(--bg); }
.pendiente-item:hover { background: #f0f9ff; border-color: #bae6fd; }
.pendiente-item.selected { background: #e0f2fe; border-color: var(--accent); }
.pendiente-item.selected .pi-nombre { color: var(--accent-dark); }
.pi-nombre { font-weight: 600; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pi-cliente { font-size: 12px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.no-pendientes { padding: 24px 16px; color: var(--text-muted); font-size: 13px; text-align: center; }
.no-pendientes span { display: block; font-size: 24px; margin-bottom: 8px; }

.sidebar-actions { padding: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.btn-add { width: 100%; padding: 8px 12px; border-radius: 7px; font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s; text-align: left; }
.btn-add.primary { background: var(--accent); color: #fff; border: none; }
.btn-add.primary:hover { background: var(--accent-dark); }
.btn-add.secondary { background: var(--bg); border: 1px solid var(--border); color: var(--text); }
.btn-add.secondary:hover { background: var(--border); }

.assign-hint { padding: 10px 12px; background: #fef3c7; border-top: 1px solid #fde68a; font-size: 12px; color: #92400e; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.assign-hint strong { flex: 1; font-size: 13px; }
.btn-cancel { background: none; border: none; cursor: pointer; color: #b45309; font-size: 12px; text-decoration: underline; }

/* ─── GRID WRAPPER ─── */
.grid-outer { flex: 1; overflow: auto; position: relative; }

/* ─── PLANNING GRID ─── */
.planning-grid { min-width: max-content; }

.grid-header-row { display: flex; position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 2px solid var(--border); box-shadow: 0 2px 4px rgba(0,0,0,.06); }

.equip-label { width: var(--sidebar-w); min-width: var(--sidebar-w); padding: 0 16px; display: flex; align-items: center; font-weight: 600; background: var(--surface); position: sticky; left: 0; z-index: 5; border-right: 1px solid var(--border); }

.grid-header-row .equip-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); height: 48px; }

.weeks-header { display: flex; }
.week-header-cell { width: var(--week-w); min-width: var(--week-w); height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; border-right: 1px solid var(--border); font-size: 11px; color: var(--text-muted); line-height: 1.3; padding: 4px 0; }
.week-header-cell.current-week { background: #e0f2fe; color: var(--accent-dark); font-weight: 700; }
.wh-num { font-size: 13px; font-weight: 700; }
.wh-date { font-size: 10px; }

/* ─── EQUIPO ROWS ─── */
.equipo-row { display: flex; border-bottom: 1px solid var(--border); }
.equipo-row .equip-label { height: var(--row-h); font-size: 13px; border-left: 4px solid var(--equip-color, #6b7280); position: sticky; left: 0; z-index: 4; background: var(--surface); }
.equip-color-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--equip-color, #6b7280); margin-right: 8px; flex-shrink: 0; }

.weeks-container { position: relative; display: flex; height: var(--row-h); }
.week-cell { width: var(--week-w); min-width: var(--week-w); height: var(--row-h); border-right: 1px solid var(--border); cursor: default; transition: background .1s; }
.week-cell.current-week { background: #f0f9ff; }
.planning-grid.assign-mode .week-cell { cursor: crosshair; }
.planning-grid.assign-mode .week-cell:hover { background: #dbeafe; }

/* ─── FAENA BLOCKS ─── */
.faena-block { position: absolute; top: 7px; height: 40px; border-radius: 7px; display: flex; align-items: center; padding: 0 10px; overflow: hidden; cursor: pointer; transition: filter .15s, opacity .15s; z-index: 2; }
.faena-block:hover { filter: brightness(1.1); }
.faena-name { font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.faena-block[data-admin="true"]:hover::after { content: '✕'; position: absolute; right: 8px; font-size: 14px; color: rgba(255,255,255,.9); }

/* ─── MODALS ─── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--surface); border-radius: 14px; padding: 28px 32px; width: 400px; max-width: 90vw; box-shadow: 0 25px 60px rgba(0,0,0,.2); }
.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.modal .form-group { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }
.btn-ghost { background: none; border: 1px solid var(--border); border-radius: 7px; padding: 8px 18px; cursor: pointer; font-size: 14px; }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; border: none; border-radius: 7px; padding: 8px 18px; cursor: pointer; font-size: 14px; font-weight: 600; }
.btn-danger:hover { background: #dc2626; }

/* Color picker */
.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; transition: transform .1s; }
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: var(--text); }

/* Loading */
.loading { padding: 48px; text-align: center; color: var(--text-muted); font-size: 15px; }
.spinner { display: inline-block; width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin-bottom: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast { position: fixed; bottom: 24px; right: 24px; background: #1e293b; color: #fff; padding: 12px 20px; border-radius: 8px; font-size: 13px; z-index: 200; animation: slideIn .2s ease; }
.toast.error { background: var(--danger); }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
