/* ============================================================
   AI Diyetisyen — Tasarım (mobile-first, tam responsive)
   Breakpoint'ler: sm 576 / md 768 / lg 1024
   ============================================================ */

:root {
  --primary: #16a34a;
  --primary-dark: #15803d;
  --primary-strong: #0f7a3d;
  --primary-light: #dcfce7;
  --primary-softer: #f0fdf4;
  --bg: #f4f7f5;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
  --shadow-lg: 0 12px 40px rgba(16,24,40,.16);
  --sidebar-w: 252px;
  --bottom-nav-h: 62px;
  --topbar-h: 56px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
button { font-family: inherit; }
a { color: var(--primary-dark); }

/* ---------- Butonlar ---------- */
.btn {
  padding: 10px 18px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card); color: var(--text); cursor: pointer;
  font-size: 14px; font-weight: 600; transition: all .15s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; text-decoration: none;
}
.btn:hover { background: var(--bg); border-color: #d1d5db; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(22,163,74,.3); }
.btn-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); color: #fff; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border: none; color: var(--muted); min-height: 0; padding: 6px 10px; }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { color: var(--danger); }
.link-like { background: none; border: none; color: var(--primary-dark); cursor: pointer; padding: 0; font-size: 13px; font-weight: 600; }
.link-like:hover { text-decoration: underline; }

/* ---------- Formlar ---------- */
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 15px; font-family: inherit;
  background: #fff; color: var(--text); transition: border-color .15s, box-shadow .15s;
  min-height: 42px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22,163,74,.15);
}
textarea { resize: vertical; min-height: 42px; }
label { font-size: 13px; font-weight: 600; display: block; margin-bottom: 4px; color: #374151; }
.check-row { display: flex; align-items: flex-start; gap: 8px; font-weight: 500; font-size: 14px; }
.check-row input[type=checkbox] { width: 18px; height: 18px; min-height: 0; margin-top: 2px; accent-color: var(--primary); }

/* ---------- Mesajlar ---------- */
.msg { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 14px; margin-top: 12px; }
.msg.error { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.msg.success { background: var(--primary-light); color: var(--primary-strong); border: 1px solid #bbf7d0; }

/* ---------- Giriş ekranı ---------- */
#view-auth { min-height: 100vh; }
.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(160deg, #f0fdf4 0%, #e8f5ec 40%, #d9ede3 100%);
}
.auth-box {
  background: var(--card); border-radius: 22px; box-shadow: var(--shadow-lg);
  padding: 34px 28px; width: 100%; max-width: 420px; text-align: center;
}
.auth-logo { font-size: 56px; line-height: 1; }
.auth-title { margin: 12px 0 6px; font-size: 26px; font-weight: 800; color: var(--primary-strong); }
.auth-sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 20px; background: var(--bg); border-radius: 12px; padding: 4px; }
.auth-tab {
  flex: 1; padding: 10px; border: none; background: transparent;
  border-radius: 9px; cursor: pointer; font-size: 14px; font-weight: 700; color: var(--muted);
  transition: all .15s;
}
.auth-tab.active { background: var(--primary); color: #fff; box-shadow: 0 1px 3px rgba(22,163,74,.3); }
.auth-form { text-align: left; }
.auth-form label { margin: 12px 0 5px; }
.auth-note { font-size: 12px; color: var(--muted); margin-top: 12px; text-align: center; }

/* ---------- Uygulama iskeleti ---------- */
#view-app { min-height: 100vh; }
.app-main { min-height: 100vh; }

/* Masaüstü kenar çubuğu (varsayılan gizli) */
.sidebar { display: none; }

/* Mobil üst bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 0 14px; height: var(--topbar-h);
  position: sticky; top: 0; z-index: 30;
  box-shadow: 0 1px 4px rgba(16,24,40,.04);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 16px; }
.brand-ico { font-size: 24px; }
.brand-name { color: var(--primary-strong); }
.top-user { display: flex; align-items: center; gap: 8px; }
.user-email { font-size: 12px; color: var(--muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Mobil alt gezinme */
.bottom-nav {
  display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--card); border-top: 1px solid var(--border);
  height: var(--bottom-nav-h); padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav .nav-item {
  flex: 1; border: none; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 600; cursor: pointer; transition: color .15s;
}
.bottom-nav .nav-item .nav-ico { font-size: 22px; line-height: 1; }
.bottom-nav .nav-item.active { color: var(--primary-strong); }

/* İçerik */
.content {
  padding: 14px 14px calc(var(--bottom-nav-h) + 22px);
  max-width: 880px; margin: 0 auto;
}

/* ---------- Genel kartlar ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 12px; font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.hint { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Sohbet ---------- */
#view-chat { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h) - var(--bottom-nav-h) - 22px); }
body[data-view="chat"] .content { padding-bottom: 8px; }
.chat-box {
  flex: 1; overflow-y: auto; padding: 12px 2px 16px;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}
.msg-bubble {
  max-width: 84%; padding: 11px 14px; border-radius: 16px;
  font-size: 14.5px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.55;
}
.msg-user {
  align-self: flex-end; background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; border-bottom-right-radius: 5px;
  box-shadow: 0 1px 3px rgba(22,163,74,.25);
}
.msg-ai {
  align-self: flex-start; background: var(--card); border: 1px solid var(--border);
  border-bottom-left-radius: 5px; box-shadow: var(--shadow);
  color: var(--text);
}
.msg-typing { color: var(--muted); font-style: italic; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .45; } 50% { opacity: 1; } }

/* Markdown içeriği */
.msg-ai h1, .msg-ai h2, .msg-ai h3 { font-size: 15px; margin: 12px 0 5px; color: var(--text); }
.msg-ai h1:first-child, .msg-ai h2:first-child, .msg-ai h3:first-child, .msg-ai p:first-child { margin-top: 0; }
.msg-ai p { margin: 6px 0; }
.msg-ai ul, .msg-ai ol { margin: 6px 0; padding-left: 22px; }
.msg-ai li { margin: 3px 0; }
.msg-ai table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 13px; }
.msg-ai th, .msg-ai td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.msg-ai th { background: var(--bg); font-weight: 700; }
.msg-ai tr:nth-child(even) td { background: var(--bg); }
.msg-ai code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.msg-ai pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; }
.msg-ai strong { font-weight: 700; }
.msg-ai blockquote, .plan-content-body blockquote {
  margin: 10px 0; padding: 10px 14px; border-left: 4px solid var(--primary);
  background: var(--primary-softer); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: #374151; font-size: 13.5px;
}
.msg-ai hr, .plan-content-body hr { border: none; border-top: 2px solid var(--border); margin: 16px 0; }

/* Sohbet giriş alanı */
.chat-input-wrap {
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 8px; box-shadow: var(--shadow-lg);
  position: sticky; bottom: calc(var(--bottom-nav-h) + 10px); z-index: 20;
}
.btn-attach { min-height: 42px; width: 44px; flex-shrink: 0; font-size: 18px; line-height: 1; padding: 0; }
.doc-type {
  width: auto; flex-shrink: 0; min-height: 42px;
  border: 1px solid var(--border); border-radius: 10px; font-size: 13px; padding: 0 8px;
}
#chat-input { flex: 1; border: none; box-shadow: none !important; min-height: 42px; max-height: 150px; padding: 10px 4px; resize: none; }
#chat-input:focus { outline: none; border: none; }
.btn-send { min-height: 42px; flex-shrink: 0; }

.upload-status {
  max-width: 100%; margin: 8px auto 0; padding: 9px 14px; border-radius: 10px;
  font-size: 13px; font-weight: 600; background: var(--card); border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.upload-status.ok { border-color: #bbf7d0; color: var(--primary-strong); background: var(--primary-softer); }
.upload-status.error { border-color: #fecaca; color: #991b1b; background: var(--danger-light); }

/* ---------- Takip ---------- */
.track-grid { display: grid; gap: 14px; }
.targets { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.target-item { background: var(--bg); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; }
.target-item b { display: block; font-size: 17px; color: var(--primary-strong); font-weight: 800; }
.target-item span { color: var(--muted); font-size: 12px; }

.row-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.row-form input, .row-form select { flex: 1; min-width: 120px; }
.date-sm { min-width: 140px !important; flex: 0 0 auto !important; }

.mini-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.mini-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--bg); border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13.5px;
}
.mini-item .del { border: none; background: none; color: var(--danger); cursor: pointer; font-size: 16px; padding: 2px 6px; border-radius: 6px; }
.mini-item .del:hover { background: var(--danger-light); }

.daily-form, .blood-form, .settings-form { display: flex; flex-direction: column; gap: 12px; }
.daily-form label, .blood-form label, .settings-form label { margin: 0; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row select { width: auto; min-height: 40px; }
#weight-chart { width: 100%; background: var(--bg); border-radius: var(--radius-sm); margin-top: 8px; }

/* ---------- Profil ---------- */
.prof-section { margin-bottom: 20px; }
.prof-section h4 { margin: 0 0 12px; font-size: 15px; color: var(--primary-strong); border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.prof-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
#btn-save-profile { margin-top: 8px; }

/* ---------- Onboarding ---------- */
.onboarding {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, .55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.onboarding-box {
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; padding: 26px;
}
.onboarding-header h3 { margin: 0 0 6px; font-size: 20px; color: var(--primary-strong); }
.onboarding-header p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.onboarding-step .prof-section { margin-bottom: 0; }
.onboarding-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 20px; }
.onb-counter { font-size: 13px; color: var(--muted); font-weight: 700; }
.onboarding-skip { margin-top: 14px; text-align: center; }
.onboarding-skip .btn { color: var(--muted); font-size: 13px; }

/* ---------- Diyet Listeleri ---------- */
.plans-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.plans-head h2 { margin: 0; font-size: 20px; }
.plan-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.plan-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 0; }
.plan-item-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.plan-item-info b { font-size: 15px; }
.plan-date { font-size: 12px; color: var(--muted); }
.plan-item-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.btn-sm { min-height: 34px; padding: 4px 12px; font-size: 13px; }
.plan-form { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Plan detayı (tam ekran) ---------- */
#plan-detail { max-width: 760px; margin: 0 auto; }
.btn-back { margin-bottom: 14px; }
.plan-content {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.plan-content-head {
  padding: 20px 22px; border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--primary-light), var(--primary-softer));
}
.plan-content-head h2 { margin: 0 0 4px; font-size: 22px; color: var(--primary-strong); }
.plan-content-body { padding: 22px; font-size: 15px; line-height: 1.65; color: var(--text); }

/* Plan içeriği markdown stili */
.plan-content-body h1, .plan-content-body h2, .plan-content-body h3 {
  font-size: 17px; margin: 22px 0 8px; padding-bottom: 6px;
  border-bottom: 2px solid var(--primary-light); color: var(--primary-strong);
}
.plan-content-body h1:first-child, .plan-content-body h2:first-child, .plan-content-body h3:first-child { margin-top: 0; }
.plan-content-body .meal-head {
  display: inline-block; background: var(--primary-light); color: var(--primary-strong);
  padding: 7px 16px; border-radius: 999px; border: none;
  font-size: 15px; font-weight: 800; margin: 22px 0 10px;
}
.plan-content-body .meal-head:first-child { margin-top: 0; }
.plan-content-body p { margin: 8px 0; }
.plan-content-body ul, .plan-content-body ol { margin: 8px 0; padding-left: 22px; }
.plan-content-body li { margin: 4px 0; }
.plan-content-body li::marker { color: var(--primary); }
.plan-content-body table { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 14px; }
.plan-content-body th, .plan-content-body td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.plan-content-body th { background: var(--primary-softer); font-weight: 700; color: var(--primary-strong); }
.plan-content-body tr:nth-child(even) td { background: var(--bg); }
.plan-content-body code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.plan-content-body pre { background: var(--bg); padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.plan-content-body strong { font-weight: 700; }
.plan-content-body hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(var(--bottom-nav-h) + 16px); left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 11px 20px; border-radius: 12px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); z-index: 120;
  max-width: 92vw; text-align: center;
}

/* ============================================================
   MASAÜSTÜ (≥1024px) — kenar çubuğu düzeni
   ============================================================ */
@media (min-width: 1024px) {
  .sidebar {
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
    background: var(--card); border-right: 1px solid var(--border);
    padding: 20px 14px;
  }
  .sidebar-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; padding: 4px 10px 18px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
  .sidebar-brand .brand-name { color: var(--primary-strong); }
  .sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
  .sidebar-nav .nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; border: none; background: transparent; border-radius: var(--radius-sm);
    font-size: 15px; font-weight: 600; color: var(--muted); cursor: pointer; text-align: left;
    transition: all .15s;
  }
  .sidebar-nav .nav-item .nav-ico { font-size: 18px; }
  .sidebar-nav .nav-item:hover { background: var(--bg); color: var(--text); }
  .sidebar-nav .nav-item.active { background: var(--primary-light); color: var(--primary-strong); }
  .sidebar-user {
    display: flex; align-items: center; gap: 10px;
    border-top: 1px solid var(--border); padding-top: 14px; margin-top: 8px;
  }
  .avatar {
    width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 17px;
  }
  .sidebar-user-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .sidebar-user-meta .user-email { max-width: 150px; }

  .app-main { margin-left: var(--sidebar-w); }
  .topbar { display: none; }
  .bottom-nav { display: none; }
  .content { padding: 26px 30px 40px; }
  .toast { bottom: 24px; }

  #view-chat { height: calc(100vh - 70px); }
  .chat-input-wrap { bottom: 10px; }
}

/* ============================================================
   TABLET (768–1023px) — üstteki ince çubuk
   ============================================================ */
@media (min-width: 768px) and (max-width: 1023px) {
  .content { padding: 18px 24px calc(var(--bottom-nav-h) + 26px); }
  .prof-grid { grid-template-columns: 1fr 1fr; }
  .prof-grid .full { grid-column: 1 / -1; }
}

/* ============================================================
   TELEFON (<768px)
   ============================================================ */
@media (max-width: 767px) {
  .content { padding-left: 12px; padding-right: 12px; }
  .msg-bubble { max-width: 90%; }
  .user-email { display: none; }
  .row-form input, .row-form select { min-width: 100%; }
  .row-form .btn { width: 100%; }
  .doc-type { display: none; }
  .btn-attach { width: 42px; }
  .card { padding: 15px; }
  .auth-box { padding: 28px 20px; }
}
