:root {
  --bg: #0b0d10;
  --surface: #151921;
  --surface-2: #1c222d;
  --border: #262e3d;
  --text: #f3f6fc;
  --muted: #94a3b8;
  --primary: #22c55e;
  --primary-dark: #16a34a;
  --protein: #38bdf8;
  --amber: #f59e0b;
  --danger: #ef4444;
  --radius: 16px;
  --nav-height: 68px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100%;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.muted {
  color: var(--muted);
  margin: 0;
}

.muted-sm {
  color: var(--muted);
  font-size: 0.85rem;
}

/* Formlar ve Girdiler */
input,
textarea,
button {
  font-family: inherit;
  font-size: 1rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 44px;
  outline: none;
  transition: border-color 0.15s ease;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
}

textarea {
  resize: vertical;
  min-height: 82px;
}

.input-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 5px;
}

/* Butonlar */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-full {
  width: 100%;
}

.btn-sm {
  min-height: 38px;
  padding: 6px 12px;
  font-size: 0.88rem;
}

.btn-primary {
  background: var(--primary);
  color: #04130a;
}

.btn-success {
  background: #10b981;
  color: #03150e;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.45);
}

.btn-text {
  background: transparent;
  border: none;
  color: var(--muted);
  min-height: 44px;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 600;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
}

.btn-icon-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.btn-icon-sm.active-star {
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.45);
}

.btn-icon-sm.danger:hover,
.btn-icon-sm.danger:active {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.45);
}

/* Giriş Ekranı */
.login-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px 22px;
  text-align: center;
}

.login-logo {
  width: 68px;
  height: 68px;
  margin-bottom: 12px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
}

.login-card form {
  margin-top: 20px;
  text-align: left;
}

/* Ana Kabuk */
.app-shell {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 20px);
}

.main-content {
  padding: 14px 14px 20px;
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.tab-panel.active {
  display: flex;
}

/* Yardımcı Yerleşimler */
.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.row-gap {
  display: flex;
  gap: 10px;
}

.row-gap > .btn {
  flex: 1;
}

.row-end {
  display: flex;
  justify-content: flex-end;
}

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

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

@media (max-width: 440px) {
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card-header-row,
.section-header-row,
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
}

.label-sm {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Tarih Çubuğu */
.date-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.date-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.date-label {
  font-weight: 700;
  font-size: 1.05rem;
}

.pill-btn {
  background: rgba(34, 197, 94, 0.16);
  color: var(--primary);
  border: 1px solid rgba(34, 197, 94, 0.45);
  border-radius: 999px;
  padding: 4px 12px;
  min-height: 32px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

/* Özet Kartı */
.summary-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.summary-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
}

.hero-number {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--primary);
}

.hero-number.over {
  color: var(--danger);
}

.deficit-box {
  text-align: right;
}

.deficit-value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.deficit-value.positive-deficit {
  color: var(--primary);
}

.deficit-value.surplus {
  color: var(--amber);
}

.progress-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  color: var(--muted);
}

.progress-header strong {
  color: var(--text);
}

.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-fill.over {
  background: var(--danger);
}

.progress-fill.protein-fill {
  background: var(--protein);
}

.macro-pills {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.macro-pill {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.86rem;
}

.macro-pill-label {
  color: var(--muted);
}

/* Önizleme Kartı */
.preview-card {
  border-color: rgba(34, 197, 94, 0.5);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.reasoning-box {
  background: var(--bg);
  border-left: 3px solid var(--primary);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem;
  color: #cbd5e1;
}

.preview-items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.preview-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview-item-head {
  display: flex;
  gap: 8px;
  align-items: center;
}

.preview-item-note {
  font-size: 0.8rem;
  color: var(--muted);
}

.preview-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
  font-size: 0.95rem;
}

.checkbox-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

/* Öğün Listesi */
.meals-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.meals-list,
.favorites-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.meal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meal-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.meal-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meal-name {
  font-weight: 700;
  font-size: 1rem;
}

.meal-meta {
  font-size: 0.84rem;
  color: var(--muted);
}

.meal-kcal {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--primary);
  white-space: nowrap;
}

.meal-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.meal-macros {
  font-size: 0.84rem;
  color: #cbd5e1;
}

.meal-actions {
  display: flex;
  gap: 6px;
}

.empty-state {
  text-align: center;
  padding: 28px 16px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.92rem;
}

/* Danışman Sekmesi */
.live-badge {
  background: rgba(56, 189, 248, 0.14);
  color: var(--protein);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 700;
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 40px;
  font-size: 0.85rem;
  cursor: pointer;
  text-align: left;
}

.chip:active {
  border-color: var(--primary);
}

.coach-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 220px;
}

.coach-empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  color: var(--muted);
  font-size: 0.92rem;
}

.msg-bubble {
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 0.94rem;
  max-width: 100%;
  overflow-x: auto;
}

.msg-user {
  align-self: flex-end;
  background: rgba(34, 197, 94, 0.16);
  border: 1px solid rgba(34, 197, 94, 0.35);
  max-width: 88%;
}

.msg-assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  width: 100%;
}

.msg-assistant ul,
.msg-assistant ol {
  margin: 6px 0;
  padding-left: 20px;
}

.msg-assistant p {
  margin: 6px 0;
}

.msg-assistant p:first-child {
  margin-top: 0;
}

.msg-assistant p:last-child {
  margin-bottom: 0;
}

.msg-assistant table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 0.85rem;
}

.msg-assistant th,
.msg-assistant td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.msg-assistant th {
  background: var(--surface-2);
}

.msg-assistant code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.88em;
}

.coach-input-bar {
  display: flex;
  gap: 8px;
  position: sticky;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 8px);
  background: var(--bg);
  padding-top: 6px;
}

.coach-input-bar input {
  flex: 1;
}

/* Favoriler */
.fav-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.fav-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.fav-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Özet & İstatistik */
.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
}

.seg-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 9px;
  padding: 6px 12px;
  min-height: 36px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--surface-2);
  color: var(--text);
}

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

.kpi-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-val {
  font-size: 1.25rem;
  font-weight: 800;
}

.chart-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-chart {
  width: 100%;
  overflow-x: auto;
}

.stats-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--muted);
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 4px;
}

.dot-ok {
  background: var(--primary);
}

.dot-over {
  background: var(--danger);
}

.line-ref {
  display: inline-block;
  width: 14px;
  height: 2px;
  background: var(--amber);
  vertical-align: middle;
  margin-right: 4px;
}

.weekly-list,
.weight-history {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.week-row,
.weight-row {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
}

.weight-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.weight-form input {
  flex: 1;
}

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

/* Alt Gezinme */
.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 640px;
  min-height: var(--nav-height);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: rgba(11, 13, 16, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  z-index: 50;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 48px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}

.nav-btn.active {
  color: var(--primary);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  z-index: 1;
}

@media (min-width: 600px) {
  .modal {
    align-items: center;
    padding: 16px;
  }
  .modal-card {
    border-radius: 20px;
  }
}

/* Uyarılar & Toast */
.alert-error {
  background: rgba(239, 68, 68, 0.14);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem;
}

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.6);
  color: #fca5a5;
}
