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

:root {
  --bg: #f5f5f0;
  --card: #fff;
  --border: #ddd;
  --primary: #2d6a4f;
  --primary-light: #40916c;
  --primary-bg: #d8f3dc;
  --danger: #d62828;
  --danger-bg: #fde8e8;
  --warn: #f9c74f;
  --warn-bg: #fff8e1;
  --text: #333;
  --text-light: #888;
  --radius: 6px;
}

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

/* Login */
.screen { min-height: 100vh; }

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2d6a4f, #40916c);
}

#login-screen.hidden-screen {
  display: none;
}

#app-screen {
  display: none;
}

#app-screen.visible-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.login-card {
  background: var(--card);
  padding: 2.5rem;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  text-align: center;
  width: 340px;
}

.login-logo {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin-bottom: 1rem;
}

.login-card h1 {
  font-size: 1.4rem;
  margin-bottom: 1.5rem;
  color: var(--primary);
}

.login-card input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  margin-bottom: 1rem;
}

.login-card button {
  width: 100%;
  padding: 0.75rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
}

.login-card button:hover { background: var(--primary-light); }

.error { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; }

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: white;
  flex-wrap: wrap;
  gap: 0.5rem;
  transition: background-color 0.3s ease;
}

header.suc-header-HIMNO { background: #1B5E20; }
header.suc-header-CARRANZA { background: #0D47A1; }
header.suc-header-LOMAS { background: #BF360C; }
header.suc-header-PROD { background: #4A148C; }

.header-logo {
  height: 32px;
  width: auto;
}

.header-title {
  font-size: 1.1rem;
  font-weight: 600;
  opacity: 0.9;
  letter-spacing: 0.5px;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.week-dates { font-size: 0.8rem; opacity: 0.8; }

#week-select {
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  border: none;
  font-size: 0.9rem;
  background: rgba(255,255,255,0.9);
}

.btn-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.2);
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover { background: rgba(255,255,255,0.35); }

.btn-sm {
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.3);
  background: transparent;
  color: white;
  cursor: pointer;
  font-size: 0.8rem;
}

.btn-sm:hover { background: rgba(255,255,255,0.15); }

.btn-primary {
  padding: 0.5rem 1.2rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-primary:hover { background: var(--primary-light); }

.btn-cancel {
  padding: 0.5rem 1.2rem;
  background: transparent;
  color: var(--text-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-cancel:hover { background: #f0f0f0; }

.save-status {
  font-size: 0.75rem;
  opacity: 0.8;
  min-width: 60px;
}

/* Sucursal tabs */
.tabs-bar {
  display: flex;
  align-items: center;
  background: #e8e8e3;
  border-bottom: 2px solid var(--primary);
}

.suc-tabs {
  display: flex;
  gap: 0;
  flex: 1;
}

.suc-tab {
  padding: 0.55rem 1.2rem;
  cursor: pointer;
  border: none;
  background: transparent;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-light);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}

.suc-tab:hover { color: var(--text); background: rgba(255,255,255,0.5); }

/* Sucursal colors */
.suc-tab[data-suc="HIMNO"].active { color: #1B5E20; border-bottom-color: #1B5E20; background: #E8F5E9; }
.suc-tab[data-suc="CARRANZA"].active { color: #0D47A1; border-bottom-color: #0D47A1; background: #E3F2FD; }
.suc-tab[data-suc="LOMAS"].active { color: #BF360C; border-bottom-color: #BF360C; background: #FBE9E7; }
.suc-tab[data-suc="PROD"].active { color: #4A148C; border-bottom-color: #4A148C; background: #F3E5F5; }

.suc-bg-HIMNO { background: #E8F5E9; }
.suc-bg-CARRANZA { background: #E3F2FD; }
.suc-bg-LOMAS { background: #FBE9E7; }
.suc-bg-PROD { background: #F3E5F5; }

.suc-header-HIMNO th { background: #1B5E20 !important; }
.suc-header-CARRANZA th { background: #0D47A1 !important; }
.suc-header-LOMAS th { background: #BF360C !important; }
.suc-header-PROD th { background: #4A148C !important; }

.view-toggle {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 0.8rem;
}

.view-btn {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  background: transparent;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--text-light);
}

.view-btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.view-btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-left: none; }

.view-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.suc-tab.active {
  color: var(--primary);
  background: var(--card);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* Main layout */
#app-screen > main {
  flex: 1;
  overflow: auto;
  padding: 0.8rem;
  display: flex;
  gap: 0.8rem;
}

#grid-wrapper {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

#grid-container { flex: 1; overflow-x: auto; }

/* Schedule grid */
.schedule-grid {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.schedule-grid th,
.schedule-grid td {
  border: 1px solid #e5e5e0;
  padding: 0.3rem 0.4rem;
  text-align: center;
  white-space: nowrap;
}

.schedule-grid th {
  background: var(--primary);
  color: white;
  font-weight: 500;
  position: sticky;
  top: 0;
  z-index: 2;
}

.schedule-grid .col-horario {
  text-align: left;
  font-size: 0.78rem;
  min-width: 130px;
  background: #fafaf8;
  font-weight: 500;
}

.schedule-grid .col-rol {
  text-align: left;
  font-size: 0.78rem;
  min-width: 90px;
  background: #fafaf8;
  color: var(--text-light);
}

.schedule-grid td.cell-name {
  min-width: 80px;
  position: relative;
}

/* Editable cell */
.cell-input {
  width: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-size: 0.85rem;
  padding: 0.25rem;
  outline: none;
  font-family: inherit;
}

.cell-input:focus {
  background: var(--primary-bg);
  border-radius: 2px;
}

/* Read-only cells for empleados */
.cell-readonly {
  padding: 0.35rem;
  color: var(--text);
}

/* Conflict highlight */
.cell-conflict {
  background: var(--danger-bg) !important;
}

.cell-conflict .cell-input {
  color: var(--danger);
  font-weight: 600;
}

/* Row actions */
.row-actions {
  width: 30px;
  padding: 0 !important;
}

.btn-delete-row {
  border: none;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem;
}

.btn-delete-row:hover { color: var(--danger); }

.btn-add-row {
  margin: 0.5rem 0;
  padding: 0.4rem 1rem;
  background: var(--primary-bg);
  color: var(--primary);
  border: 1px dashed var(--primary);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-add-row:hover { background: #b7e4c7; }

/* Horario and rol inputs in grid */
.horario-input,
.rol-input {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 0.78rem;
  padding: 0.25rem;
  outline: none;
  font-family: inherit;
}

.horario-input:focus,
.rol-input:focus {
  background: var(--primary-bg);
}

/* Todos panel */
.todos-panel {
  width: 220px;
  min-width: 180px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 0.8rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  overflow-y: auto;
  font-size: 0.8rem;
}

.todos-panel h3 {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  color: var(--primary);
}

.todo-emp {
  padding: 0.25rem 0;
  border-bottom: 1px solid #f0f0eb;
  display: flex;
  justify-content: space-between;
}

.todo-emp-name { font-weight: 500; }

.todo-emp-days {
  color: var(--text-light);
  font-size: 0.75rem;
}

.todo-emp.unassigned {
  color: var(--danger);
}

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.visible {
  display: flex;
}

.modal-content {
  background: var(--card);
  border-radius: 12px;
  width: 600px;
  max-width: 95vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 1.1rem; }

.modal-close {
  border: none;
  background: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-light);
}

.aliases-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.8rem 1.2rem;
}

.alias-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.4rem;
}

.alias-emp-name {
  flex: 1;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.alias-input {
  width: 90px;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  text-align: center;
  font-weight: 600;
  text-transform: uppercase;
}

.alias-rol {
  width: 130px;
  padding: 0.35rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--text-light);
}

.modal-footer {
  padding: 0.8rem 1.2rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* Cell schedule edit (employee-centric) */
.cell-schedule-edit {
  display: flex;
  flex-direction: column;
  gap: 1px;
  position: relative;
}

.cell-time-row {
  display: flex;
  align-items: center;
  gap: 1px;
}

.cell-time-sep {
  font-size: 0.65rem;
  color: var(--text-light);
  flex-shrink: 0;
}

.cell-select-time {
  width: 58px;
  border: 1px solid #e0e0e0;
  background: white;
  font-size: 0.7rem;
  padding: 2px 1px;
  border-radius: 3px;
  cursor: pointer;
  text-align: center;
  -webkit-appearance: none;
  appearance: none;
}

.cell-select-rol {
  width: 100%;
  border: 1px solid #e0e0e0;
  background: white;
  font-size: 0.65rem;
  padding: 2px 2px;
  border-radius: 3px;
  cursor: pointer;
  color: var(--text-light);
  margin-top: 2px;
  -webkit-appearance: none;
  appearance: none;
}

.cell-select-time:focus,
.cell-select-rol:focus {
  border-color: var(--primary);
  outline: none;
}

/* Apertura/Cierre flags */
.cell-flags {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-bottom: 2px;
}

.cell-flag {
  font-size: 0.6rem;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 1px;
  cursor: pointer;
}

.cell-flag input { width: 12px; height: 12px; margin: 0; cursor: pointer; }

.flag-badge {
  display: inline-block;
  background: var(--primary-bg);
  color: var(--primary);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.6rem;
  font-weight: 600;
}

/* Zebra striping */
.row-zebra td { background: rgba(0, 0, 0, 0.025); }

.btn-clear-cell {
  position: absolute;
  top: -2px;
  right: -2px;
  border: none;
  background: var(--danger);
  color: white;
  font-size: 0.6rem;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.cell-name:hover .btn-clear-cell { display: flex; }

.btn-assign-cell {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  width: 100%;
  padding: 0.3rem;
  font-size: 0.8rem;
  border-radius: 3px;
}

.btn-assign-cell:hover {
  background: var(--primary-bg);
  color: var(--primary);
  border-color: var(--primary);
}

.cell-other-suc {
  font-size: 0.7rem;
  color: var(--text-light);
  font-style: italic;
}

/* Todos filter */
.todos-filter {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
  position: relative;
  max-width: 300px;
}

.todos-filter-input {
  width: 100%;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  outline: none;
}

.todos-filter-input:focus {
  border-color: var(--primary);
}

.todos-filter-clear {
  position: absolute;
  right: 6px;
  border: none;
  background: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-light);
  padding: 0 4px;
}

.todos-filter-clear:hover { color: var(--danger); }

/* Autocomplete dropdown */
.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 50;
  max-height: 150px;
  overflow-y: auto;
}

.autocomplete-item {
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 0.82rem;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: var(--primary-bg);
}

/* Responsive */
@media (max-width: 768px) {
  header { flex-direction: column; align-items: stretch; }
  .header-left, .header-center, .header-right {
    justify-content: center;
  }
  .todos-panel { display: none; }
  #app-screen > main { padding: 0.4rem; }
  .schedule-grid { font-size: 0.75rem; }
  .cell-input { font-size: 0.75rem; }
  .suc-tab { padding: 0.4rem 0.7rem; font-size: 0.8rem; }
}
