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

:root {
  --accent:      #1e7a47;
  --accent-light:#e8f5ee;
  --accent-mid:  #2d9e5f;
  --bg:          #f7f8f7;
  --bg2:         #ffffff;
  --bg3:         #f0f2f0;
  --border:      #e2e6e2;
  --text:        #1a1f1a;
  --text2:       #5a6b5a;
  --text3:       #9aaa9a;
  --danger:      #d93025;
  --warning:     #e07b00;
  --success:     #1e7a47;
  --mono:        'DM Mono', monospace;
  --sans:        'Inter', sans-serif;
  --radius:      16px;
  --radius-sm:   10px;
  --radius-xs:   6px;
  --shadow:      0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-y: scroll; /* always show scrollbar, prevents layout shift */
}

/* ── App shell ── */
.app-shell {
  display: grid;
  grid-template-rows: 56px 1fr;
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-brand {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.main {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  overflow-y: scroll; /* instead of auto */
  scrollbar-width: none; /* Firefox */
}

.main::-webkit-scrollbar {
  display: none; /* Chrome, Safari */
}

/* ── Cards ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

/* ── Temperature hero card ── */
.temp-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  position: relative;
}

.temp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.device-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.online-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text3);
}

.online-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--border);
}
.online-dot.online {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(30,122,71,0.15);
}

.temp-main {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 16px;
}

.temp-value {
  font-size: 72px;
  font-weight: 300;
  letter-spacing: -2px;
  line-height: 1;
  color: var(--text);
  font-family: var(--sans);
}

.temp-value.error-state { color: var(--danger); }

.temp-meta {
  padding-bottom: 8px;
}

.temp-setpoint {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 4px;
}

.temp-setpoint span {
  font-weight: 600;
  color: var(--text);
}

.relay-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--bg3);
  color: var(--text3);
}

.relay-indicator.active {
  background: rgba(224,123,0,0.1);
  color: var(--warning);
}

.temp-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  cursor: default;
}

.badge-boost   { background: rgba(30,122,71,0.1); color: var(--accent); }
.badge-force   { background: rgba(224,123,0,0.1); color: var(--warning); }
.badge-disabled{ background: rgba(217,48,37,0.1); color: var(--danger); }
.badge-offline { background: var(--bg3); color: var(--text3); }

/* ── Section title ── */
.section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 10px;
}

/* ── Boost buttons ── */
.boost-options {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.boost-option {
  flex: 1;
  min-width: 48px;
  padding: 10px 4px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.boost-option:hover { border-color: var(--accent); color: var(--accent); }
.boost-option.selected {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  width: 100%;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-mid); }
.btn-danger  { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-warning { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover { border-color: var(--text2); }
.btn-ghost   { background: var(--bg3); color: var(--text2); border-color: transparent; }

.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.tab {
  flex: 1;
  padding: 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Schedule ── */
.schedule-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.schedule-row label {
  font-size: 13px;
  color: var(--text2);
  min-width: 60px;
}

input[type="time"] {
  background: var(--bg3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  padding: 8px 10px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

input[type="time"]:focus { border-color: var(--accent); }

input[type="number"] {
  background: var(--bg3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  padding: 8px 10px;
  outline: none;
  width: 90px;
}

input[type="number"]:focus { border-color: var(--accent); }

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px; height: 16px;
  cursor: pointer;
}

/* ── Info rows (settings tab) ── */
.info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.info-row:last-child { border-bottom: none; }
.info-row-label { color: var(--text2); }
.info-row-value { font-family: var(--mono); font-weight: 500; font-size: 13px; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--bg2);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px 32px;
  width: 100%;
  max-width: 480px;
  transform: translateY(20px);
  transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}
.modal-close {
  float: right;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text3);
  line-height: 1;
}

/* ── Offline ── */
#device-panel.offline .card:not(#alert-settings-card) { opacity: 0.6; }
#device-panel.offline .btn:not(#alert-settings-card .btn)  { pointer-events: none; opacity: 0.5; }
#device-panel.offline .boost-option { pointer-events: none; }
#device-panel.offline input:not(#alert-settings-card input) { pointer-events: none; opacity: 0.5; }

/* ── Login ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 28px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-md);
}
.login-logo {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 500;
  color: var(--accent);
  text-align: center;
  letter-spacing: 0.1em;
  margin-bottom: 28px;
}
.login-field { margin-bottom: 14px; }
.login-field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text3);
  margin-bottom: 6px;
}
.login-field input {
  width: 100%;
  background: var(--bg3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  padding: 11px 14px;
  outline: none;
}
.login-field input:focus { border-color: var(--accent); }
.login-error { color: var(--danger); font-size: 13px; margin-bottom: 10px; min-height: 18px; }

.option-desc {
  font-size:13px;
  color:var(--text2);
  margin-bottom:10px;
}

/* ── Mode option ── */
.mode-option {
  display: flex;
  flex-direction: column;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  gap: 4px;
}
.mode-option:last-of-type { border-bottom: none; }

.mode-option-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.mode-option-header input[type="checkbox"] {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin: 0;
}
.mode-option-header strong {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

/* ── Portal footer ── */
.portal-footer {
  text-align: center;
  padding: 20px 20px 24px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}
.footer-logo {
  height: 20px;
  opacity: 0.3;
  margin-bottom: 6px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}
.footer-copy {
  font-size: 10px;
  color: var(--text3);
  line-height: 1.6;
  max-width: 300px;
  margin: 0 auto;
}

/* ── Account button (topbar) ── */
.account-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent-light);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

/* ── CWH segmented tabs ── */
.cwh-tabs {
  display: flex;
  background: var(--bg3);
  border-radius: 12px;
  padding: 3px;
  margin-bottom: 12px;
  /* Remove sticky for now — causes the gap */
}

.cwh-tab {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.cwh-tab.active {
  background: var(--bg2);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

@media (hover: hover) and (pointer: fine) {
  .qs-wrapper:hover .qs-delete-desktop {
    display: block !important;
  }
  .qs-delete-desktop:hover {
    color: var(--danger) !important;
    background: var(--bg3) !important;
  }
}