/* ==========================================================================
   Tri's Android Design System — CRED-inspired premium dark theme
   Translated from the Jetpack Compose design system (Color.kt / Theme.kt /
   component patterns) to CSS custom properties + component classes.
   Dark-only. No light theme variant. See ui/theme skill for the source spec.
   ========================================================================== */

:root {
  /* Background & Surface */
  --cred-bg: #0a0a0f;
  --cred-surface: #141420;
  --cred-surface-variant: #1e1e2c;

  /* Primary: Champagne Gold */
  --cred-gold: #c8a45a;
  --on-cred-gold: #1f1100;
  --cred-gold-container: #3b2800;
  --on-cred-gold-container: #ffddb3;

  /* Secondary: Soft Violet */
  --cred-purple: #9c85d4;
  --on-cred-purple: #1e0060;
  --cred-purple-container: #2d2060;
  --on-cred-purple-container: #e2d9ff;

  /* Tertiary: Teal Mint */
  --cred-teal: #5cb8b2;
  --on-cred-teal: #00302e;
  --cred-teal-container: #1a3c3a;
  --on-cred-teal-container: #a7f3ed;

  /* Text */
  --cred-on-bg: #ececec;
  --cred-on-surface: #ececec;
  --cred-on-surface-variant: #9797a8;
  --cred-outline: #2c2c3c;

  /* Error */
  --cred-error: #cf6679;
  --on-cred-error: #37000f;
  --cred-error-container: #3b0a14;
  --on-cred-error-container: #ffd9de;

  /* Spacing (8dp base unit) */
  --space-xs: 4px;
  --space-s: 8px;
  --space-m: 12px;
  --space-l: 16px;
  --space-xl: 24px;
  --space-xxl: 32px;

  /* Corner radius */
  --radius-subtle: 6px;
  --radius-standard: 10px;
  --radius-large: 16px;

  --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--cred-bg);
  color: var(--cred-on-bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
  background: linear-gradient(
    180deg,
    var(--cred-surface) 0%,
    var(--cred-bg) 40%,
    var(--cred-bg) 100%
  );
}

header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-l);
  background: var(--cred-bg);
  color: var(--cred-on-bg);
  border-bottom: 1px solid var(--cred-outline);
  position: sticky;
  top: 0;
  z-index: 5;
}

header.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin: 0;
}

.icon-button {
  background: none;
  border: none;
  color: var(--cred-on-surface-variant);
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
  transition: color 150ms var(--ease-standard);
}

.icon-button:hover,
.icon-button:active {
  color: var(--cred-gold);
}

main {
  flex: 1;
  padding: var(--space-l);
}

.tutor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-m);
}

.tutor-card {
  background: var(--cred-surface);
  border-radius: var(--radius-large);
  padding: var(--space-l) var(--space-m);
  text-align: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  border: 1px solid var(--cred-outline);
  cursor: pointer;
  transition: border-color 150ms var(--ease-standard), box-shadow 150ms var(--ease-standard);
}

.tutor-card.selected {
  border-color: var(--cred-gold);
  box-shadow: 0 0 0 2px rgba(200, 164, 90, 0.25), 0 2px 10px rgba(0, 0, 0, 0.35);
}

.tutor-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--cred-surface-variant);
  border: 2px solid var(--cred-outline);
  margin-bottom: var(--space-s);
}

.tutor-card.selected .tutor-avatar {
  border-color: var(--cred-gold);
}

.tutor-card h3 {
  margin: var(--space-xs) 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--cred-on-surface);
}

.tutor-card .subtitle {
  font-size: 12px;
  color: var(--cred-on-surface-variant);
  margin-bottom: var(--space-m);
  min-height: 32px;
}

.tutor-card-actions {
  display: flex;
  gap: var(--space-s);
  justify-content: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-standard);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: filter 150ms var(--ease-standard), opacity 150ms var(--ease-standard);
}

.btn:active {
  filter: brightness(0.92);
}

.btn-primary {
  background: var(--cred-gold);
  color: var(--on-cred-gold);
  font-weight: 700;
}

.btn-secondary {
  background: transparent;
  color: var(--cred-on-surface);
  border: 1px solid var(--cred-outline);
}

.btn-call {
  background: var(--cred-teal);
  color: var(--on-cred-teal);
}

.btn-call.disabled {
  background: var(--cred-surface-variant);
  color: var(--cred-on-surface-variant);
  pointer-events: none;
}

.btn-block {
  width: 100%;
  padding: 14px;
  font-size: 15px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cred-on-surface-variant);
  margin: var(--space-xl) 0 var(--space-s);
}

/* Brand tag - CRED "premium touch" tagline treatment: SemiBold + wide
   letter-spacing (3sp in the Compose spec, ~3px here). */
.brand-tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--cred-gold);
  margin-bottom: var(--space-s);
}

.brand-credit {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--cred-on-surface-variant);
  margin: var(--space-xxl) 0 var(--space-l);
}

/* Alert / error card (CRED "Error Card" pattern) */
.alert-card {
  display: flex;
  align-items: center;
  gap: var(--space-s);
  background: var(--cred-error-container);
  color: var(--on-cred-error-container);
  border-radius: var(--radius-standard);
  padding: var(--space-m);
  font-size: 13px;
  margin: var(--space-s) 0;
}

.alert-card .alert-icon {
  color: var(--cred-error);
  flex-shrink: 0;
}

/* Chat */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--space-m);
}

.chat-header img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--cred-surface-variant);
  border: 1px solid var(--cred-outline);
}

.chat-header strong {
  color: var(--cred-on-surface);
  font-weight: 600;
}

/* Mid-session tutor switcher */
.tutor-switcher {
  display: flex;
  gap: var(--space-s);
  overflow-x: auto;
  padding-bottom: var(--space-s);
  margin-bottom: var(--space-m);
}

.switcher-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  flex-shrink: 0;
  width: 64px;
}

.switcher-item img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--cred-surface-variant);
  border: 2px solid var(--cred-outline);
}

.switcher-item.selected img {
  border-color: var(--cred-gold);
}

.switcher-item span {
  font-size: 11px;
  color: var(--cred-on-surface-variant);
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switcher-item.selected span {
  color: var(--cred-gold);
  font-weight: 600;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 40vh;
  margin-bottom: var(--space-m);
}

.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius-large);
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.bubble.user {
  align-self: flex-end;
  background: var(--cred-gold);
  color: var(--on-cred-gold);
  border-bottom-right-radius: var(--radius-subtle);
}

.bubble.assistant {
  align-self: flex-start;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--cred-surface);
  color: var(--cred-on-surface);
  border: 1px solid var(--cred-outline);
  border-bottom-left-radius: var(--radius-subtle);
}

.bubble-text {
  flex: 1;
}

.speak-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 2px;
  font-size: 15px;
  line-height: 1;
  color: var(--cred-on-surface-variant);
  cursor: pointer;
  transition: color 150ms var(--ease-standard);
}

.speak-btn:hover,
.speak-btn:active {
  color: var(--cred-gold);
}

.bubble.pending {
  opacity: 0.6;
  font-style: italic;
}

.bubble-image {
  display: block;
  max-width: 220px;
  max-height: 220px;
  width: 100%;
  height: auto;
  border-radius: var(--radius-standard);
  object-fit: cover;
  margin-bottom: 6px;
}

.image-preview {
  display: flex;
  align-items: center;
  gap: var(--space-s);
}

.image-preview:empty {
  display: none;
}

.image-preview img {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-standard);
  object-fit: cover;
  border: 1px solid var(--cred-outline);
}

.remove-image-btn {
  background: none;
  border: none;
  color: var(--cred-on-surface-variant);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  transition: color 150ms var(--ease-standard);
}

.remove-image-btn:hover,
.remove-image-btn:active {
  color: var(--cred-error);
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-s);
  position: sticky;
  bottom: 0;
  background: var(--cred-bg);
  padding-top: var(--space-s);
}

.attach-btn,
.mic-btn {
  flex-shrink: 0;
  font-size: 20px;
  border: 1px solid var(--cred-outline);
  border-radius: 50%;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mic-btn.listening {
  color: var(--on-cred-error);
  background: var(--cred-error);
  border-color: var(--cred-error);
  animation: mic-pulse 1s ease-in-out infinite;
}

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

@keyframes mic-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(207, 102, 121, 0.5);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(207, 102, 121, 0);
  }
}

.chat-input-row textarea {
  flex: 1;
  resize: none;
  border-radius: var(--radius-standard);
  border: 1px solid var(--cred-outline);
  background: var(--cred-surface-variant);
  color: var(--cred-on-surface);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  min-height: 42px;
  max-height: 120px;
}

.chat-input-row textarea:focus {
  outline: none;
  border-color: var(--cred-gold);
}

.chat-input-row textarea::placeholder {
  color: var(--cred-on-surface-variant);
}

/* Forms */
.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: var(--space-xs);
  color: var(--cred-on-surface-variant);
}

.field input[type="text"],
.field input[type="tel"],
.field input[type="password"],
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--cred-outline);
  border-radius: var(--radius-standard);
  font-size: 14px;
  font-family: inherit;
  background: var(--cred-surface-variant);
  color: var(--cred-on-surface);
  transition: border-color 150ms var(--ease-standard);
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--cred-gold);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--cred-on-surface-variant);
}

.field select {
  color-scheme: dark;
}

.field textarea {
  min-height: 80px;
  resize: vertical;
}

.photo-picker {
  display: flex;
  align-items: center;
  gap: var(--space-m);
}

.photo-picker img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--cred-surface-variant);
  border: 1px solid var(--cred-outline);
}

.helper-text {
  font-size: 12px;
  color: var(--cred-on-surface-variant);
  margin-top: var(--space-xs);
}

.helper-text code {
  background: var(--cred-surface-variant);
  border-radius: var(--radius-subtle);
  padding: 1px 5px;
  font-size: 11px;
  color: var(--cred-on-surface);
}

.status-text {
  font-size: 13px;
  margin-top: var(--space-s);
}

.status-text.ok {
  color: var(--cred-teal);
}

.status-text.error {
  color: var(--cred-error);
}

/* Bottom nav */
nav.bottom-nav {
  display: flex;
  border-top: 1px solid var(--cred-outline);
  background: var(--cred-surface);
  position: sticky;
  bottom: 0;
}

nav.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  font-size: 12px;
  color: var(--cred-on-surface-variant);
  cursor: pointer;
  transition: color 150ms var(--ease-standard);
}

nav.bottom-nav button.active {
  color: var(--cred-gold);
  font-weight: 700;
}

/* Toast */
#toast-root {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 90px;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 20;
}

.toast {
  background: var(--cred-gold);
  color: var(--on-cred-gold);
  padding: 12px 18px;
  border-radius: var(--radius-standard);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  max-width: 90%;
  text-align: center;
  animation: toast-in 0.2s var(--ease-standard);
}

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

.empty-state {
  text-align: center;
  color: var(--cred-on-surface-variant);
  padding: 40px 16px;
  font-size: 14px;
}

.tutor-edit-divider {
  border-top: 1px solid var(--cred-outline);
  margin: var(--space-xxl) 0 0;
}

/* ==========================================================================
   Staggered screen-entrance animation (adapted from the Compose G0-G3
   staggered-entrance pattern: 4 tiers at 0/80/155/225ms, fade + slide).
   Applied to the direct children of #main-content on every navigation.
   ========================================================================== */
@keyframes screen-enter {
  from {
    opacity: 0;
    transform: translateX(18px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

#main-content.screen-enter > * {
  animation: screen-enter 350ms var(--ease-standard) both;
}

#main-content.screen-enter > *:nth-child(1) {
  animation-delay: 0ms;
}
#main-content.screen-enter > *:nth-child(2) {
  animation-delay: 80ms;
}
#main-content.screen-enter > *:nth-child(3) {
  animation-delay: 155ms;
}
#main-content.screen-enter > *:nth-child(n + 4) {
  animation-delay: 225ms;
}

@media (prefers-reduced-motion: reduce) {
  /* Kill every animation AND transition (border/color/filter fades on cards,
     buttons, nav, inputs, etc.) - not just the keyframe animations above. */
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
}
