/* ── NABU COMPONENTS — Sprint 4 ──────────────────────────────────────────── */

/* ── RESET ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }
html { font-size:16px; -webkit-text-size-adjust:100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: var(--line-height);
  letter-spacing: var(--letter-space);
  word-spacing: var(--word-space);
  min-height: 100vh; min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-align: left;
}

/* ── LOADING SCREEN ──────────────────────────────────────────────────────── */
.loading-screen {
  position:fixed; inset:0; background:var(--bg);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  z-index:1000; transition: opacity 0.6s ease, visibility 0.6s ease;
}
.loading-screen.fade-out { opacity:0; visibility:hidden; pointer-events:none; }
.loading-diamond { font-size:36px; color:var(--gold); animation: pulse-gold 2s ease-in-out infinite; }
.loading-name { font-family:var(--font-display); font-size:42px; font-weight:600; color:var(--gold); letter-spacing:0.15em; margin-top:16px; }
.loading-sub { font-size:var(--text-sm); font-weight:300; color:var(--text-3); letter-spacing:0.08em; margin-top:8px; }
@keyframes pulse-gold {
  0%,100% { opacity:0.4; transform:scale(1); }
  50%     { opacity:1;   transform:scale(1.15); }
}

/* ── TOP BAR ─────────────────────────────────────────────────────────────── */
.topbar {
  position:sticky; top:0; z-index:100;
  height:var(--topbar-h); display:flex; align-items:center; justify-content:space-between;
  padding:0 var(--padding); background:var(--bg);
  border-bottom:1px solid var(--border);
  backdrop-filter:blur(12px); -webkit-backdrop-filter:blur(12px);
}
@supports (padding-top: env(safe-area-inset-top)) {
  .topbar { padding-top:env(safe-area-inset-top); height:calc(var(--topbar-h) + env(safe-area-inset-top)); }
}
.topbar-left  { display:flex; align-items:center; gap:10px; }
.topbar-right { display:flex; align-items:center; gap:14px; }
.topbar-diamond { color:var(--gold); font-size:14px; }
.topbar-title { font-family:var(--font-display); font-size:18px; font-weight:600; color:var(--gold); letter-spacing:0.12em; }
.topbar-time { font-size:var(--text-sm); font-weight:300; color:var(--text-3); font-variant-numeric:tabular-nums; }
.topbar-status { width:8px; height:8px; border-radius:50%; background:var(--text-muted); transition:background 0.4s ease; }
.topbar-status.online { background:var(--green); box-shadow:0 0 6px var(--green); }
.topbar-theme {
  width:32px; height:32px; border-radius:var(--radius-full);
  background:var(--surface-2); border:1px solid var(--border);
  color:var(--gold); font-size:14px; cursor:pointer;
  display:flex; align-items:center; justify-content:center;
  transition: background var(--duration) var(--ease), border-color var(--duration) var(--ease);
}
.topbar-theme:hover { background:var(--surface-hover); border-color:var(--border-2); }
.topbar-theme:active { transform:scale(0.92); }

/* ── BOTTOM NAV ──────────────────────────────────────────────────────────── */
.bottomnav {
  position:fixed; bottom:0; left:0; right:0; z-index:100;
  height:var(--bottomnav-h); background:var(--bg); border-top:1px solid var(--border);
  display:flex; align-items:center; justify-content:space-around;
  backdrop-filter:blur(12px); -webkit-backdrop-filter:blur(12px);
}
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottomnav { height:calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); padding-bottom:env(safe-area-inset-bottom); }
}
.nav-item {
  display:flex; flex-direction:column; align-items:center; gap:4px;
  padding:6px 16px; border-radius:var(--radius);
  background:none; border:none; cursor:pointer;
  color:var(--text-muted); font-family:var(--font-body);
  transition: color var(--duration) var(--ease);
  -webkit-tap-highlight-color:transparent;
}
.nav-item:hover { color:var(--text-3); }
.nav-item.active { color:var(--gold); }
.nav-icon { font-size:20px; line-height:1; }
.nav-label { font-size:var(--text-xs); font-weight:400; letter-spacing:var(--letter-space-ui); }

/* ── VIEWS ───────────────────────────────────────────────────────────────── */
.view {
  display:none; max-width:var(--content-max); margin:0 auto;
  padding:var(--padding);
  padding-bottom:calc(var(--bottomnav-h) + 24px + env(safe-area-inset-bottom, 0px));
}
.view.active { display:block; animation: view-enter 0.3s ease both; }
@keyframes view-enter {
  from { opacity:0; transform:translateY(6px); }
  to   { opacity:1; transform:translateY(0); }
}

/* Chat view — flexbox layout so messages fill space */
.view--chat {
  display:none; flex-direction:column;
  max-width:var(--content-max); margin:0 auto;
  padding:0 var(--padding);
  padding-bottom:calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  height:calc(100vh - var(--topbar-h));
  height:calc(100dvh - var(--topbar-h));
}
.view--chat.active { display:flex; animation: none; }

/* ── HERO ────────────────────────────────────────────────────────────────── */
.hero { padding:24px 0 20px; }
.hero-greeting { font-family:var(--font-display); font-size:var(--text-2xl); font-weight:600; color:var(--text); line-height:1.2; }
.hero-date { font-size:var(--text-sm); font-weight:300; color:var(--text-3); margin-top:6px; letter-spacing:0.04em; }

/* ── CARDS ────────────────────────────────────────────────────────────────── */
.card {
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius-lg); margin-bottom:14px; overflow:hidden;
  transition: border-color var(--duration) var(--ease);
}
.card:hover { border-color:var(--border-2); }
.card-header {
  display:flex; align-items:center; gap:10px;
  padding:14px 18px 12px; border-bottom:1px solid var(--border);
}
.card-diamond { color:var(--gold); font-size:11px; }
.card-title { font-family:var(--font-display); font-size:var(--text-base); font-weight:600; color:var(--gold); letter-spacing:0.04em; flex:1; }
.card-badge { font-size:var(--text-xs); font-weight:500; color:var(--text-muted); padding:2px 8px; border-radius:var(--radius-full); background:var(--surface-2); letter-spacing:var(--letter-space-ui); }
.card-chevron { color:var(--text-muted); font-size:var(--text-sm); transition: transform var(--duration) var(--ease); }
.card-body { padding:14px 18px 18px; font-size:var(--text-sm); color:var(--text-2); }

.card-body--placeholder { display:flex; flex-direction:column; align-items:center; padding:24px 18px; text-align:center; }
.placeholder-icon { font-size:24px; color:var(--gold-dark); margin-bottom:8px; opacity:0.4; }
.placeholder-text { font-size:var(--text-sm); color:var(--text-muted); font-weight:300; }

.card--collapsible summary { cursor:pointer; list-style:none; }
.card--collapsible summary::-webkit-details-marker { display:none; }
.card--collapsible .card-header--clickable { cursor:pointer; user-select:none; }
.card--collapsible .card-header--clickable:hover { background:var(--surface-2); }
.card--collapsible[open] .card-chevron { transform:rotate(90deg); }

.status-row { display:flex; align-items:center; justify-content:space-between; padding:9px 0; border-bottom:1px solid var(--border); font-size:var(--text-sm); }
.status-row:last-child { border-bottom:none; }
.status-label { color:var(--text-2); }
.status-value { font-weight:500; font-variant-numeric:tabular-nums; }
.status-value.ok { color:var(--green); }
.status-value.pending { color:var(--text-muted); }
.status-value.connected { color:var(--gold); }

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  padding:10px 20px; border-radius:var(--radius);
  font-family:var(--font-body); font-size:var(--text-sm); font-weight:500;
  letter-spacing:var(--letter-space-ui);
  cursor:pointer; border:1px solid var(--border);
  background:var(--surface-2); color:var(--text-2);
  transition: all var(--duration) var(--ease);
  -webkit-tap-highlight-color:transparent;
}
.btn:hover { background:var(--surface-hover); border-color:var(--border-2); color:var(--text); }
.btn:active { transform:scale(0.97); }
.btn--gold { background:var(--gold-bg); border-color:var(--gold-border); color:var(--gold); }
.btn--gold:hover { background:var(--gold); color:var(--bg); border-color:var(--gold); }
.btn--sm { padding:7px 14px; font-size:var(--text-xs); }
.btn--full { width:100%; }
.btn:disabled { opacity:0.4; cursor:not-allowed; pointer-events:none; }

/* ── INPUTS ──────────────────────────────────────────────────────────────── */
.input {
  width:100%; padding:12px 16px;
  background:var(--surface-2); border:1px solid var(--border);
  border-radius:var(--radius); color:var(--text);
  font-family:var(--font-body); font-size:var(--text-base);
  line-height:var(--line-height); letter-spacing:var(--letter-space);
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.input::placeholder { color:var(--text-muted); }
.input:focus { outline:none; border-color:var(--border-focus); box-shadow:0 0 0 3px var(--gold-glow); }
.input:disabled { opacity:0.5; cursor:not-allowed; }

.input-bar {
  display:flex; align-items:center; gap:8px;
  padding:8px; background:var(--surface);
  border:1px solid var(--border); border-radius:var(--radius-lg);
}
.input-bar .input { border:none; background:transparent; padding:8px 12px; flex:1; }
.input-bar .input:focus { box-shadow:none; }
.input-bar .btn { flex-shrink:0; }

/* ── DATE NAV ────────────────────────────────────────────────────────────── */
.date-nav { display:flex; align-items:center; justify-content:space-between; gap:8px; margin-bottom:16px; }

/* ── TAB BAR ─────────────────────────────────────────────────────────────── */
.tab-bar { display:flex; gap:4px; margin-bottom:16px; padding:4px; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); }
.tab { flex:1; padding:8px 12px; border:none; border-radius:6px; background:transparent; color:var(--text-muted); font-family:var(--font-body); font-size:var(--text-sm); font-weight:500; cursor:pointer; transition: all var(--duration) var(--ease); -webkit-tap-highlight-color:transparent; }
.tab:hover { color:var(--text-3); }
.tab.active { background:var(--gold-bg); color:var(--gold); }

/* ── EMPTY STATES ────────────────────────────────────────────────────────── */
.empty-state { display:flex; flex-direction:column; align-items:center; padding:32px 16px; text-align:center; }
.empty-icon { font-size:32px; color:var(--gold-dark); opacity:0.3; margin-bottom:12px; }
.empty-title { font-family:var(--font-display); font-size:var(--text-lg); font-weight:600; color:var(--text-3); margin-bottom:8px; }
.empty-text { font-size:var(--text-sm); color:var(--text-muted); max-width:280px; font-weight:300; }

/* ── MODULE GRID ─────────────────────────────────────────────────────────── */
.modules-grid { display:grid; grid-template-columns:repeat(3, 1fr); gap:10px; margin-top:8px; margin-bottom:24px; }
.module-card { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:16px 10px; text-align:center; cursor:default; opacity:0.35; transition: opacity var(--duration) var(--ease), border-color var(--duration) var(--ease); }
.module-card.active { opacity:1; cursor:pointer; border-color:var(--gold-border); background:var(--gold-bg); }
.module-card.active:hover { border-color:var(--gold); }
.module-icon { font-size:20px; color:var(--gold-dark); margin-bottom:5px; }
.module-card.active .module-icon { color:var(--gold); }
.module-label { font-family:var(--font-display); font-size:var(--text-xs); font-weight:600; color:var(--text-3); margin-bottom:2px; }
.module-card.active .module-label { color:var(--text); }
.module-status { font-size:10px; font-weight:300; color:var(--text-muted); letter-spacing:var(--letter-space-ui); }
.module-card.active .module-status { color:var(--gold); }

/* ── SECTION HEADERS ─────────────────────────────────────────────────────── */
.section-header { display:flex; align-items:center; gap:8px; margin:24px 0 8px; padding-bottom:8px; border-bottom:1px solid var(--border); }
.section-title { font-family:var(--font-display); font-size:var(--text-base); font-weight:600; color:var(--gold); letter-spacing:0.04em; }

/* ── FOOTER ──────────────────────────────────────────────────────────────── */
.app-footer { text-align:center; padding:20px 0 12px; border-top:1px solid var(--border); margin-top:16px; }
.footer-line { font-size:var(--text-xs); color:var(--gold-dark); letter-spacing:0.06em; }

/* ═══════════════════════════════════════════════════════════════════════════
   CHAT — Sprint 4: Nabu's AI conversation interface
   ═══════════════════════════════════════════════════════════════════════════ */

.chat-messages {
  flex:1; overflow-y:auto;
  padding:16px 0 8px;
  display:flex; flex-direction:column; gap:12px;
  /* Scroll to bottom behavior */
  scroll-behavior: smooth;
}

/* Welcome state */
.chat-welcome {
  display:flex; flex-direction:column; align-items:center;
  justify-content:center; flex:1;
  padding:40px 20px; text-align:center;
}
.chat-welcome-diamond { font-size:28px; color:var(--gold); opacity:0.4; margin-bottom:12px; }
.chat-welcome-name {
  font-family:var(--font-display); font-size:var(--text-xl); font-weight:600;
  color:var(--gold); letter-spacing:0.08em; margin-bottom:8px;
}
.chat-welcome-text { font-size:var(--text-sm); color:var(--text-3); font-weight:300; }

/* Message bubbles */
.chat-msg {
  max-width:85%; animation: msg-in 0.25s ease both;
}
.chat-msg--user {
  align-self:flex-end;
  background:var(--gold-bg); border:1px solid var(--gold-border);
  border-radius:var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
  padding:12px 16px;
}
.chat-msg--nabu {
  align-self:flex-start;
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
  padding:12px 16px;
}

.chat-msg-sender {
  font-size:var(--text-xs); font-weight:600; margin-bottom:4px;
  letter-spacing:var(--letter-space-ui);
}
.chat-msg--user .chat-msg-sender { color:var(--gold); }
.chat-msg--nabu .chat-msg-sender { color:var(--gold-dark); }

.chat-msg-text {
  font-size:var(--text-sm); line-height:var(--line-height);
  color:var(--text); word-wrap:break-word;
  white-space:pre-wrap;
}
.chat-msg-text p { margin-bottom:8px; }
.chat-msg-text p:last-child { margin-bottom:0; }

/* Inline code */
.chat-msg-text code {
  background:var(--surface-3); padding:2px 6px;
  border-radius:4px; font-size:var(--text-xs);
  font-family:var(--font-mono, monospace);
}

/* Typing indicator */
.chat-typing {
  align-self:flex-start;
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
  padding:14px 20px;
  animation: msg-in 0.25s ease both;
}
.typing-dots { display:flex; gap:5px; }
.typing-dot {
  width:6px; height:6px; border-radius:50%;
  background:var(--gold-dark);
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay:0.15s; }
.typing-dot:nth-child(3) { animation-delay:0.3s; }

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

@keyframes msg-in {
  from { opacity:0; transform:translateY(8px); }
  to   { opacity:1; transform:translateY(0); }
}

/* Chat input area */
.chat-input-area {
  flex-shrink:0;
  padding:8px 0 12px;
}

/* Model toggle */
.chat-model-toggle {
  display:flex; gap:4px; margin-bottom:8px;
}
.model-btn {
  flex:1; padding:6px 10px; border:1px solid var(--border);
  border-radius:var(--radius); background:var(--surface);
  color:var(--text-muted); font-family:var(--font-body);
  font-size:var(--text-xs); font-weight:500; cursor:pointer;
  transition: all var(--duration) var(--ease);
  -webkit-tap-highlight-color:transparent;
  letter-spacing:var(--letter-space-ui);
}
.model-btn:hover { color:var(--text-3); border-color:var(--border-2); }
.model-btn.active { background:var(--gold-bg); border-color:var(--gold-border); color:var(--gold); }

/* Sending state */
.chat-bar--sending .input { opacity:0.6; }

/* ── ANIMATIONS ──────────────────────────────────────────────────────────── */
@keyframes fade-up {
  from { opacity:0; transform:translateY(10px); }
  to   { opacity:1; transform:translateY(0); }
}

#view-home.active .hero         { animation: fade-up 0.4s ease 0.1s both; }
#view-home.active .card         { animation: fade-up 0.35s ease 0.2s both; }
#view-home.active .section-header { animation: fade-up 0.3s ease 0.35s both; }
#view-home.active .modules-grid { animation: fade-up 0.3s ease 0.4s both; }

#view-home.active #card-weather  { animation-delay: 0.15s; }
#view-home.active #card-schedule { animation-delay: 0.22s; }
#view-home.active #card-tasks    { animation-delay: 0.29s; }
#view-home.active #card-sports   { animation-delay: 0.36s; }
#view-home.active #card-news     { animation-delay: 0.43s; }

/* ── RESPONSIVE ──────────────────────────────────────────────────────────── */
@media (max-width: 380px) {
  .hero-greeting { font-size:var(--text-xl); }
  .modules-grid { grid-template-columns:repeat(2, 1fr); gap:8px; }
  .chat-msg { max-width:90%; }
}

@media (min-width: 768px) {
  .view { padding-bottom:40px; }
  .view--chat { height:calc(100vh - var(--topbar-h)); padding-bottom:16px; }
  .bottomnav { display:none; }
  .modules-grid { grid-template-columns:repeat(3, 1fr); }
}
