/* SimStudio Master Design System & Dark Glassmorphism Stylesheet */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&family=Outfit:wght@600;700;800&display=swap');

:root {
  --bg: #f8fafc;
  --card: rgba(255, 255, 255, 0.85);
  --card-solid: #ffffff;
  --muted: rgba(0, 0, 0, 0.04);
  --border: rgba(0, 0, 0, 0.08);
  --border-bright: rgba(0, 0, 0, 0.16);
  --accent: #4f46e5;
  --accent-hover: #3730a3;
  --accent-glow: rgba(79, 70, 229, 0.15);
  --amber: #d97706;
  --red: #dc2626;
  --green: #059669;
  --white: #0f172a;
  --text-dim: #334155;
  --text-muted: #64748b;
  
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-display: 'Outfit', 'Inter', sans-serif;

  --shadow-accent: 0 4px 20px rgba(79, 70, 229, 0.15);
  --shadow-red: 0 4px 20px rgba(220, 38, 38, 0.15);
  --shadow-card: 0 8px 32px 0 rgba(0, 0, 0, 0.06);
  --border-default: 1px solid var(--border);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg);
  color: var(--white);
  font-family: var(--font-sans);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background-image: 
    radial-gradient(circle at 10% 10%, rgba(79, 70, 229, 0.05) 0%, transparent 45%),
    radial-gradient(circle at 90% 90%, rgba(5, 150, 105, 0.03) 0%, transparent 45%);
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); /* Space for mobile nav bar */
}

@media (min-width: 769px) {
  body {
    padding-bottom: 0;
  }
}

/* Live studio: free bottom space and hide tab bar so Speak/Send stay reachable */
body.studio-live-mode {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

body.studio-live-mode .mobile-nav {
  display: none !important;
}

.mono { font-family: var(--font-mono); }
.text-accent { color: var(--accent); }
.text-amber { color: var(--amber); }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.text-dim { color: var(--text-dim); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }

/* Desktop Navigation Bar */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

@media (min-width: 769px) {
  .navbar {
    padding: 16px 32px;
  }
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.wordmark {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--white);
}

@media (min-width: 769px) {
  .wordmark {
    font-size: 22px;
  }
}

.badge-role {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.badge-role.admin {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-role.user {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent);
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.nav-links {
  display: none;
  align-items: center;
  gap: 12px;
}

@media (min-width: 769px) {
  .nav-links {
    display: flex;
    gap: 24px;
  }
}

.nav-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: color 0.15s ease;
}

.nav-link:hover, .nav-link.active {
  color: var(--white);
}

/* Mobile Bottom Navigation Bar */
.mobile-nav {
  display: flex;
  justify-content: space-around;
  align-items: center;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  min-height: 64px;
  height: auto;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  z-index: 200;
}

.mobile-nav-item form,
.mobile-nav-item button {
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 0;
}

@media (min-width: 769px) {
  .mobile-nav {
    display: none;
  }
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
}

.mobile-nav-item.active {
  color: var(--accent);
}

.mobile-nav-item svg {
  width: 20px;
  height: 20px;
}

/* Layout Container */
.main-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px;
}

@media (min-width: 769px) {
  .main-container {
    padding: 32px 24px;
  }
}

.page-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

@media (min-width: 769px) {
  .page-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
  }
}

.page-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
}

@media (min-width: 769px) {
  .page-title {
    font-size: 28px;
  }
}

.page-subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 4px;
}

/* Glass Cards */
.card {
  background: var(--card);
  backdrop-filter: blur(16px);
  border: var(--border-default);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
}

@media (min-width: 769px) {
  .card {
    padding: 24px;
    margin-bottom: 24px;
  }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
}

@media (min-width: 769px) {
  .card-title {
    font-size: 18px;
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.2s ease;
  min-height: 44px; /* Touch friendly */
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary:active, .btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--muted);
  color: var(--white);
  border: 1px solid var(--border);
}

.btn-secondary:active, .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-bright);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:active, .btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 12px;
  min-height: 36px;
}

/* Form Controls */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-control {
  width: 100%;
  padding: 12px 14px;
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--white);
  font-family: var(--font-sans);
  font-size: 14px;
  transition: border-color 0.2s ease;
  min-height: 46px; /* Touch friendly */
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea.form-control {
  min-height: 100px;
  resize: vertical;
}

select.form-control {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%239ca3af'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 36px;
}

/* Table Styles */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.table th {
  padding: 12px 14px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 13px;
}

.table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* Grid System - Mobile First Defaults */
.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

/* Keep single column on phones; 2-up only from tablet landscape-ish */
@media (min-width: 768px) {
  .grid {
    gap: 20px;
  }
  .grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
  .grid { gap: 24px; }
  .grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
}

/* Specific Layout Helpers */
.layout-span-2 {
  grid-column: span 1;
}

@media (min-width: 1024px) {
  .layout-span-2 {
    grid-column: span 2;
  }
}

.layout-span-3 {
  grid-column: span 1;
}

@media (min-width: 1024px) {
  .layout-span-3 {
    grid-column: span 3;
  }
}

/* Metric & Score Cards */
.score-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}

.score-value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
  color: var(--accent);
}

@media (min-width: 769px) {
  .score-value {
    font-size: 32px;
  }
}

.score-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

/* Siri-style Buyer Orb */
.siri-orb-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.siri-orb {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #a855f7, #6366f1, #3b82f6);
  box-shadow: 0 0 35px rgba(99, 102, 241, 0.6);
  animation: pulse-orb 3s infinite ease-in-out;
}

.siri-orb.buyer-orb-compact {
  width: 52px;
  height: 52px;
  box-shadow: 0 0 18px rgba(99, 102, 241, 0.5);
}

@media (min-width: 769px) {
  .siri-orb:not(.buyer-orb-compact) {
    width: 120px;
    height: 120px;
    box-shadow: 0 0 40px rgba(99, 102, 241, 0.6);
  }
}

.siri-orb.speaking {
  animation: speak-orb 0.8s infinite alternate ease-in-out;
  box-shadow: 0 0 60px rgba(168, 85, 247, 0.8);
}

.siri-orb.buyer-orb-compact.speaking {
  box-shadow: 0 0 28px rgba(168, 85, 247, 0.75);
}

@keyframes pulse-orb {
  0%, 100% { transform: scale(1); filter: hue-rotate(0deg); }
  50% { transform: scale(1.05); filter: hue-rotate(30deg); }
}

@keyframes speak-orb {
  0% { transform: scale(0.95); }
  100% { transform: scale(1.12); }
}

/* Flatpickr Interactive Date Picker Custom Styling */
.flatpickr-calendar {
  background: var(--card-solid) !important;
  border: 1px solid var(--border-bright) !important;
  border-radius: 12px !important;
  box-shadow: var(--shadow-card) !important;
  backdrop-filter: blur(16px);
}

.flatpickr-calendar, .flatpickr-calendar *, .flatpickr-months, .flatpickr-month, .flatpickr-weekday, .flatpickr-day, .flatpickr-time, .flatpickr-time input, .flatpickr-time .numInputWrapper span {
  color: var(--white) !important;
}

.flatpickr-day.selected, .flatpickr-day.startRange, .flatpickr-day.endRange {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #ffffff !important;
}

.flatpickr-day:hover {
  background: var(--muted) !important;
}

/* ---------- Mobile-safe studio & lists (desktop unchanged ≥900px) ---------- */

.briefing-panel {
  max-width: 900px;
  margin: 0 auto;
  padding-top: 10px;
}

.briefing-cta {
  width: 100%;
  max-width: 360px;
  min-width: 0;
  padding: 16px 24px;
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 8px 30px var(--accent-glow);
}

.briefing-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.studio-header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.page-header-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  .page-header-actions {
    width: 100%;
  }

  .page-header-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
    min-width: 0;
  }
}

.studio-split {
  display: flex;
  gap: 20px;
  width: 100%;
  flex-wrap: nowrap;
  align-items: stretch;
}

.studio-panel {
  flex: 1;
  min-width: 0;
  min-height: 520px;
  margin-bottom: 0;
}

.studio-camera-panel {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #07080c;
  border: 1px solid var(--border-bright);
  border-radius: 16px;
  padding: 0;
}

.studio-dialogue-panel {
  display: flex;
  flex-direction: column;
  background: var(--card-solid);
  border: 1px solid var(--border-bright);
  border-radius: 16px;
  padding: 20px;
  justify-content: space-between;
}

.studio-turn-actions {
  margin-top: 12px;
  gap: 10px;
}

.attempts-mobile-list {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.attempt-mobile-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: var(--muted);
}

.attempt-mobile-card-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.attempt-mobile-card-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.wizard-steps {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}

@media (max-width: 899px) {
  .studio-split {
    flex-direction: column;
    flex-wrap: wrap;
    gap: 14px;
  }

  .studio-panel {
    width: 100%;
    flex: none;
    min-height: 0;
  }

  .studio-camera-panel {
    min-height: min(52vh, 420px);
    height: min(52vh, 420px);
  }

  .studio-dialogue-panel {
    min-height: 0;
    padding: 14px;
  }

  #live_studio_screen .page-title {
    font-size: 18px !important;
  }

  #dialogue_container {
    max-height: 200px !important;
  }

  .studio-turn-actions {
    position: sticky;
    bottom: 0;
    z-index: 30;
    background: var(--card-solid);
    padding-top: 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    margin-left: -4px;
    margin-right: -4px;
    padding-left: 4px;
    padding-right: 4px;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 768px) {
  .attempts-desktop-table {
    display: none;
  }

  .attempts-mobile-list {
    display: flex;
    gap: 14px;
  }
}

@media (min-width: 769px) {
  .attempts-mobile-list {
    display: none !important;
  }
}

/* ---------- Small-screen spacing polish (phones / narrow tablets) ---------- */
@media (max-width: 767px) {
  .main-container {
    padding: 16px 14px;
  }

  .page-header {
    gap: 14px;
    margin-bottom: 20px;
  }

  .page-title {
    font-size: 20px;
    line-height: 1.25;
  }

  .page-subtitle {
    font-size: 13px;
    line-height: 1.45;
  }

  .card {
    padding: 16px;
    margin-bottom: 16px;
    border-radius: 14px;
  }

  .card-header {
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 12px;
  }

  .grid {
    gap: 14px;
    grid-template-columns: 1fr !important;
  }

  .grid.grid-cols-2,
  .grid.grid-cols-3,
  .grid.grid-cols-4 {
    grid-template-columns: 1fr !important;
  }

  .form-group {
    margin-bottom: 18px;
  }

  .form-label {
    margin-bottom: 8px;
  }

  .btn {
    padding: 12px 16px;
  }

  .btn-sm {
    min-height: 40px;
    padding: 10px 14px;
  }

  /* Stack common action / button rows */
  .page-header-actions {
    width: 100%;
    flex-direction: column;
    gap: 10px;
  }

  .page-header-actions .btn {
    width: 100%;
    flex: none;
  }

  .studio-header-actions {
    width: 100%;
  }

  .studio-header-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .studio-turn-actions {
    flex-direction: column;
    gap: 10px !important;
  }

  .studio-turn-actions .btn {
    width: 100%;
    flex: none !important;
  }

  .briefing-meta {
    gap: 8px 10px;
  }

  .briefing-cta {
    max-width: 100%;
    width: 100%;
  }

  .attempt-mobile-card {
    padding: 16px;
  }

  .attempt-mobile-card-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .attempt-mobile-card-meta {
    margin-top: 12px;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
  }

  .attempt-mobile-card .btn {
    margin-top: 14px !important;
  }

  .score-card {
    padding: 16px 12px;
  }

  .table th,
  .table td {
    padding: 12px 10px;
  }

  /* Training cards: give stacked CTAs breathing room */
  .grid .card .btn + .btn,
  .grid .card a.btn + a.btn {
    margin-top: 0;
  }

  .badge-role {
    margin-bottom: 2px;
  }

  /* Inline form rows that use flex (goals / concept rows) */
  .concept-row-item {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .concept-row-item .btn {
    width: 100%;
  }

  /* Type toggle / mode pickers */
  .type-toggle {
    flex-direction: column;
    gap: 10px !important;
  }

  .type-toggle > * {
    width: 100%;
  }

  /* Training index cards: full-width CTAs with clearer separation */
  .grid .card a.btn,
  .grid .card button.btn {
    width: 100%;
    box-sizing: border-box;
  }

  .grid .card a.btn + a.btn,
  .grid .card .btn + .btn,
  .grid .card a.btn + .btn,
  .grid .card .btn + a.btn {
    margin-top: 2px;
  }

  .grid .card [style*="flex-direction: column"] {
    gap: 10px !important;
  }

  .grid .card [style*="padding-top: 10px"] {
    margin-top: 12px !important;
    padding-top: 12px !important;
  }
}

