:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-border: #dfe7f5;
  --primary: #2a5bd7;
  --primary-dark: #173faf;
  --text: #1b2431;
  --muted: #5d6b82;
  --danger: #b83b3b;
  --success: #227b4d;
  --warning: #d58b00;
  --shadow: 0 8px 24px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 600px;
  margin: 24px auto;
  padding: 20px;
}

h1, h2 {
  margin-top: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}

.config-panel,
.threshold-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: end;
}

.field-group {
  display: flex;
  flex-direction: column;
  min-width: 180px;
  flex: 1;
}

.threshold-panel > .field-group:first-child {
  margin-right: auto;
}

.field-group input,
.zone-inputs input {
  max-width: 150px;
}

.field-group:has(#apiKey) {
  flex: 1.8;
}

.field-group:has(#apiKey) input {
  max-width: 100%;
  min-width: 180px;
}

.field-group.wide {
  flex: 2;
}

label {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #c7d3ee;
  border-radius: 8px;
  font-size: 16px;
  color: var(--text);
  background: #fff;
}

.input-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
}

.input-wrap input {
  width: 130px;
  max-width: 130px;
  padding-right: 62px;
}

.input-suffix {
  position: absolute;
  right: 12px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  pointer-events: none;
}

input:focus {
  outline: 2px solid rgba(42, 93, 215, 0.2);
  border-color: var(--primary);
}

input.invalid {
  border-color: var(--danger);
  background: #fff6f6;
  outline: 2px solid rgba(184, 59, 59, 0.15);
}

button {
  border: none;
  border-radius: 8px;
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease;
}

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

button.primary:hover {
  background: var(--primary-dark);
}

button.secondary {
  background: #edf2ff;
  color: var(--primary);
}

button.secondary:hover {
  background: #e5ebff;
}

.button-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-left: auto;
}

.status {
  display: none;
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 600;
}

.status.visible {
  display: block;
}

.status.info {
  background: #edf4ff;
  color: #1a3e82;
  border: 1px solid #cfe1ff;
}

.status.success {
  background: #eafaf0;
  color: var(--success);
  border: 1px solid #c4ebd0;
}

.status.error {
  background: #fff0f0;
  color: var(--danger);
  border: 1px solid #f3c9c9;
}

.status.warning {
  background: #fff8e6;
  color: var(--warning);
  border: 1px solid #f4d78a;
}

.zones-container {
  display: grid;
  gap: 16px;
}

.zone {
  border: 1px solid var(--panel-border);
  background: #f9fbff;
  border-radius: 10px;
  padding: 16px;
}

.zone-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
}

.zone-name-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.zone-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(17, 24, 39, 0.05);
}

.zone-header strong {
  font-size: 1.05rem;
}

.zone-range {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
}

.zone-inputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.zone-inputs label {
  display: flex;
  flex-direction: column;
  color: var(--muted);
  font-weight: 600;
  max-width: 160px;
}

.zone-inputs label:last-child {
  margin-left: auto;
}

@media (max-width: 640px) {
  .app {
    padding: 14px;
  }

  .config-panel,
  .threshold-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .button-row {
    flex-direction: column;
  }
}
