@import './variables.css';

/* ==========================================================================
   Base & Reset
   ========================================================================== */
html {
  box-sizing: border-box;
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

*, *::before, *::after {
  box-sizing: inherit;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(76px + var(--safe-bottom));
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  position: relative;
}

h1, h2, h3, h4, .font-display {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.container {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 16px 14px 36px;
  box-sizing: border-box;
  overflow-x: hidden;
}

/* ==========================================================================
   Header & Brand
   ========================================================================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-subtle);
  margin-bottom: 16px;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  background: var(--brand-dark);
  color: #ffffff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
}

.brand-details h1 {
  font-size: 1.05rem;
  line-height: 1.2;
  font-weight: 700;
}

.brand-details p {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--brand-accent-light);
  border: 1px solid var(--brand-accent-border);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--brand-accent);
}

.status-dot {
  width: 6px;
  height: 6px;
  background: var(--brand-accent);
  border-radius: 50%;
}

/* ==========================================================================
   Hero Panel & Core Metrics
   ========================================================================== */
.hero-panel {
  background: linear-gradient(135deg, #090d16 0%, #172033 100%);
  color: var(--text-inverse);
  border-radius: var(--radius-xl);
  padding: 24px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-elevated);
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.hero-panel::after {
  content: '';
  position: absolute;
  top: -30px;
  right: -30px;
  width: 160px;
  height: 160px;
  background: radial-gradient(circle, rgba(15, 118, 110, 0.28) 0%, transparent 70%);
  pointer-events: none;
}

.hero-headline {
  margin-bottom: 18px;
}

.hero-headline h2 {
  color: #ffffff;
  font-size: 1.45rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.hero-headline p {
  color: #94a3b8;
  font-size: 0.88rem;
  max-width: 620px;
}

.metrics-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (min-width: 640px) {
  .metrics-row {
    grid-template-columns: repeat(4, 1fr);
  }
}

.metric-cell {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  font-weight: 600;
  margin-bottom: 2px;
}

.metric-value {
  font-size: 1.35rem;
  font-weight: 700;
  font-family: 'Outfit', sans-serif;
  color: #ffffff;
  line-height: 1.2;
}

.metric-sub {
  font-size: 0.72rem;
  color: #cbd5e1;
  margin-top: 2px;
}

/* ==========================================================================
   Navigation (Desktop & Mobile)
   ========================================================================== */
.tab-bar-desktop {
  display: none;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

@media (min-width: 768px) {
  .tab-bar-desktop {
    display: flex;
  }
}

.nav-tab-btn {
  flex: 1;
  padding: 9px 14px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  text-align: center;
}

.nav-tab-btn:hover {
  color: var(--text-primary);
}

.nav-tab-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-subtle);
  font-weight: 700;
}

/* Sticky Mobile Navigation Bar */
.mobile-tab-bar {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  padding: 8px 12px calc(8px + var(--safe-bottom));
  z-index: 900;
  justify-content: space-around;
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.05);
}

@media (min-width: 768px) {
  .mobile-tab-bar {
    display: none;
  }
}

.mobile-tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  border: none;
  background: transparent;
  cursor: pointer;
  flex: 1;
  min-width: 0;
  transition: all 0.15s;
}

.mobile-tab-item svg {
  width: 20px;
  height: 20px;
  stroke-width: 2;
}

.mobile-tab-item.active {
  color: var(--brand-accent);
  background: var(--brand-accent-light);
  font-weight: 700;
}

/* ==========================================================================
   Tab Panes & Layouts
   ========================================================================== */
.tab-section {
  display: none;
}

.tab-section.active {
  display: block;
  animation: tabFadeIn 0.2s ease-out;
}

@keyframes tabFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Surface Card */
.surface-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--bg-subtle);
  flex-wrap: wrap;
  gap: 8px;
}

.section-title h3 {
  font-size: 1.18rem;
  font-weight: 700;
}

.badge-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}

.badge-teal { background: var(--brand-accent-light); color: var(--brand-accent); border: 1px solid var(--brand-accent-border); }
.badge-amber { background: var(--warm-bg); color: var(--warm-accent); border: 1px solid var(--warm-border); }
.badge-neutral { background: var(--bg-subtle); color: var(--text-secondary); border: 1px solid var(--border-subtle); }

/* ==========================================================================
   Form Controls & Filters (Mobile WebKit Hardened)
   ========================================================================== */
.filter-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  background: var(--bg-subtle);
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  margin-bottom: 18px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

@media (min-width: 640px) {
  .filter-panel {
    grid-template-columns: 1fr 1fr;
  }
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.filter-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.select-input {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 11px 36px 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background-color: var(--bg-surface);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: calc(100% - 12px) center;
  background-size: 14px;
}

.select-input:focus {
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.15);
}

/* ==========================================================================
   Kitchen Scale & Proportions Grid
   ========================================================================== */
.scale-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

@media (min-width: 640px) {
  .scale-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.scale-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
}

.scale-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.scale-category {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.scale-ratio {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--brand-accent);
  background: #ffffff;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
}

.scale-grams {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: 'Outfit', sans-serif;
  line-height: 1.15;
  margin-bottom: 4px;
}

.scale-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.scale-note {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.35;
}

/* ==========================================================================
   Meal Split Dishes Layout
   ========================================================================== */
.meal-split-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 14px;
}

@media (min-width: 720px) {
  .meal-split-layout {
    grid-template-columns: repeat(3, 1fr);
  }
}

.dish-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-subtle);
  display: flex;
  flex-direction: column;
}

.dish-card.active-dish {
  border-color: var(--brand-accent);
  background: linear-gradient(180deg, #ffffff 0%, #fbfdfd 100%);
}

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

.dish-name {
  font-size: 0.95rem;
  font-weight: 700;
}

.dish-total-badge {
  background: var(--brand-dark);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
}

.dish-items {
  list-style: none;
  margin-bottom: 12px;
  flex: 1;
}

.dish-items li {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 0.84rem;
  border-bottom: 1px dashed var(--bg-subtle);
}

.dish-items li:last-child {
  border-bottom: none;
}

.item-label {
  color: var(--text-secondary);
}

.item-val {
  font-weight: 600;
  color: var(--text-primary);
}

.dish-footer-note {
  font-size: 0.76rem;
  color: var(--text-muted);
  background: var(--bg-subtle);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  line-height: 1.35;
}

/* Calcium Box */
.calcium-box {
  background: var(--warm-bg);
  border: 1px solid var(--warm-border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-top: 16px;
}

.calcium-box h4 {
  color: var(--warm-accent);
  font-size: 0.95rem;
  margin-bottom: 4px;
  font-weight: 700;
}

.calcium-box p {
  font-size: 0.84rem;
  color: #78350f;
  line-height: 1.45;
}

/* ==========================================================================
   Variations & Ingredient Matrix
   ========================================================================== */
.matrix-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 20px;
}

@media (min-width: 720px) {
  .matrix-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.group-panel {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
}

.group-panel h4 {
  font-size: 0.9rem;
  margin-bottom: 10px;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.group-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.group-item-row {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.group-item-row strong {
  display: block;
  font-size: 0.86rem;
  color: var(--text-primary);
}

.group-item-row span {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.3;
  display: block;
  margin-top: 2px;
}

.notice-aversion {
  background: var(--alert-bg);
  border: 1px solid var(--alert-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 18px;
  font-size: 0.85rem;
  color: var(--alert-accent);
  line-height: 1.45;
}

.notice-aversion strong {
  font-weight: 700;
}

/* Menu Composer */
.composer-panel {
  background: linear-gradient(180deg, #fbfcfd 0%, #f1f5f9 100%);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.composer-header {
  margin-bottom: 14px;
}

.composer-header h4 {
  font-size: 1.05rem;
  font-weight: 700;
}

.composer-header p {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.composer-selects {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 14px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

@media (min-width: 640px) {
  .composer-selects {
    grid-template-columns: repeat(3, 1fr);
  }
}

.composer-result {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-subtle);
}

/* ==========================================================================
   Article & Science Content Blocks
   ========================================================================== */
.article-stream {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.article-block {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
}

.article-block h4 {
  font-size: 1.05rem;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.article-block p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
  line-height: 1.55;
}

.article-block ul {
  padding-left: 18px;
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.55;
}

.callout-box {
  background: var(--brand-accent-light);
  border-left: 3px solid var(--brand-accent);
  padding: 12px 14px;
  border-radius: 4px;
  font-size: 0.84rem;
  color: #134e4a;
  margin-top: 10px;
}

/* ==========================================================================
   Clinical Alerts & Emergency Signs
   ========================================================================== */
.alert-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 14px;
}

@media (min-width: 600px) {
  .alert-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.alert-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--alert-accent);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.alert-item strong {
  display: block;
  color: var(--alert-accent);
  font-size: 0.88rem;
  margin-bottom: 3px;
}

.alert-item p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
}
