/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #1a1f2e;
  --surface:   #252b3d;
  --surface2:  #2f3650;
  --accent:    #c9a861;
  --accent-dk: #a8863d;
  --text:      #f0ece4;
  --text-muted:#8f8c86;
  --success:   #4ade80;
  --error:     #f87171;
  --border:    #3a4258;
  --radius:    12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  /* safe-area insets for notched phones */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Header ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

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

.header-crest {
  font-size: 1.5rem;
  line-height: 1;
}

.header-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: uppercase;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 7px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.4s;
}
.status-dot.online  { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.offline { background: var(--error);   box-shadow: 0 0 6px var(--error);   }

.status-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── Main ── */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px 0;
}

/* ── Section headings ── */
.section-heading {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.section-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

/* ── Tile grid ── */
.tiles-section { }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 100px;
  padding: 12px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.tile:active,
.tile.pressed {
  background: var(--surface2);
  border-color: var(--accent);
  transform: scale(0.96);
}

.tile:hover:not(:active) {
  border-color: var(--accent-dk);
}

.tile.loading {
  opacity: 0.6;
  cursor: wait;
}

.tile-icon {
  font-size: 1.9rem;
  line-height: 1;
  display: block;
}

.tile-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
}

/* ── Chat ── */
.chat-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding-bottom: 20px;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 220px;
  max-height: 45vh;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  scroll-behavior: smooth;
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 88%;
}

.chat-message.carson { align-self: flex-start; }
.chat-message.user   { align-self: flex-end;   }

.chat-sender {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 4px;
}

.chat-message.user .chat-sender { text-align: right; }

.chat-bubble {
  display: block;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  line-height: 1.5;
  word-break: break-word;
}

.chat-message.carson .chat-bubble {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-top-left-radius: 2px;
  color: var(--text);
}

.chat-message.user .chat-bubble {
  background: var(--accent);
  color: #1a1a1a;
  border-top-right-radius: 2px;
}

.chat-message.error .chat-bubble {
  background: transparent;
  border: 1px solid var(--error);
  color: var(--error);
}

/* Typing indicator */
.chat-message.typing .chat-bubble {
  color: var(--text-muted);
  font-style: italic;
}

/* ── Chat form ── */
.chat-form {
  display: flex;
  gap: 8px;
  position: sticky;
  bottom: 0;
  padding-bottom: env(safe-area-inset-bottom, 8px);
  background: var(--bg);
  padding-top: 4px;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.chat-input::placeholder { color: var(--text-muted); }
.chat-input:focus { border-color: var(--accent); }

.chat-send {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #1a1a1a;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.chat-send:active { background: var(--accent-dk); transform: scale(0.93); }
.chat-send:disabled { opacity: 0.4; cursor: default; }

/* ── Toast notifications ── */
.toast-container {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  z-index: 999;
  pointer-events: none;
  width: min(90vw, 400px);
}

.toast {
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 0.88rem;
  font-weight: 500;
  text-align: center;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s, transform 0.2s;
  max-width: 100%;
  word-break: break-word;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--success); color: #1a1a1a; }
.toast.error   { background: var(--error);   color: #1a1a1a; }
.toast.info    { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }

/* ── Scrollbar ── */
.chat-log::-webkit-scrollbar { width: 4px; }
.chat-log::-webkit-scrollbar-track { background: transparent; }
.chat-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Tablet / desktop bump ── */
@media (min-width: 600px) {
  .tile-grid { gap: 16px; }
  .tile { min-height: 110px; }
  .tile-icon { font-size: 2.2rem; }
  .tile-label { font-size: 0.85rem; }
  .chat-log { max-height: 50vh; }
}
