@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary: #4CAF50;
  --primary-dark: #2E7D32;
  --primary-light: #A5D6A7;
  --accent: #009688;
  --bg: #f0f4f0;
  --text: #263238;
  --text-muted: #78909c;
  --card-bg: #ffffff;
  --timeline-done: #4CAF50;
  --timeline-todo: #e0e0e0;
  --danger: #ef5350;
  --danger-light: #ffebee;
  --warning: #ffa726;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.07);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.18);
  --radius: 14px;
  --radius-sm: 8px;
  --transition: 0.22s ease;
}

body {
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 20px;
  padding-bottom: 80px;
  /* Space for fixed buttons if any */
}

.container {
  max-width: 600px;
  margin: 0 auto;
}

/* Header e Status */
header {
  text-align: center;
  margin-bottom: 20px;
}

h1 {
  color: var(--primary-dark);
  margin: 0;
  font-size: 1.8rem;
}

p.subtitle {
  color: #78909c;
  margin: 5px 0 0 0;
  font-size: 0.9rem;
}

/* Connection Bar */
.connection-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  padding: 10px 15px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  margin-bottom: 20px;
}

.status-dot {
  height: 10px;
  width: 10px;
  background-color: #ccc;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
}

.status-dot.connected {
  background-color: var(--primary);
  box-shadow: 0 0 5px var(--primary);
}

.btn-connect {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 15px;
  border-radius: 20px;
  font-weight: bold;
  cursor: pointer;
}

.btn-connect:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* Alerts */
.alert-box {
  padding: 15px;
  margin-bottom: 20px;
  border-radius: 10px;
  text-align: center;
  font-size: 0.95em;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.alert-box.info {
  background-color: #e3f2fd;
  color: #0d47a1;
  border: 1px solid #bbdefb;
}

.alert-box.error {
  background-color: #ffebee;
  color: #b71c1c;
  border: 1px solid #ffcdd2;
}

.btn-claim {
  background: #0d47a1;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: bold;
  cursor: pointer;
  width: fit-content;
}

.btn-claim:hover {
  background: #1565c0;
}

/* Dashboard Cards */
.current-status-card {
  background: var(--card-bg);
  border-radius: 15px;
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  text-align: center;
  border-top: 5px solid var(--primary);
  margin-bottom: 20px;
}

.status-item h3 {
  font-size: 0.8em;
  color: #90a4ae;
  margin-bottom: 5px;
  text-transform: uppercase;
}

.status-item .val {
  font-size: 1.2em;
  font-weight: bold;
  color: var(--text);
}

.status-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 15px;
  color: white;
  font-weight: bold;
  font-size: 0.8em;
  cursor: pointer;
}

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

.off {
  background-color: var(--danger);
  opacity: 0.8;
}

/* Timeline */
.timeline-container {
  margin-bottom: 20px;
  padding: 0 5px;
}

.progress-bar {
  height: 8px;
  background: var(--timeline-todo);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
}

.progress-segment {
  height: 100%;
  transition: width 0.5s ease;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-size: 0.75em;
  font-weight: bold;
  color: #78909c;
}

/* Phase List & Config */
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  color: var(--text);
}

.btn-add {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}

.phase-card {
  background: white;
  border-radius: 12px;
  padding: 15px;
  margin-bottom: 15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  border-left: 4px solid transparent;
  position: relative;
}

.phase-card.active {
  border-left-color: var(--primary);
  background: #f1f8e9;
}

.phase-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-right: 70px;
  /* Prevent overlap with absolute actions */
}

.phase-name {
  font-weight: bold;
  font-size: 1.1em;
}

.phase-days {
  font-size: 0.9em;
  color: #666;
  background: #eee;
  padding: 2px 8px;
  border-radius: 10px;
}

.phase-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  font-size: 0.9em;
  color: #555;
}

.phase-details .detail-row:first-child {
  grid-column: span 2;
  border-bottom: 1px solid #eee;
  padding-bottom: 5px;
  margin-bottom: 5px;
}

.detail-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.card-actions {
  position: absolute;
  top: 15px;
  right: 15px;
  display: flex;
  gap: 10px;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.6;
  padding: 5px;
}

.icon-btn:hover {
  opacity: 1;
}

/* Forms & Inputs */
.date-input-group {
  background: white;
  padding: 15px;
  border-radius: 12px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

input[type="date"] {
  border: 1px solid #ddd;
  padding: 8px;
  border-radius: 6px;
  font-family: inherit;
}

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

.modal {
  background: white;
  width: 90%;
  max-width: 500px;
  border-radius: 15px;
  padding: 25px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  font-size: 1.2em;
  font-weight: bold;
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  font-size: 0.9em;
}

.form-group input {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-sizing: border-box;
}

.form-row {
  display: flex;
  gap: 15px;
}

.form-row .form-group {
  flex: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.btn-cancel {
  background: #eee;
  color: #333;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
}

.btn-save {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
}

/* Loading Spinner */
.spinner {
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top: 3px solid white;
  width: 16px;
  height: 16px;
  animation: spin 1s linear infinite;
  display: inline-block;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Spinner */
.spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #4CAF50;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* ════════════════════════════════════════════
   PROVISION WIZARD MODAL
   ════════════════════════════════════════════ */

/* Overlay */
#provisionWizard {
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 12, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 2000;
  padding: 0;
}

#provisionWizard.active {
  display: flex;
  animation: wizardFadeIn 0.3s ease;
}

@keyframes wizardFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Sheet panel */
.wizard-sheet {
  background: #fff;
  width: 100%;
  max-width: 520px;
  border-radius: 24px 24px 0 0;
  padding: 0 0 env(safe-area-inset-bottom, 20px);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: sheetUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* Handle bar at top */
.wizard-handle {
  width: 40px;
  height: 4px;
  background: #ddd;
  border-radius: 2px;
  margin: 14px auto 0;
  flex-shrink: 0;
}

/* Step indicator */
.wizard-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 18px 24px 0;
  flex-shrink: 0;
}

.wizard-step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ddd;
  transition: var(--transition);
  flex-shrink: 0;
}

.wizard-step-dot.active {
  background: var(--primary);
  width: 24px;
  border-radius: 4px;
}

.wizard-step-dot.done {
  background: var(--primary-light);
}

.wizard-step-line {
  height: 2px;
  width: 24px;
  background: #e8e8e8;
  flex-shrink: 0;
}

/* Wizard body */
.wizard-body {
  padding: 20px 24px 28px;
  flex: 1;
}

.wizard-icon {
  font-size: 2.4rem;
  text-align: center;
  margin-bottom: 8px;
  animation: iconBounce 0.5s ease;
}

@keyframes iconBounce {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

.wizard-title {
  font-family: 'Inter', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin: 0 0 6px;
}

.wizard-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
  margin: 0 0 22px;
  line-height: 1.5;
}

.wizard-device-badge {
  display: inline-block;
  background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 1rem;
  padding: 6px 20px;
  border-radius: 20px;
  letter-spacing: 0.05em;
  border: 2px solid var(--primary-light);
}

/* ── Auth Tabs ── */
.auth-tabs {
  display: flex;
  background: #f5f5f5;
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  padding: 9px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.auth-tab.active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}

.auth-panel {
  display: none;
}

.auth-panel.active {
  display: block;
  animation: panelFade 0.2s ease;
}

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

/* ── Wizard Form Fields ── */
.wizard-form-group {
  margin-bottom: 14px;
}

.wizard-form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.wizard-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #e0e0e0;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  color: var(--text);
  background: #fafafa;
  box-sizing: border-box;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.wizard-input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.15);
}

.wizard-input.has-icon {
  padding-right: 42px;
}

.input-wrapper {
  position: relative;
}

.input-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  cursor: pointer;
  user-select: none;
  color: var(--text-muted);
}

/* ── Wizard Buttons ── */
.btn-wizard-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 4px 14px rgba(46, 125, 50, 0.35);
  margin-top: 8px;
}

.btn-wizard-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(46, 125, 50, 0.45);
}

.btn-wizard-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-wizard-primary:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.btn-wizard-secondary {
  width: 100%;
  padding: 12px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 4px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.btn-wizard-secondary:hover {
  background: #f5f5f5;
  color: var(--text);
}

/* ── Error Banner ── */
.wizard-error {
  background: var(--danger-light);
  color: #c62828;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin-bottom: 14px;
  display: none;
  align-items: center;
  gap: 8px;
  border-left: 3px solid var(--danger);
}

.wizard-error.visible {
  display: flex;
  animation: panelFade 0.2s ease;
}

/* ── Claim Card ── */
.claim-card {
  background: linear-gradient(135deg, #e8f5e9, #f1f8e9);
  border: 2px solid var(--primary-light);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  margin-bottom: 20px;
}

.claim-card-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary-dark);
  font-weight: 700;
  margin-bottom: 8px;
}

.claim-card-code {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary-dark);
  font-family: 'Inter', sans-serif;
  letter-spacing: 0.1em;
}

.claim-card-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ── Wi-Fi Panel ── */
.wifi-strength-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Provision Status Steps ── */
.prov-status-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 4px 0 20px;
}

.prov-status-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: #f9f9f9;
  border-radius: var(--radius-sm);
  border: 1.5px solid #e8e8e8;
  transition: background var(--transition), border-color var(--transition);
}

.prov-status-item.active {
  background: #e8f5e9;
  border-color: var(--primary-light);
}

.prov-status-item.success {
  background: #e8f5e9;
  border-color: var(--primary);
}

.prov-status-item.error {
  background: var(--danger-light);
  border-color: var(--danger);
}

.prov-status-icon {
  font-size: 1.4rem;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.prov-status-icon .mini-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(76, 175, 80, 0.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  display: inline-block;
}

.prov-status-text {
  flex: 1;
}

.prov-status-label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.prov-status-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── User Bar update ── */
.user-bar {
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
}

/* Responsive: desktop centres the sheet */
@media (min-width: 540px) {
  #provisionWizard {
    align-items: center;
  }
  .wizard-sheet {
    border-radius: 24px;
    max-height: 88vh;
  }
}

/* ════════════════════════════════════════════
   OTA FIRMWARE UPDATE
   ════════════════════════════════════════════ */

.ota-section {
  margin-top: 28px;
  border-top: 1px solid #e8f0e8;
  padding-top: 20px;
}

.ota-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 14px;
  cursor: pointer;
  user-select: none;
}

.ota-section-title .ota-chevron {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.ota-section-title.expanded .ota-chevron {
  transform: rotate(180deg);
}

.ota-collapsible {
  display: none;
}

.ota-collapsible.open {
  display: block;
  animation: panelFade 0.2s ease;
}

/* Info row */
.ota-info-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.ota-chip {
  background: #e8f5e9;
  color: var(--primary-dark);
  border: 1px solid var(--primary-light);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.ota-chip.warn {
  background: #fff3e0;
  color: #e65100;
  border-color: #ffb74d;
}

/* Drop zone */
.ota-drop-zone {
  border: 2px dashed var(--primary-light);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: #fafffe;
  position: relative;
}

.ota-drop-zone:hover,
.ota-drop-zone.dragover {
  border-color: var(--primary);
  background: #f1f8e9;
}

.ota-drop-zone input[type=file] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.ota-drop-icon {
  font-size: 2rem;
  margin-bottom: 6px;
}

.ota-drop-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.ota-filename {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--primary-dark);
  font-weight: 600;
  min-height: 1.2em;
}

/* Progress */
.ota-progress-wrap {
  margin-top: 14px;
  display: none;
}

.ota-progress-bg {
  background: #e0e0e0;
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
}

.ota-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  border-radius: 99px;
  transition: width 0.3s ease;
}

.ota-progress-pct {
  text-align: right;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Upload button */
.ota-upload-btn {
  width: 100%;
  margin-top: 14px;
  padding: 13px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 0.97rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  box-shadow: 0 4px 14px rgba(46,125,50,0.3);
}

.ota-upload-btn:hover:not(:disabled) {
  opacity: 0.92;
  transform: translateY(-1px);
}

.ota-upload-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ota-status {
  margin-top: 10px;
  font-size: 0.85rem;
  text-align: center;
  min-height: 1.3em;
  color: var(--text-muted);
}

.ota-status.success { color: var(--primary-dark); font-weight: 600; }
.ota-status.error   { color: var(--danger); font-weight: 600; }

.ota-not-connected {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 10px 0;
}