:root {
  color-scheme: dark;
  --bg-color: #050b18;
  --card-color: rgba(17, 25, 40, 0.88);
  --accent: #4cc9f0;
  --accent-strong: #4361ee;
  --text-color: #f1f5ff;
  --muted-text: rgba(241, 245, 255, 0.65);
  --error: #ff7b7b;
  font-family: "Montserrat", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100vw;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  background: radial-gradient(circle at top, #0b1224, var(--bg-color) 80%);
  color: var(--text-color);
  font-weight: 600;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  height: 100vh;
  max-height: 100vh;
  padding: 0.5rem;
  background: rgba(6, 11, 22, 0.35);
  overflow: hidden;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-transform: uppercase;
  font-size: clamp(18px, 3.5vw, 24px);
  letter-spacing: 0.08em;
  padding: 0.25rem 0;
  min-height: auto;
}


.top-bar__meta {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.top-bar__connection {
  font-size: clamp(10px, 2vw, 12px);
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: rgba(76, 201, 240, 0.18);
  color: #4cc9f0;
  text-transform: none;
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.top-bar__connection--lost {
  background: rgba(255, 123, 123, 0.18);
  color: #ff9a9a;
}

.chip-button {
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  background: transparent;
  color: var(--text-color);
  font-size: clamp(11px, 2vw, 14px);
  padding: 0.2rem 0.6rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.chip-button:active {
  transform: scale(0.97);
}

.chip-button--secondary {
  border-color: rgba(76, 201, 240, 0.4);
  color: var(--accent);
}

.top-bar__version {
  font-size: clamp(14px, 2.5vw, 18px);
  color: var(--muted-text);
}

.app-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-shrink: 0;
}

.app-footer__version {
  font-size: clamp(10px, 1.8vw, 12px);
  color: var(--muted-text);
  font-weight: 500;
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-align: center;
}

#screen-measure {
  overflow: hidden;
}

#screen-scale-config,
#screen-networks {
  overflow-y: auto;
  overflow-x: hidden;
  justify-content: flex-start;
  padding: 0.5rem 0;
  align-items: stretch;
  min-height: 0;
}

#screen-scale-config .scale-config-form {
  flex-shrink: 0;
  margin-bottom: 0.5rem;
}

#screen-networks .network-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.view__title {
  font-size: clamp(20px, 5vw, 30px);
  margin: 0;
}

.view__message {
  font-size: clamp(14px, 3.5vw, 20px);
  margin: 0;
  color: var(--muted-text);
}

.view__actions {
  display: flex;
  gap: 0.4rem;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 16px;
  padding: 0.8rem 1.2rem;
  font-size: clamp(18px, 5vw, 28px);
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  max-width: 12rem;
  color: var(--text-color);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
  transform: none;
  box-shadow: none;
}

.btn--primary {
  background: linear-gradient(140deg, var(--accent), var(--accent-strong));
  color: #ffffff;
}

.btn--secondary {
  background: rgba(255, 255, 255, 0.12);
}

.btn--ghost {
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.18);
}

.measure-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

.measure-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.measure-weight-line {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.measure-weight {
  font-size: clamp(140px, 65vw, 220px);
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 0.85;
}

.measure-weight--with-decimals {
  font-size: clamp(120px, 58vw, 190px);
}

.measure-weight-integer {
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  line-height: inherit;
}

.measure-weight-decimal {
  font-size: 0.4em;
  vertical-align: baseline;
  opacity: 0.85;
}

.measure-unit {
  font-size: clamp(36px, 13vw, 50px);
  color: var(--muted-text);
  text-transform: uppercase;
  letter-spacing: 0.25em;
}

.measure-display--compact .measure-weight {
  font-size: clamp(100px, 50vw, 160px);
}

.measure-display--compact .measure-weight--with-decimals {
  font-size: clamp(88px, 45vw, 140px);
}

.measure-display--compact .measure-weight-decimal {
  font-size: 0.45em;
}

.measure-display--compact .measure-unit {
  font-size: clamp(28px, 11vw, 40px);
  letter-spacing: 0.18em;
}

.measure-display--compact .measure-details-grid {
  width: 100%;
  gap: 1.5rem;
}

.measure-details-grid {
  display: grid;
  width: 95%;
  grid-template-columns: 1fr 0.6fr 1.4fr 1fr;
  gap: 0.5rem;
}

/* Scale status indicator */
.scale-indicator {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  margin-top: -0.2rem;
}

.scale-indicator-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  animation: pulse 1.5s ease-in-out infinite;
}

.scale-indicator--ready .scale-indicator-dot {
  background: #4ade80;
  animation: none;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.5);
}

.scale-indicator--error .scale-indicator-dot {
  background: var(--error);
  animation: none;
  box-shadow: 0 0 8px rgba(255, 123, 123, 0.5);
}

.scale-indicator--connecting .scale-indicator-dot {
  background: #fbbf24;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.4;
    transform: scale(0.95);
  }

  50% {
    opacity: 1;
    transform: scale(1.05);
  }
}

.scale-indicator-text {
  font-size: clamp(10px, 2vw, 12px);
  color: var(--muted-text);
  font-weight: 600;
}

.scale-indicator--ready .scale-indicator-text {
  color: #4ade80;
}

.scale-indicator--error .scale-indicator-text {
  color: var(--error);
}

.scale-indicator--connecting .scale-indicator-text {
  color: #fbbf24;
}

.measure-rfid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.measure-rfid-label {
  font-size: clamp(12px, 3.5vw, 16px);
  color: var(--muted-text);
  text-transform: uppercase;
  letter-spacing: 0.35em;
}

.measure-rfid-value {
  font-size: clamp(14px, 4vw, 18px);
  letter-spacing: 0.08em;
}

.result-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  padding: 0.25rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
}

.result-item--highlight {
  background: rgba(76, 201, 240, 0.08);
}

.measure-actions {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.measure-actions .feedback {
  flex: 1;
  text-align: left;
}

.measure-actions .btn {
  margin-left: auto;
}

.result-value {
  font-size: clamp(16px, 5vw, 24px);
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-color);
}

.result-value--large {
  font-size: clamp(18px, 6vw, 28px);
}

.result-value--wide {
  font-size: clamp(16px, 5.5vw, 24px);
  word-break: break-word;
}

.btn--compact {
  max-width: 10rem;
  padding: 0.75rem 1rem;
  font-size: clamp(18px, 4vw, 24px);
}

.network-list {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow-y: auto;
  padding-right: 0.25rem;
  max-height: 100%;
}

.network-btn {
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 0.8rem 1.2rem;
  font-size: clamp(18px, 5vw, 28px);
  font-weight: 800;
  background: var(--card-color);
  color: var(--text-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.38);
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}

.network-btn span {
  font-size: clamp(14px, 4vw, 20px);
  color: var(--muted-text);
}

.network-btn:active {
  transform: scale(0.97);
}

.password-input {
  width: 100%;
  font-size: clamp(20px, 6vw, 32px);
  padding: 0.8rem;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  background: rgba(10, 16, 28, 0.85);
  color: var(--text-color);
  text-align: center;
  box-shadow: inset 0 0 0 2px rgba(67, 97, 238, 0.15);
}

.password-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px rgba(76, 201, 240, 0.35);
}

.keyboard {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.keyboard__row {
  display: flex;
  gap: 0.4rem;
}

.key-btn {
  flex: 1;
  padding: 0.6rem 0;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-color);
  font-size: clamp(16px, 4vw, 24px);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.32);
  transition: transform 0.08s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.key-btn:active {
  transform: scale(0.97);
}

.key-btn--wide {
  flex: 1.6;
}

.key-btn--space {
  flex: 3;
}

.key-btn--active {
  background: linear-gradient(140deg, rgba(76, 201, 240, 0.6), rgba(67, 97, 238, 0.6));
}

/* Teclas de cambio de layout (123 / ABC / #+=) estilo móvil */
.key-btn--layout {
  flex: 1.2;
  font-size: clamp(14px, 3.5vw, 20px);
  font-weight: 600;
  color: var(--accent);
  background: rgba(76, 201, 240, 0.15);
}
.key-btn--layout:active {
  background: rgba(76, 201, 240, 0.3);
}

.feedback {
  min-height: 1.2rem;
  margin: 0;
  font-size: clamp(12px, 3.5vw, 16px);
  color: var(--muted-text);
  white-space: pre-line;
}

.feedback--error {
  color: var(--error);
}

.feedback--success {
  color: #4ade80;
}

/* Success state - green text for entire app */
.app-shell--success {
  color: #4ade80;
}

.app-shell--success .measure-weight,
.app-shell--success .measure-weight-integer,
.app-shell--success .measure-weight-decimal,
.app-shell--success .measure-unit,
.app-shell--success .measure-rfid-value,
.app-shell--success .result-value {
  color: #4ade80;
}

/* Scale configuration form */
.scale-config-form {
  width: 100%;
  max-width: 580px;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 1rem;
  background: var(--card-color);
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.38);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: clamp(12px, 2.5vw, 14px);
  color: var(--muted-text);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.form-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

.form-row--split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-input,
.form-select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  font-size: clamp(14px, 3vw, 16px);
  font-weight: 600;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  background: rgba(10, 16, 28, 0.7);
  color: var(--text-color);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(76, 201, 240, 0.2);
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%234cc9f0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  background-size: 1.2em;
  padding-right: 2.5rem;
}

.form-select option {
  background: #0b1224;
  color: var(--text-color);
  padding: 0.5rem;
}

.btn--small {
  padding: 0.6rem 0.9rem;
  font-size: clamp(12px, 2.5vw, 14px);
  max-width: none;
  width: auto;
  flex-shrink: 0;
}

.scale-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  margin-top: 0.3rem;
}

.scale-status-label {
  font-size: clamp(12px, 2.5vw, 14px);
  color: var(--muted-text);
  font-weight: 600;
}

.scale-status-value {
  font-size: clamp(12px, 2.5vw, 14px);
  font-weight: 700;
}

.scale-status-value--ok {
  color: #4ade80;
}

.scale-status-value--error {
  color: var(--error);
}

.scale-status-value--pending {
  color: #fbbf24;
}

@media (max-width: 480px) {
  .app-shell {
    padding: 1rem;
    gap: 1rem;
  }

  .top-bar__meta {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .measure-display {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  .measure-side--left {
    order: 2;
    text-align: left;
  }

  .measure-side--right {
    order: 3;
    text-align: left;
  }

  .measure-center {
    order: 1;
  }

  .measure-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .measure-actions .btn {
    margin-left: 0;
    align-self: flex-end;
  }

  .keyboard__row {
    gap: 0.5rem;
  }

  .key-btn {
    border-radius: 14px;
  }

  .network-list {
    gap: 0.75rem;
  }

  .scale-config-form {
    padding: 1rem;
    gap: 1rem;
  }

  .form-row--split {
    grid-template-columns: 1fr;
  }

  .form-row {
    flex-direction: column;
    align-items: stretch;
  }

  .btn--small {
    width: 100%;
  }
}

@media (min-width: 720px) {
  .measure-actions .feedback {
    font-size: clamp(20px, 4vw, 26px);
  }
}