:root {
  --navy: #1A3A5C;
  --orange: #E8650A;
  --green: #0F6E56;
  --yellow: #854F0B;
  --red: #A32D2D;
  --bg: #F5F6F8;
  --card: #FFFFFF;
  --text: #1A2330;
  --muted: #6B7280;
  --border: #E5E7EB;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

.app {
  max-width: 500px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

header {
  background: var(--navy);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.5px;
}

header h1 .accent {
  color: var(--orange);
}

header .subtitle {
  display: block;
  font-size: 11px;
  font-weight: normal;
  opacity: 0.8;
  margin-top: 2px;
}

header .icon-btn {
  background: transparent;
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}

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

main {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}

/* Setup form */
.setup-form {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid var(--border);
}

.setup-form h2 {
  margin: 0 0 8px 0;
  color: var(--navy);
  font-size: 18px;
}

.setup-form .lead {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 20px 0;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.field .hint {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  font-family: inherit;
}

.field input:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 2px rgba(232, 101, 10, 0.15);
}

.btn {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--orange);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn:hover {
  background: #cf5908;
}

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

/* Chat */
.chat-history {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 120px;
}

.msg {
  max-width: 90%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--navy);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg.assistant-text {
  align-self: flex-start;
  background: white;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  text-align: center;
}

/* Verdict card */
.verdict-card {
  align-self: stretch;
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.verdict-header {
  padding: 14px 16px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.verdict-header.green { background: var(--green); }
.verdict-header.yellow { background: var(--yellow); }
.verdict-header.red { background: var(--red); }

.verdict-header .label {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
}

.verdict-header .verdict-action {
  font-size: 13px;
  opacity: 0.95;
  font-weight: 500;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}

.stat {
  background: white;
  padding: 12px 14px;
}

.stat .stat-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 2px;
}

.stat .stat-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
}

.stat .stat-sub {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

/* Detail rows: labeled table below the 4-cell stat grid. */
.detail-rows {
  background: white;
}

.detail-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.35;
}

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

.detail-label {
  color: var(--muted);
  font-weight: 500;
  flex-shrink: 0;
  text-transform: none;
  letter-spacing: 0;
}

.detail-value {
  color: var(--text);
  font-weight: 600;
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 0;
}

.detail-value .detail-primary {
  font-size: 14px;
}

.detail-value .detail-breakdown {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  margin-top: 2px;
}

.detail-value.value-good,
.detail-value.value-good .detail-primary {
  color: var(--green);
}

.detail-value.value-bad,
.detail-value.value-bad .detail-primary {
  color: var(--red);
}

/* Single italic line above the counter box, only on RED/YELLOW loads. */
.counter-reason {
  margin: 12px 16px 0;
  font-size: 12px;
  font-style: italic;
  color: var(--muted);
  line-height: 1.45;
}

/* Weather alert banner — sits above the verdict card on RED/YELLOW weather. */
.weather-banner {
  align-self: stretch;
  background: var(--yellow);
  color: white;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  font-size: 13px;
  line-height: 1.4;
}

.weather-banner .alert-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.weather-banner .alert-icon {
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1.4;
}

/* Quiet status row inside the verdict card (no-alerts or unavailable). */
.weather-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.weather-status.weather-ok {
  color: var(--green);
}

.counter-box {
  margin: 0 16px 14px 16px;
  background: rgba(232, 101, 10, 0.08);
  border: 1px solid rgba(232, 101, 10, 0.3);
  border-radius: 8px;
  padding: 10px 12px;
}

.counter-box .counter-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--orange);
  font-weight: 700;
  margin-bottom: 2px;
}

.counter-box .counter-value {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 8px;
}

.counter-box .counter-rate {
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
}

.counter-box .counter-projection {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.disclaimer {
  padding: 0 16px 12px 16px;
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}

/* Load entry form */
.load-form {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 12px 16px 16px 16px;
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.04);
}

.load-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  margin-bottom: 10px;
}

.load-field {
  display: flex;
  flex-direction: column;
}

.load-field-wide {
  grid-column: 1 / -1;
}

.load-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 3px;
}

.load-field input {
  padding: 9px 11px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: white;
  font-family: inherit;
}

.load-field input:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 2px rgba(232, 101, 10, 0.15);
}

.calc-btn {
  padding: 11px;
  font-size: 15px;
}

/* Pickup-date dropdown trio */
.date-picker {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr 1fr;
  gap: 6px;
}

.date-picker select {
  padding: 9px 8px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: white;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%208%208%22%3E%3Cpath%20d%3D%22M0%201l4%204%204-4z%22%20fill%3D%22%231A3A5C%22%2F%3E%3C%2Fsvg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 8px;
  padding-right: 22px;
}

.date-picker select:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 2px rgba(232, 101, 10, 0.15);
}

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

/* User input summary card */
.input-card {
  align-self: flex-end;
  max-width: 90%;
  background: var(--navy);
  color: white;
  border-radius: 12px;
  border-bottom-right-radius: 4px;
  padding: 10px 14px;
  font-size: 14px;
}

.input-card .input-primary {
  font-weight: 600;
  font-size: 15px;
}

.input-card .input-secondary {
  opacity: 0.8;
  font-size: 13px;
  margin-top: 2px;
}

/* Empty state */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}

.empty h3 {
  color: var(--navy);
  margin: 0 0 8px 0;
}

.empty p {
  margin: 0 0 8px 0;
  font-size: 14px;
}

.empty .example {
  margin-top: 16px;
  padding: 12px;
  background: white;
  border: 1px dashed var(--border);
  border-radius: 8px;
  font-size: 13px;
  text-align: left;
  color: var(--text);
  font-style: italic;
}

/* Install banner */
.install-banner {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 468px;
  background: var(--navy);
  color: white;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 50;
  animation: slide-up 0.25s ease-out;
}

/* Higher-specificity rule so the [hidden] attribute actually hides the
   banner — without this, .install-banner's display:flex overrides the
   user-agent's [hidden]{display:none}. */
.install-banner[hidden] {
  display: none;
}

@keyframes slide-up {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

.install-text {
  flex: 1;
  min-width: 0;
}

.install-title {
  font-size: 14px;
  font-weight: 700;
}

.install-sub {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 2px;
}

.install-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.install-btn {
  padding: 8px 12px;
  background: var(--orange);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.install-btn-secondary {
  background: transparent;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

/* Loading dots */
.loading {
  align-self: flex-start;
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 14px 18px;
  display: inline-flex;
  gap: 4px;
}

.loading span {
  width: 7px;
  height: 7px;
  background: var(--muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.loading span:nth-child(2) { animation-delay: 0.15s; }
.loading span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}
