/* ======================== RESET Y CONFIGURACIÓN BASE ======================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --color-primary: #007bff;
  --color-success: #28a745;
  --color-warning: #ffc107;
  --color-danger: #dc3545;
  --color-info: #17a2b8;
  --color-dark: #343a40;
  --color-light: #f8f9fa;
  --color-white: #ffffff;
  --color-border: #dee2e6;
  --color-text: #212529;
  --color-text-light: #6c757d;
  --color-areperia: #ffed00;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--color-light);
  color: var(--color-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* ======================== PANTALLAS ======================== */
.screen {
  display: none;
  min-height: 100vh;
  padding: 20px;
  animation: fadeIn 0.3s ease-in-out;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ======================== HEADER ======================== */
.header {
  background: var(--color-areperia);
  color: var(--color-dark);
  padding: 15px 20px;
  margin: -20px -20px 20px -20px;
  text-align: center;
  box-shadow: var(--shadow);
}

.header h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 5px;
}

.production-code {
  font-size: 0.9rem;
  color: var(--color-text-light);
  font-weight: 500;
}

.user-badge {
  background: var(--color-white);
  padding: 5px 15px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-primary);
}

/* ======================== CONTAINERS ======================== */
.container {
  max-width: 600px;
  margin: 0 auto;
}

.container.center {
  text-align: center;
}

/* ======================== LOGIN ======================== */
#screen-login {
  position: relative;
  background: linear-gradient(135deg, rgba(255, 237, 0, 0.08) 0%, rgba(255, 237, 0, 0.03) 100%);
}

#screen-login::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 400px;
  height: 400px;
  background: url('../assets/images/icon.png') center center no-repeat;
  background-size: contain;
  opacity: 0.06;
  z-index: 0;
  pointer-events: none;
}

.login-container {
  position: relative;
  z-index: 1;
  max-width: 400px;
  margin: 80px auto;
  background: var(--color-white);
  padding: 40px;
  border-radius: 15px;
  box-shadow: var(--shadow-lg);
}

.logo {
  text-align: center;
  margin-bottom: 40px;
}

.logo-img {
  width: 70px;
  height: 70px;
  margin-bottom: 15px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
  animation: logoFadeIn 0.6s ease-in-out;
}

@keyframes logoFadeIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.logo h1 {
  font-size: 2rem;
  color: var(--color-dark);
  margin-bottom: 5px;
  font-weight: 700;
}

.subtitle {
  color: var(--color-text-light);
  font-size: 1rem;
}

/* ======================== FORM ELEMENTS ======================== */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--color-dark);
  font-size: 1rem;
}

.input-field {
  width: 100%;
  padding: 15px;
  font-size: 1.1rem;
  border: 2px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-white);
  color: var(--color-text);
  transition: border-color 0.3s ease;
}

.input-field:focus {
  outline: none;
  border-color: var(--color-primary);
}

.input-field::placeholder {
  color: #adb5bd;
}

.input-large {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  color: var(--color-success);
}

.input-with-unit {
  display: flex;
  align-items: center;
  gap: 10px;
}

.input-with-unit .input-field {
  flex: 1;
}

.unit-label {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-text-light);
  min-width: 50px;
}

textarea.input-field {
  resize: vertical;
  font-family: inherit;
  min-height: 80px;
}

/* ======================== BUTTONS ======================== */
.btn {
  display: inline-block;
  width: 100%;
  padding: 16px 24px;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: var(--shadow);
}

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.btn-large {
  padding: 20px 24px;
  font-size: 1.2rem;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-white);
}

.btn-primary:hover {
  background: #0056b3;
}

.btn-success {
  background: var(--color-success);
  color: var(--color-white);
}

.btn-success:hover {
  background: #218838;
}

.btn-warning {
  background: var(--color-warning);
  color: var(--color-dark);
}

.btn-warning:hover {
  background: #e0a800;
}

.btn-danger {
  background: var(--color-danger);
  color: var(--color-white);
}

.btn-danger:hover {
  background: #c82333;
}

.btn-secondary {
  background: var(--color-border);
  color: var(--color-text);
  margin-top: 10px;
}

.btn-secondary:hover {
  background: #c8cfd6;
}

.btn-link {
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  padding: 10px;
  text-decoration: none;
  display: inline-block;
}

.btn-link:hover {
  text-decoration: underline;
}

.button-group {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  margin-bottom: 15px;
}

/* ======================== INFO BOXES ======================== */
.info-box {
  background: #e7f3ff;
  border-left: 4px solid var(--color-info);
  padding: 15px;
  border-radius: 6px;
  margin-bottom: 20px;
}

.info-box strong {
  color: var(--color-dark);
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.info-row:last-child {
  border-bottom: none;
}

.info-row .label {
  font-weight: 600;
  color: var(--color-text-light);
}

.info-row .value {
  font-weight: 700;
  color: var(--color-dark);
}

.result-box {
  background: #d4edda;
  border-left: 4px solid var(--color-success);
  padding: 15px;
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 1.1rem;
}

.highlight {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--color-success);
  margin-left: 10px;
}

/* ======================== INGREDIENTS LIST ======================== */
.ingredients-list {
  background: var(--color-white);
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.ingredient-item {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 1rem;
}

.ingredient-item:last-child {
  border-bottom: none;
}

.ingredient-name {
  font-weight: 600;
  color: var(--color-dark);
  flex: 2;
}

.ingredient-qty {
  font-weight: 700;
  color: var(--color-primary);
  text-align: right;
  flex: 1;
}

/* ======================== PHASES ======================== */
.phase-current {
  text-align: center;
  margin: 20px 0;
}

.phase-current label {
  display: block;
  font-size: 0.9rem;
  color: var(--color-text-light);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.phase-name {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-primary);
  margin: 0;
}

.phases-list {
  background: var(--color-white);
  border-radius: 8px;
  padding: 15px;
  box-shadow: var(--shadow);
}

.phase-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  transition: background 0.3s ease;
}

.phase-info {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 8px;
}

.phase-time {
  font-size: 0.8rem;
  font-weight: 400;
  margin-left: auto;
  opacity: 0.8;
}

.phase-time.overdue {
  color: #dc3545;
  font-weight: 700;
}

.btn-phase-action {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  margin-left: 8px;
  white-space: nowrap;
}

.btn-finish-phase {
  background: #28a745;
  color: white;
}

.btn-finish-phase:active {
  background: #218838;
}

.btn-pause-phase {
  background: #ffc107;
  color: #212529;
}

.btn-pause-phase:active {
  background: #e0a800;
}

.btn-resume-phase {
  background: #17a2b8;
  color: white;
}

.btn-resume-phase:active {
  background: #138496;
}

.phase-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.phase-item.paused {
  background: #fff3cd;
  color: #856404;
}

.phase-item.completed, .phase-item.finished {
  background: #d4edda;
  color: #155724;
}

.phase-item.in-progress, .phase-item.in_progress {
  background: #cfe2ff;
  color: #084298;
}

.phase-item.pending {
  background: #f8f9fa;
  color: #6c757d;
}

.phase-icon {
  font-size: 1.5rem;
  margin-right: 12px;
}

/* ======================== TIME & PROGRESS ======================== */
.time-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin: 20px 0;
}

.time-item {
  background: var(--color-white);
  padding: 15px;
  border-radius: 8px;
  text-align: center;
  box-shadow: var(--shadow);
}

.time-label {
  display: block;
  font-size: 0.85rem;
  color: var(--color-text-light);
  margin-bottom: 5px;
}

.time-value {
  display: block;
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--color-primary);
}

.progress-container {
  margin: 20px 0;
}

.progress-container label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

.progress-bar {
  width: 100%;
  height: 30px;
  background: #e9ecef;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-success), #5cb85c);
  border-radius: 15px;
  transition: width 0.5s ease;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10px;
}

.progress-text {
  display: block;
  text-align: center;
  margin-top: 5px;
  font-weight: 700;
  color: var(--color-success);
  font-size: 1.1rem;
}

/* Barra de progreso en estado vencido (roja) */
.progress-fill.overdue {
  background: linear-gradient(90deg, var(--color-danger), #e74c3c);
}

.progress-text.overdue {
  color: var(--color-danger);
}

/* Tiempo transcurrido vencido - titilación de alerta */
.time-value.overdue {
  color: var(--color-danger) !important;
  animation: blink-overdue 1s ease-in-out infinite;
  border-radius: 4px;
  padding: 2px 6px;
}

@keyframes blink-overdue {
  0%, 100% {
    opacity: 1;
    background-color: transparent;
  }
  50% {
    opacity: 0.5;
    background-color: rgba(220, 53, 69, 0.25);
  }
}

/* ======================== SUCCESS SCREEN ======================== */
.success-icon {
  font-size: 5rem;
  margin: 40px 0 20px 0;
}

.success-message {
  font-size: 1.1rem;
  color: var(--color-text-light);
  margin-bottom: 30px;
}

/* ======================== UTILITIES ======================== */
.divider {
  height: 1px;
  background: var(--color-border);
  margin: 25px 0;
}

.hidden {
  display: none !important;
}

.error-message {
  background: #f8d7da;
  border-left: 4px solid var(--color-danger);
  color: #721c24;
  padding: 15px;
  border-radius: 6px;
  margin-top: 15px;
  font-weight: 600;
}

/* ======================== RESPONSIVE ======================== */
@media (max-width: 480px) {
  .screen {
    padding: 15px;
  }

  .login-container {
    margin: 40px auto;
    padding: 30px 20px;
  }

  .logo h1 {
    font-size: 2rem;
  }

  .header h2 {
    font-size: 1.2rem;
  }

  .phase-name {
    font-size: 1.5rem;
  }

  .time-info {
    grid-template-columns: 1fr;
  }

  .button-group {
    grid-template-columns: 1fr;
  }
}

/* ======================== TOUCH FEEDBACK ======================== */
@media (hover: none) {
  .btn:active {
    transform: scale(0.98);
  }
}

/* ======================== LISTA DE PRODUCCIONES ACTIVAS ======================== */
.productions-list {
  display: grid;
  gap: 12px;
  margin-bottom: 20px;
}

.production-card {
  background: var(--color-white);
  border-radius: 8px;
  padding: 15px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--color-primary);
  cursor: pointer;
  transition: all 0.3s ease;
}

.production-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.production-card.selected {
  border-left-color: var(--color-success);
  background: #f0f9f4;
}

.production-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.production-card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-dark);
}

.production-card-code {
  font-size: 0.85rem;
  color: var(--color-text-light);
  background: var(--color-light);
  padding: 4px 8px;
  border-radius: 4px;
}

.production-card-phase {
  font-size: 0.9rem;
  color: var(--color-primary);
  margin-bottom: 5px;
}

.production-card-time {
  font-size: 0.85rem;
  color: var(--color-text-light);
}

/* Alerta de fase vencida */
.production-card.overdue-alert {
  background: #FFC107;
  border-left-color: var(--color-warning);
  animation: blink-card-warning 1.5s ease-in-out infinite;
}

@keyframes blink-card-warning {
  0%, 100% {
    background-color: #FFC107;
    opacity: 1;
  }
  50% {
    background-color: #FFE082;
    opacity: 0.85;
  }
}

.btn-advance-phase-card {
  display: block;
  width: 90%;
  max-width: 280px;
  margin: 15px auto 5px auto;
  padding: 16px 20px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
}

.btn-advance-phase-card:hover {
  background: #0056b3;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 123, 255, 0.4);
}

.btn-advance-phase-card:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
}

#active-productions-section h3 {
  color: var(--color-dark);
  font-size: 1.2rem;
  margin-bottom: 15px;
}

/* ========== HISTORIAL ========== */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  background: var(--color-white);
  border-radius: 8px;
  padding: 15px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--color-primary);
}

.history-item.cancelled {
  border-left-color: var(--color-danger);
  opacity: 0.8;
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.history-item-title {
  font-weight: bold;
  color: var(--color-dark);
  font-size: 1rem;
}

.history-item-code {
  font-size: 0.85rem;
  color: var(--color-text-light);
  font-family: monospace;
}

.history-item-state {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
}

.history-item-state.finished {
  background: var(--color-success);
  color: white;
}

.history-item-state.cancelled {
  background: var(--color-danger);
  color: white;
}

.history-item-details {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.history-item-detail {
  display: flex;
  flex-direction: column;
}

.history-item-detail-label {
  font-size: 0.75rem;
  color: var(--color-text-light);
  margin-bottom: 2px;
}

.history-item-detail-value {
  font-weight: bold;
  color: var(--color-dark);
  font-size: 0.9rem;
}

.history-item-yield {
  color: var(--color-success);
}

.history-item-yield.low {
  color: var(--color-warning);
}

.history-item-yield.very-low {
  color: var(--color-danger);
}

.history-item-footer {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #eee;
  font-size: 0.8rem;
  color: var(--color-text-light);
}

.loading-message {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-light);
  font-size: 1.1rem;
}

.empty-message {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-light);
  font-size: 1rem;
}

/* ======================== MODAL CONFIGURACIÓN ======================== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none !important;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: var(--color-white);
  padding: 30px;
  border-radius: 15px;
  box-shadow: var(--shadow-lg);
  max-width: 400px;
  width: 90%;
  z-index: 1001;
  animation: modalFadeIn 0.3s ease-in-out;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-content h3 {
  text-align: center;
  margin-bottom: 25px;
  color: var(--color-dark);
  font-size: 1.3rem;
}

.modal-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.modal-buttons .btn {
  padding: 12px 8px;
  font-size: 0.9rem;
}

.config-status {
  padding: 12px;
  border-radius: 6px;
  margin-top: 15px;
  font-weight: 600;
  text-align: center;
}

.config-status.success {
  background: #d4edda;
  color: #155724;
  border-left: 4px solid var(--color-success);
}

.config-status.error {
  background: #f8d7da;
  color: #721c24;
  border-left: 4px solid var(--color-danger);
}

.config-status.loading {
  background: #e7f3ff;
  color: #084298;
  border-left: 4px solid var(--color-info);
}

.config-info {
  text-align: center;
  margin-top: 15px;
  color: var(--color-text-light);
}

.config-info small {
  font-size: 0.85rem;
}

#current-url {
  font-weight: 600;
  color: var(--color-primary);
  word-break: break-all;
}

/* Botón de configuración (engranaje) */
.btn-config {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--color-light);
  border: 2px solid var(--color-border);
  font-size: 1.5rem;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-light);
}

.btn-config:hover {
  background: var(--color-white);
  border-color: var(--color-primary);
  color: var(--color-primary);
  transform: rotate(90deg);
}

.btn-config:active {
  transform: rotate(90deg) scale(0.95);
}
