/* ═══════════════════════════════════════════════
   CVA View Control — style.css
   Friendly, clean, touch-first design
═══════════════════════════════════════════════ */

:root {
  --bg:        #f5f6fa;
  --bg2:       #ffffff;
  --surface:   #ffffff;
  --border:    #e8eaef;
  --border2:   #d1d5e0;
  --blue:      #4361ee;
  --blue-lt:   #eef0fd;
  --blue-dk:   #3451d1;
  --green:     #2dc653;
  --green-lt:  #e8faf0;
  --red:       #ef4444;
  --red-lt:    #fef2f2;
  --amber:     #f59e0b;
  --amber-lt:  #fffbeb;
  --gray:      #6b7280;
  --gray-lt:   #f3f4f6;
  --text:      #111827;
  --text2:     #4b5563;
  --text3:     #9ca3af;
  --font:      'Plus Jakarta Sans', system-ui, sans-serif;
  --radius-sm: 10px;
  --radius:    16px;
  --radius-lg: 22px;
  --shadow:    0 2px 12px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 24px rgba(0,0,0,0.12);
  --tab-h:     64px;
  --header-h:  60px;
  --strip-h:   58px;
  --banner-h:  44px;
  --ease:      cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { font-size: 15px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100dvh; overflow: hidden; }
button { cursor: pointer; font-family: var(--font); border: none; background: none; }
input  { font-family: var(--font); }
a { text-decoration: none; color: inherit; }

/* ── Toast ──────────────────────────────────── */
#toast-container {
  position: fixed; bottom: calc(var(--tab-h) + 16px); left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999; pointer-events: none;
  width: min(94vw, 420px);
}
.toast {
  background: #1f2937; color: #fff;
  border-radius: 12px; padding: 13px 16px;
  font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  pointer-events: all; cursor: pointer;
  animation: toastIn 0.25s var(--ease) both;
}
.toast.removing { animation: toastOut 0.2s var(--ease) forwards; }
@keyframes toastIn  { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes toastOut { to   { transform: translateY(16px); opacity: 0; } }
.toast-icon { font-size: 18px; flex-shrink: 0; }
.toast.success .toast-icon::before { content: '✅'; }
.toast.error   .toast-icon::before { content: '❌'; }
.toast.info    .toast-icon::before { content: '💬'; }
.toast.warn    .toast-icon::before { content: '⚠️'; }

/* ── Modal ──────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0; z-index: 8000;
  background: rgba(0,0,0,0.45); backdrop-filter: blur(6px);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  transition: opacity 0.2s;
}
#modal-overlay.hidden { opacity: 0; pointer-events: none; display: flex !important; }
#modal-box {
  background: var(--bg2); border-radius: 24px 24px 0 0;
  padding: 28px 24px 40px; width: 100%; max-width: 560px;
  position: relative; max-height: 90dvh; overflow-y: auto;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.18);
  animation: slideSheet 0.28s var(--ease);
}
#modal-overlay.hidden #modal-box { animation: none; }
@keyframes slideSheet { from { transform: translateY(60px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-close-btn {
  position: absolute; top: 16px; right: 16px;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--gray-lt); color: var(--text2);
  font-size: 14px; display: flex; align-items: center; justify-content: center;
}
.modal-close-btn:hover { background: var(--border2); }
.modal-title { font-size: 20px; font-weight: 800; margin-bottom: 6px; }
.modal-sub { font-size: 14px; color: var(--text2); margin-bottom: 24px; line-height: 1.5; }
.modal-form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text2); }
.form-hint  { font-size: 12px; color: var(--text3); margin-top: -2px; }
.form-input {
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  padding: 13px 15px; font-size: 15px; color: var(--text);
  background: var(--bg); outline: none;
  transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--blue); }
.form-input::placeholder { color: var(--text3); }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .cancel-btn {
  flex: 1; padding: 14px; background: var(--gray-lt); border-radius: var(--radius-sm);
  color: var(--text2); font-size: 15px; font-weight: 600;
}
.modal-actions .submit-btn {
  flex: 2; padding: 14px; background: var(--blue); border-radius: var(--radius-sm);
  color: #fff; font-size: 15px; font-weight: 700;
}
.modal-actions .submit-btn:hover { background: var(--blue-dk); }
.modal-actions .danger-submit {
  flex: 2; padding: 14px; background: var(--red); border-radius: var(--radius-sm);
  color: #fff; font-size: 15px; font-weight: 700;
}

/* ─── ONBOARDING ─────────────────────────────── */
#onboarding-screen {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: linear-gradient(160deg, #eef0fd 0%, #f5f6fa 60%);
}
.onboard-inner {
  width: 100%; max-width: 480px; text-align: center;
}
.onboard-emoji { font-size: 64px; margin-bottom: 12px; display: block; }
.onboard-title { font-size: 28px; font-weight: 800; margin-bottom: 10px; }
.onboard-sub { font-size: 16px; color: var(--text2); margin-bottom: 32px; line-height: 1.6; }

.steps-list { display: flex; flex-direction: column; gap: 14px; margin-bottom: 36px; text-align: left; }
.step-item  { display: flex; align-items: flex-start; gap: 14px; }
.step-bubble {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--blue); color: #fff;
  font-size: 14px; font-weight: 800; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.step-body { display: flex; flex-direction: column; gap: 2px; }
.step-body strong { font-size: 15px; font-weight: 700; }
.step-body span   { font-size: 13px; color: var(--text2); }

/* Onboard buttons */
.ob-btn {
  width: 100%; display: flex; align-items: center; gap: 16px;
  padding: 16px 20px; border-radius: var(--radius); margin-bottom: 12px;
  text-align: left; transition: transform 0.12s, box-shadow 0.12s;
}
.ob-btn:active { transform: scale(0.98); }
.ob-primary  { background: var(--blue); box-shadow: 0 4px 16px rgba(67,97,238,0.35); }
.ob-primary .ob-icon, .ob-primary .ob-main { color: #fff; }
.ob-primary .ob-hint { color: rgba(255,255,255,0.75); }
.ob-secondary { background: var(--surface); border: 2px solid var(--border); }
.ob-secondary .ob-main { color: var(--text); }
.ob-secondary .ob-hint { color: var(--text2); }
.ob-icon { font-size: 26px; flex-shrink: 0; }
.ob-text { display: flex; flex-direction: column; gap: 2px; }
.ob-main { font-size: 16px; font-weight: 700; }
.ob-hint { font-size: 13px; }

/* ─── APP SHELL ──────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }

/* Header */
#app-header {
  height: var(--header-h); display: flex; align-items: center;
  justify-content: space-between; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex-shrink: 0; z-index: 100;
}
.header-logo { font-size: 18px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.header-logo span { color: var(--text); }
.header-add-btn {
  background: var(--blue); color: #fff;
  padding: 9px 16px; border-radius: 20px;
  font-size: 13px; font-weight: 700;
  white-space: nowrap; transition: background 0.15s;
}
.header-add-btn:hover { background: var(--blue-dk); }

/* Device strip */
#device-strip-wrapper {
  height: var(--strip-h); flex-shrink: 0;
  background: var(--surface); border-bottom: 1px solid var(--border);
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
#device-strip-wrapper::-webkit-scrollbar { display: none; }
#device-strip {
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px; height: 100%; white-space: nowrap;
}

.dev-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 20px;
  border: 2px solid var(--border);
  background: var(--bg); cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  white-space: nowrap; flex-shrink: 0;
  font-size: 14px; font-weight: 600;
}
.dev-pill:hover { background: var(--blue-lt); border-color: var(--blue); }
.dev-pill.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.dev-pill .pill-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text3); flex-shrink: 0;
}
.dev-pill.online .pill-dot  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dev-pill.offline .pill-dot { background: var(--red); }
.dev-pill.active .pill-dot  { background: rgba(255,255,255,0.7); box-shadow: none; }

.strip-empty {
  display: flex; align-items: center; gap: 8px; padding: 0 4px;
  font-size: 13px; color: var(--text3);
}

/* Device banner */
#device-banner {
  background: var(--blue-lt); border-bottom: 1px solid #c7d0f9;
  padding: 8px 16px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px;
}
#db-info { display: flex; align-items: center; gap: 10px; font-weight: 600; }
#db-status { font-size: 12px; font-weight: 500; padding: 3px 9px; border-radius: 20px; }
.status-online  { background: var(--green-lt); color: #15803d; }
.status-offline { background: var(--red-lt);   color: #b91c1c; }
.status-checking{ background: var(--amber-lt); color: #92400e; }
#db-addr { font-size: 11px; color: var(--text3); }

/* Tab bar */
#tab-bar {
  display: flex; background: var(--surface);
  border-top: 1px solid var(--border); flex-shrink: 0;
  height: var(--tab-h); order: 10; /* push to bottom */
  position: relative; z-index: 100;
}
.tab {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  color: var(--text3); transition: color 0.15s;
  font-size: 11px; font-weight: 600; padding-bottom: 4px;
  position: relative;
}
.tab:hover { color: var(--text2); }
.tab.active { color: var(--blue); }
.tab.active::after {
  content: ''; position: absolute; top: 0; left: 20%; right: 20%;
  height: 2px; background: var(--blue); border-radius: 0 0 3px 3px;
}
.ti { font-size: 22px; line-height: 1; }
.tl { letter-spacing: 0.01em; }

/* Tab panels */
.tab-panel {
  flex: 1; overflow-y: auto; display: none;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.tab-panel.active { display: block; }
.tab-panel > * { animation: panelIn 0.2s var(--ease) both; }
@keyframes panelIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ─── SHARED COMPONENTS ──────────────────────── */

/* Pick prompt (no device selected) */
.pick-prompt {
  text-align: center; padding: 60px 30px;
}
.pp-icon { font-size: 52px; margin-bottom: 16px; opacity: 0.7; }
.pick-prompt h2 { font-size: 20px; font-weight: 800; margin-bottom: 8px; }
.pick-prompt p  { font-size: 15px; color: var(--text2); line-height: 1.5; }

/* Section headings */
.sec-heading {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text3);
  padding: 24px 16px 10px;
}

/* Panel top bar */
.panel-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 16px 12px;
}
.panel-title { font-size: 22px; font-weight: 800; }
.panel-sub   { font-size: 13px; color: var(--text2); margin-top: 3px; }
.refresh-btn {
  background: var(--gray-lt); border-radius: 20px;
  padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--text2);
  transition: background 0.15s; flex-shrink: 0;
}
.refresh-btn:hover { background: var(--border); }

/* Tip chip */
.tip-chip {
  margin: 0 16px 14px;
  background: var(--amber-lt); border: 1px solid #fde68a;
  border-radius: 10px; padding: 10px 14px;
  font-size: 13px; color: #92400e; font-weight: 500;
}

/* Loading spinner */
.loading-spinner-wrap {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 48px 20px; gap: 14px; color: var(--text3);
  font-size: 14px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--text3);
}
.empty-state .es-icon { font-size: 44px; margin-bottom: 12px; opacity: 0.5; }
.empty-state h3 { font-size: 17px; font-weight: 700; color: var(--text2); margin-bottom: 6px; }
.empty-state p  { font-size: 14px; line-height: 1.5; }

/* ─── HOME TAB ──────────────────────────────── */

/* Quick grid */
.quick-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; padding: 0 16px 4px;
}
.qcard {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 20px 12px; border-radius: var(--radius);
  background: var(--surface); border: 2px solid var(--border);
  text-align: center; transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
}
.qcard:hover { border-color: var(--blue); box-shadow: var(--shadow); }
.qcard:active { transform: scale(0.97); }
.qci { font-size: 28px; line-height: 1; }
.qcl { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.3; }

/* Volume card */
.vol-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--radius); margin: 0 16px; padding: 18px 16px;
}
.vol-side-btn { font-size: 26px; flex-shrink: 0; padding: 4px; border-radius: 8px; }
.vol-side-btn:hover { background: var(--gray-lt); }
.vol-mid { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.vol-range {
  width: 100%; -webkit-appearance: none; height: 6px;
  background: var(--border); border-radius: 3px; outline: none; cursor: pointer;
}
.vol-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px;
  border-radius: 50%; background: var(--blue);
  box-shadow: 0 2px 8px rgba(67,97,238,0.4);
  transition: transform 0.1s;
}
.vol-range::-webkit-slider-thumb:hover { transform: scale(1.15); }
.vol-row-labels {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--text3); font-weight: 500;
}

/* Control cards row */
.ctrl-row {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; padding: 0 16px 32px;
}
.ctrl-card {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; padding: 22px 12px; border-radius: var(--radius);
  border: 2px solid; text-align: center;
  transition: transform 0.12s, box-shadow 0.12s;
}
.ctrl-card:active { transform: scale(0.97); }
.ctrl-card.safe   { background: #f0fdf4; border-color: #86efac; }
.ctrl-card.danger { background: var(--red-lt); border-color: #fca5a5; }
.cci { font-size: 28px; }
.ccl { font-size: 14px; font-weight: 700; }
.ccd { font-size: 11px; color: var(--text3); }

/* ─── PHOTOS TAB ────────────────────────────── */
.photo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(110px,1fr));
  gap: 8px; padding: 0 16px 24px;
}
.photo-thumb {
  aspect-ratio: 1; border-radius: 12px; overflow: hidden;
  background: var(--gray-lt); border: 2px solid var(--border);
  cursor: pointer; position: relative;
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.photo-thumb:hover  { border-color: var(--blue); transform: scale(1.03); box-shadow: var(--shadow); }
.photo-thumb:active { transform: scale(0.98); }
.photo-thumb.showing {
  border-color: var(--blue); box-shadow: 0 0 0 3px rgba(67,97,238,0.3);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .pt-fallback { font-size: 28px; opacity: 0.3; }
.photo-thumb .pt-badge {
  position: absolute; top: 4px; right: 4px;
  background: var(--blue); color: #fff; border-radius: 6px;
  font-size: 10px; font-weight: 700; padding: 2px 6px;
}
.photo-label {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.65));
  color: #fff; font-size: 10px; padding: 12px 6px 5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ─── REMINDERS TAB ─────────────────────────── */
.add-box {
  display: flex; gap: 8px; padding: 0 16px 14px;
}
.reminder-input {
  flex: 1; border: 2px solid var(--border); border-radius: 12px;
  padding: 13px 16px; font-size: 15px; color: var(--text);
  background: var(--surface); outline: none;
  transition: border-color 0.15s;
}
.reminder-input:focus { border-color: var(--blue); }
.reminder-input::placeholder { color: var(--text3); }
.reminder-add-btn {
  background: var(--blue); color: #fff;
  padding: 13px 20px; border-radius: 12px;
  font-size: 15px; font-weight: 700;
  flex-shrink: 0; transition: background 0.15s;
}
.reminder-add-btn:hover { background: var(--blue-dk); }

#reminders-list { display: flex; flex-direction: column; gap: 8px; padding: 0 16px 32px; }

.reminder-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 2px solid var(--border);
  border-radius: 12px; padding: 15px 16px;
  transition: border-color 0.15s;
}
.reminder-row:hover { border-color: var(--border2); }
.reminder-icon { font-size: 20px; flex-shrink: 0; }
.reminder-text { flex: 1; font-size: 15px; font-weight: 500; min-width: 0; }
.reminder-del {
  width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--text3); transition: background 0.15s, color 0.15s;
}
.reminder-del:hover { background: var(--red-lt); color: var(--red); }

/* ─── SETTINGS TAB ──────────────────────────── */
.settings-header { padding: 24px 16px 8px; }
#settings-list { display: flex; flex-direction: column; gap: 10px; padding: 8px 16px 16px; }
.settings-add-wrap { padding: 8px 16px 32px; }

.settings-device-card {
  background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  transition: border-color 0.15s;
}
.settings-device-card:hover { border-color: var(--border2); }
.sdc-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.sdc-name { font-size: 17px; font-weight: 800; }
.sdc-status {
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 20px;
}
.sdc-meta {
  font-size: 12px; color: var(--text3); margin-bottom: 14px;
  display: flex; flex-direction: column; gap: 3px;
}
.sdc-meta span { display: flex; align-items: center; gap: 6px; }
.sdc-actions { display: flex; gap: 8px; }
.sdc-edit-btn {
  flex: 1; padding: 10px; border-radius: 10px;
  background: var(--gray-lt); font-size: 13px; font-weight: 600; color: var(--text2);
  transition: background 0.15s;
}
.sdc-edit-btn:hover { background: var(--border); }
.sdc-del-btn {
  flex: 1; padding: 10px; border-radius: 10px;
  background: var(--red-lt); font-size: 13px; font-weight: 600; color: var(--red);
  border: 1px solid #fca5a5; transition: background 0.15s;
}
.sdc-del-btn:hover { background: #fee2e2; }

/* ─── SCAN OVERLAY ──────────────────────────── */
#scan-overlay {
  position: fixed; inset: 0; z-index: 7000;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.scan-card {
  background: var(--surface); border-radius: 24px;
  padding: 32px 28px; width: 100%; max-width: 400px; text-align: center;
  box-shadow: var(--shadow-md);
}
.scan-anim { font-size: 52px; margin-bottom: 16px; animation: scanBounce 1.4s ease-in-out infinite; }
@keyframes scanBounce {
  0%,100% { transform: translateY(0) rotate(-10deg); }
  50%      { transform: translateY(-10px) rotate(10deg); }
}
.scan-title { font-size: 20px; font-weight: 800; margin-bottom: 6px; }
.scan-sub   { font-size: 14px; color: var(--text2); margin-bottom: 16px; }
.progress-track { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin-bottom: 12px; }
.progress-fill  { height: 100%; background: var(--blue); border-radius: 4px; width: 0; transition: width 0.4s; }
.scan-found { font-size: 15px; font-weight: 600; color: var(--green); margin-bottom: 8px; }
.scan-cancel-btn {
  margin-top: 16px; padding: 12px 28px; border-radius: 12px;
  background: var(--gray-lt); font-size: 15px; font-weight: 700; color: var(--text2);
  width: 100%; transition: background 0.15s;
}
.scan-cancel-btn:hover { background: var(--border); }

/* ─── UTILITY ───────────────────────────────── */
.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ─── RESPONSIVE ────────────────────────────── */
@media (min-width: 600px) {
  .quick-grid { grid-template-columns: repeat(4, 1fr); }
  .ctrl-row   { grid-template-columns: repeat(2, 1fr); }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); }
  #modal-overlay { align-items: center; padding: 20px; }
  #modal-box { border-radius: 24px; max-width: 480px; margin: auto; }
}

@media (min-width: 900px) {
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(160px,1fr)); }
  #tab-bar { order: unset; }
}
