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

  :root {
    --bg: #0d0f14;
    --surface: #13161d;
    --surface2: #1a1e28;
    --border: rgba(255,255,255,0.08);
    --border2: rgba(255,255,255,0.14);
    --text: #f0f2f7;
    --muted: #7a8098;
    --accent: #3de8a0;
    --accent-dim: rgba(61,232,160,0.12);
    --accent-dim2: rgba(61,232,160,0.22);
    --warn: #f5a623;
    --warn-dim: rgba(245,166,35,0.12);
    --danger: #e8534a;
    --danger-dim: rgba(232,83,74,0.12);
    --mono: 'JetBrains Mono', monospace;
    --sans: 'Inter', system-ui, sans-serif;
    --radius: 12px;
    --radius-sm: 8px;
  }

  body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
  }

  .page { display: none; width: 100%; max-width: 480px; }
  .page.active { display: block; }

  /* ── LOGIN / REGISTER / WIFI PAGES ── */
  .login-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .brand {
    text-align: center;
    margin-bottom: 2.5rem;
  }

  .brand-icon {
    width: 56px; height: 56px;
    background: var(--accent-dim2);
    border: 1px solid var(--accent);
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
  }

  .brand-icon svg { color: var(--accent); }

  .brand h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
  }

  .brand p {
    font-size: 0.8125rem;
    color: var(--muted);
    margin-top: 0.25rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .card {
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: var(--radius);
    padding: 1.75rem;
  }

  .field { margin-bottom: 1.25rem; }

  .field-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
  }

  .field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0.07em;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
  }

  /* Scan button */
  .btn-scan {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: 1px solid var(--border2);
    border-radius: 100px;
    color: var(--muted);
    font-family: var(--sans);
    font-size: 0.6875rem;
    font-weight: 500;
    padding: 0.2rem 0.6rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    letter-spacing: 0.04em;
  }

  .btn-scan:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
  }

  .btn-scan:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }

  .btn-scan svg {
    flex-shrink: 0;
    transition: transform 0.6s ease;
  }

  .btn-scan.scanning svg {
    animation: spin 0.7s linear infinite;
  }

  /* Network list */
  .network-list-wrap {
    background: var(--surface2);
    border: 1px solid var(--border2);
    border-radius: var(--radius-sm);
    overflow: hidden;
    min-height: 48px;
    position: relative;
  }

  .network-list {
    list-style: none;
    max-height: 240px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border2) transparent;
  }

  .network-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.12s;
    user-select: none;
  }

  .network-item:last-child { border-bottom: none; }

  .network-item:hover { background: rgba(255,255,255,0.04); }

  .network-item.selected {
    background: var(--accent-dim);
    border-color: rgba(61,232,160,0.15);
  }

  .network-item.selected .net-name { color: var(--accent); }

  .net-icon { flex-shrink: 0; color: var(--muted); }
  .network-item.selected .net-icon { color: var(--accent); }

  .net-info { flex: 1; min-width: 0; }

  .net-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .net-meta {
    font-size: 0.6875rem;
    color: var(--muted);
    font-family: var(--mono);
    margin-top: 1px;
    display: flex;
    gap: 0.625rem;
  }

  .net-sec {
    display: flex;
    align-items: center;
    gap: 3px;
  }

  .signal-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 14px;
    flex-shrink: 0;
  }

  .signal-bars span {
    width: 3px;
    background: var(--border2);
    border-radius: 1px;
  }

  .signal-bars span.on { background: var(--accent); }
  .signal-bars span.on.warn { background: var(--warn); }
  .signal-bars span:nth-child(1) { height: 30%; }
  .signal-bars span:nth-child(2) { height: 55%; }
  .signal-bars span:nth-child(3) { height: 80%; }
  .signal-bars span:nth-child(4) { height: 100%; }

  /* Empty / loading / error states inside the list */
  .list-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.5rem 1rem;
    color: var(--muted);
    font-size: 0.8125rem;
    text-align: center;
  }

  .list-state svg { opacity: 0.4; }

  /* Selected network chip shown below list */
  .selected-chip {
    display: none;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--accent);
    font-family: var(--mono);
  }

  .selected-chip.show { display: flex; }

  /* Inputs */
  .pw-wrap { position: relative; }

  .field select,
  .field input[type="password"],
  .field input[type="text"],
  .field input[type="email"] {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border2);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--sans);
    font-size: 0.9375rem;
    padding: 0.75rem 1rem;
    appearance: none;
    -webkit-appearance: none;
    outline: none;
    transition: border-color 0.15s;
  }

  .field input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
  }

  .pw-toggle {
    position: absolute; right: 12px; top: 50%;
    transform: translateY(-50%);
    background: none; border: none; cursor: pointer;
    color: var(--muted); padding: 4px;
    display: flex; align-items: center;
  }

  .btn-primary {
    width: 100%;
    background: var(--accent);
    color: #0d1a12;
    font-family: var(--sans);
    font-size: 0.9375rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.875rem;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
  }

  .btn-primary:hover { opacity: 0.9; }
  .btn-primary:active { transform: scale(0.98); }
  .btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

  .status-bar {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-size: 0.8125rem;
    color: var(--muted);
    margin-top: 1.25rem;
    padding: 0.75rem 1rem;
    background: var(--surface2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    min-height: 46px;
  }

  .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--border2);
    flex-shrink: 0;
  }

  .dot.connecting { background: var(--warn); animation: pulse 1s infinite; }
  .dot.success { background: var(--accent); }
  .dot.error { background: var(--danger); }

  @keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
  }

  .spinner {
    width: 16px; height: 16px;
    border: 2px solid rgba(13,26,18,0.3);
    border-top-color: #0d1a12;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
  }

  @keyframes spin { to { transform: rotate(360deg); } }

  /* Login ⇄ Register switch link */
  .auth-switch {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.8125rem;
    color: var(--muted);
  }

  .auth-switch a {
    color: var(--accent);
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
  }

  .auth-switch a:hover { text-decoration: underline; }

  /* ── DASHBOARD ── */
  .dash-wrap { padding-bottom: 2rem; }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 0 1.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
  }

  .topbar-left { display: flex; align-items: center; gap: 10px; }

  .logo-sm {
    width: 32px; height: 32px;
    background: var(--accent-dim2);
    border: 1px solid var(--accent);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
  }

  .topbar h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
  }

  .topbar-meta { text-align: right; display: flex; flex-direction: row; align-items: center; gap: 10px; }
  .topbar-meta .ssid { font-size: 0.75rem; font-weight: 500; color: var(--accent); }
  .topbar-meta .ip { font-size: 0.75rem; color: var(--muted); font-family: var(--mono); }
  .topbar-meta .ip.linked { color: var(--accent); }

  .live-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--accent-dim);
    border: 1px solid rgba(61,232,160,0.3);
    border-radius: 100px;
    padding: 0.25rem 0.625rem;
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--accent);
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
  }

  .live-dot {
    width: 6px; height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: pulse 1.5s infinite;
  }

  .metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
  }

  .metric-card {
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: var(--radius);
    padding: 1rem 1.125rem;
  }

  .metric-card .m-label {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0.07em;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
  }

  .metric-card .m-val {
    font-size: 1.625rem;
    font-weight: 600;
    font-family: var(--mono);
    color: var(--text);
    line-height: 1;
  }

  .metric-card .m-unit { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

  .metric-card.accent { background: var(--accent-dim); border-color: rgba(61,232,160,0.3); }
  .metric-card.accent .m-val { color: var(--accent); }
  .metric-card.warn { background: var(--warn-dim); border-color: rgba(245,166,35,0.3); }
  .metric-card.warn .m-val { color: var(--warn); }

  .section { margin-bottom: 1.5rem; }

  .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.875rem;
  }

  .section-header h3 {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0.07em;
    text-transform: uppercase;
  }

  .tab-group {
    display: flex;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 100px;
    padding: 3px;
    gap: 2px;
  }

  .tab {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--muted);
    background: none;
    border: none;
    border-radius: 100px;
    padding: 0.25rem 0.625rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-family: var(--sans);
    white-space: nowrap;
  }

  .tab.active {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border2);
  }

  .chart-card {
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: var(--radius);
    padding: 1rem 1.125rem 1.125rem;
  }

  .chart-wrap { position: relative; width: 100%; height: 180px; }

  .history-list { display: flex; flex-direction: column; gap: 0; }

  .history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
  }

  .history-item:last-child { border-bottom: none; }
  .history-item .h-time { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); min-width: 80px; }
  .history-item .h-event { color: var(--text); flex: 1; padding: 0 0.75rem; }
  .history-item .h-val { font-family: var(--mono); font-size: 0.8125rem; font-weight: 500; color: var(--accent); }
  .history-item .h-val.high { color: var(--warn); }

  .footer-note {
    font-size: 0.6875rem;
    color: var(--muted);
    text-align: center;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    font-family: var(--mono);
  }
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(8, 10, 18, 0.82);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
  }
  .modal-overlay.open { display: flex; }

  .modal {
    background: #161924;
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 16px;
    padding: 1.75rem;
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
  }
  .modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #f0f2f7;
    margin: 0;
  }
  .modal-close {
    background: none;
    border: none;
    color: #7a8098;
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    transition: color 0.15s;
  }
  .modal-close:hover { color: #f0f2f7; }

  /* Step indicator */
  .modal-steps {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
  }
  .modal-step {
    flex: 1;
    height: 3px;
    border-radius: 2px;
    background: rgba(255,255,255,0.08);
    transition: background 0.3s;
  }
  .modal-step.done { background: #3de8a0; }
  .modal-step.active { background: rgba(61,232,160,0.45); }

  .modal-step-label {
    font-size: 0.6875rem;
    color: #7a8098;
    font-family: 'JetBrains Mono', monospace;
    margin-bottom: 0.875rem;
    letter-spacing: 0.03em;
  }

  /* Reuse existing scan / network styles inside modal */
  .modal .network-list-wrap {
    background: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 10px;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    margin-bottom: 0.75rem;
  }
  .modal .network-list {
    list-style: none;
    margin: 0; padding: 0;
    width: 100%;
    max-height: 200px;
    overflow-y: auto;
  }
  .modal .list-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 1rem 0;
    color: #7a8098;
    font-size: 0.8125rem;
    text-align: center;
  }
  .modal .network-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
  }
  .modal .network-item:hover,
  .modal .network-item.selected { background: rgba(61,232,160,0.08); }
  .modal .network-item.selected { outline: 1px solid rgba(61,232,160,0.3); }
  .modal .net-name { font-size: 0.8125rem; font-weight: 500; color: #f0f2f7; }
  .modal .net-meta { font-size: 0.6875rem; color: #7a8098; font-family: 'JetBrains Mono', monospace; }
  .modal .net-info { display: flex; flex-direction: column; flex: 1; }
  .modal .signal-bars { display: flex; align-items: flex-end; gap: 2px; height: 14px; }
  .modal .signal-bars span {
    width: 3px;
    background: rgba(255,255,255,0.15);
    border-radius: 1px;
  }
  .modal .signal-bars span:nth-child(1) { height: 25%; }
  .modal .signal-bars span:nth-child(2) { height: 50%; }
  .modal .signal-bars span:nth-child(3) { height: 75%; }
  .modal .signal-bars span:nth-child(4) { height: 100%; }
  .modal .signal-bars span.on { background: #3de8a0; }
  .modal .signal-bars span.warn { background: #f5a623; }
  .modal .net-icon { color: #7a8098; }

  /* Field used inside modal */
  .modal .field { margin-bottom: 1rem; }
  .modal .field label { display: block; font-size: 0.75rem; color: #7a8098; margin-bottom: 0.4rem; }
  .modal .field input {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 0.6rem 0.875rem;
    color: #f0f2f7;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
  }
  .modal .field input:focus { border-color: rgba(61,232,160,0.45); }
  .modal .pw-wrap { position: relative; }
  .modal .pw-wrap input { padding-right: 2.5rem; }
  .modal .pw-toggle {
    position: absolute; right: 0.625rem; top: 50%;
    transform: translateY(-50%);
    background: none; border: none; color: #7a8098; cursor: pointer; padding: 2px;
    display: flex; align-items: center;
  }
  .modal .pw-toggle:hover { color: #f0f2f7; }

  /* OTP display */
  .otp-box {
    background: rgba(61,232,160,0.07);
    border: 1px solid rgba(61,232,160,0.25);
    border-radius: 12px;
    padding: 1.25rem;
    text-align: center;
    margin-bottom: 1rem;
  }
  .otp-label {
    font-size: 0.6875rem;
    color: #7a8098;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.06em;
    margin-bottom: 0.5rem;
  }
  .otp-code {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: 0.25em;
    color: #3de8a0;
    font-family: 'JetBrains Mono', monospace;
    line-height: 1;
    margin-bottom: 0.75rem;
  }
  .otp-timer-bar-wrap {
    background: rgba(255,255,255,0.08);
    border-radius: 99px;
    height: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
  }
  .otp-timer-bar {
    height: 100%;
    background: #3de8a0;
    border-radius: 99px;
    transition: width 1s linear, background 0.3s;
    width: 100%;
  }
  .otp-timer-text {
    font-size: 0.6875rem;
    color: #7a8098;
    font-family: 'JetBrains Mono', monospace;
  }
  .otp-timer-bar.warn-bar { background: #f5a623; }
  .otp-timer-bar.danger-bar { background: #e8534a; }

  .otp-note {
    font-size: 0.75rem;
    color: #7a8098;
    text-align: center;
    line-height: 1.5;
    margin-bottom: 1rem;
  }

  /* Device chip shown on register form after device added */
  .device-chip {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.875rem;
    background: rgba(61,232,160,0.07);
    border: 1px solid rgba(61,232,160,0.25);
    border-radius: 8px;
    font-size: 0.8125rem;
    color: #3de8a0;
    font-family: 'JetBrains Mono', monospace;
  }
  .device-chip.show { display: flex; }
  .device-chip-icon { flex-shrink: 0; }
  .device-chip-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .device-chip-remove {
    background: none; border: none; color: #7a8098; cursor: pointer;
    padding: 0; display: flex; align-items: center;
  }
  .device-chip-remove:hover { color: #e8534a; }

  /* Add device button (styled differently from btn-primary) */
  .btn-add-device {
    width: 100%;
    padding: 0.65rem 1rem;
    background: rgba(61,232,160,0.08);
    border: 1px dashed rgba(61,232,160,0.35);
    border-radius: 10px;
    color: #3de8a0;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: background 0.2s, border-color 0.2s;
  }
  .btn-add-device:hover {
    background: rgba(61,232,160,0.14);
    border-color: rgba(61,232,160,0.55);
  }

  .field-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
  }
  .field-header label { margin-bottom: 0 !important; }

  .btn-scan {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.65rem;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    color: #c8cdd8;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
  }
  .btn-scan:hover { background: rgba(255,255,255,0.10); }
  .btn-scan.scanning { opacity: 0.6; pointer-events: none; }

  .selected-chip {
    display: none;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: #3de8a0;
    font-family: 'JetBrains Mono', monospace;
  }
  .selected-chip.show { display: flex; }

  @keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
  }
  .modal .btn-primary {
    width: 100%;
    padding: 0.75rem;
    background: #3de8a0;
    border: none;
    border-radius: 10px;
    color: #0b0f1a;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: opacity 0.2s;
    margin-top: 0.25rem;
  }
  .modal .btn-primary:hover { opacity: 0.88; }
  .modal .btn-primary:disabled { opacity: 0.45; pointer-events: none; }

  .modal .status-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    font-size: 0.75rem;
    color: #7a8098;
    font-family: 'JetBrains Mono', monospace;
    min-height: 1.25rem;
  }
  .dot { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,0.2); flex-shrink: 0; }
  .dot.connecting { background: #f5a623; animation: pulse 1s ease-in-out infinite; }
  .dot.success    { background: #3de8a0; }
  .dot.error      { background: #e8534a; }
  @keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

  .spinner {
    width: 14px; height: 14px;
    border: 2px solid rgba(11,15,26,0.3);
    border-top-color: #0b0f1a;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
  }
/* ═══════════════════════════════════════════════════════════════════════
   RESPONSIVE LAYOUT
   Base styles above are mobile-first (good as-is on phones). These
   breakpoints widen the dashboard for tablet/desktop and fix a few edge
   cases on very small/narrow phones and notched devices, without
   changing how anything looks on a typical phone screen.
   ═══════════════════════════════════════════════════════════════════════ */

/* Respect notches / home indicators (iOS) when the page fills the screen */
body {
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-top: max(1rem, env(safe-area-inset-top));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

/* Replaces the inline style="height:160px" previously on the monthly chart,
   so responsive breakpoints can actually resize it (inline styles always
   beat external CSS, even inside media queries). */
.chart-wrap.chart-wrap--short { height: 160px; }

/* ── Very small phones (<360px): tighten spacing, prevent topbar overflow ── */
@media (max-width: 359px) {
  .card { padding: 1.25rem; }
  .brand h1 { font-size: 1.3rem; }
  .metrics-grid { gap: 0.5rem; }
  .metric-card { padding: 0.8rem 0.875rem; }
  .metric-card .m-val { font-size: 1.375rem; }

  .topbar {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding-bottom: 1rem;
  }
  .topbar-meta {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

/* ── Tablet and up (≥700px): dashboard gets real breathing room ── */
@media (min-width: 700px) {
  #page-dashboard.page {
    max-width: min(94vw, 900px);
  }

  .metrics-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .chart-wrap { height: 220px; }

  /* Login/register stay comfortably card-sized rather than stretching --
     a 480px form on a wide screen still reads correctly. */
  .login-wrap { justify-content: center; }
}

/* ── Small laptop / desktop (≥1024px): wider dashboard, bigger charts ── */
@media (min-width: 1024px) {
  #page-dashboard.page {
    max-width: min(90vw, 1200px);
  }

  .chart-wrap { height: 280px; }
  .chart-wrap.chart-wrap--short { height: 220px; } /* monthly chart override */

  .metric-card .m-val { font-size: 1.875rem; }

  .topbar { padding: 1.5rem 0 1.75rem; }
}

/* ── Large desktop (≥1440px): scale further, cap only on ultra-wide ── */
@media (min-width: 1440px) {
  #page-dashboard.page {
    max-width: min(85vw, 1600px);
  }

  .chart-wrap { height: 320px; }
  .chart-wrap.chart-wrap--short { height: 240px; }
}

/* ── Landscape phones: avoid the centered-form layout eating the whole
   viewport height awkwardly on short, wide screens ── */
@media (max-height: 480px) and (orientation: landscape) {
  body { align-items: flex-start; }
  .login-wrap { min-height: auto; padding: 1.5rem 0; }
  .brand { margin-bottom: 1.25rem; }
}

/* ── Touch-friendlier tap targets on coarse pointers (phones/tablets) ── */
@media (pointer: coarse) {
  .btn-scan, .pw-toggle, .modal-close {
    min-height: 36px;
    min-width: 36px;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   WELCOME LINE + LIVE BILL ESTIMATE CARD
   ═══════════════════════════════════════════════════════════════════════ */

.welcome-line {
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
  color: var(--muted, #7a8098);
}

.bill-rate-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.bill-rate-row label {
  font-size: 0.8125rem;
  color: var(--muted, #7a8098);
  font-weight: 500;
}

.bill-rate-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--mono, 'JetBrains Mono', monospace);
  font-size: 0.875rem;
  color: var(--text, #f0f2f7);
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
}

.bill-rate-input-wrap input {
  width: 80px;
  background: transparent;
  border: none;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  text-align: right;
  outline: none;
}

.bill-rate-input-wrap input::-webkit-outer-spin-button,
.bill-rate-input-wrap input::-webkit-inner-spin-button {
  opacity: 1;
}

#bill-estimate-card .metrics-grid {
  margin-top: 0;
}

@media (min-width: 700px) {
  #bill-estimate-card .metrics-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}