:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1f2430;
  --text-muted: #6b7280;
  --primary: #4338ca;
  --primary-hover: #3730a3;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); }
.brand:hover { text-decoration: none; }
.topnav { display: flex; gap: 18px; flex: 1; }
.topnav a { color: var(--text-muted); font-weight: 500; margin-right: 18px; }
.topnav a:last-child { margin-right: 0; }

/* --- Nav grup açılır menüleri (İçerik / Araçlar / Ayarlar) --- */
.nav-dropdown { position: relative; display: inline-block; }
.nav-dropdown-toggle.action-menu-toggle {
  background: none;
  border: none;
  padding: 0;
  margin-right: 18px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-muted);
}
.nav-dropdown-toggle.action-menu-toggle:hover { background: none; color: var(--text); }

.nav-hamburger { display: none; }
.topbar-user.topbar-user-mobile { display: none; }
.topbar-user { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--text-muted); }
.logout-link { color: var(--danger); }

.page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 22px; margin: 0; }

.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f3f4f6; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

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

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: 14px;
}
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-info { background: #dbeafe; color: #1e40af; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--text-muted); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }

.avatar-thumb {
  width: 38px; height: 38px; border-radius: 50%;
  object-fit: cover; background: #e5e7eb; vertical-align: middle;
}
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge-active { background: #dcfce7; color: #166534; }
.badge-draft { background: #fef3c7; color: #92400e; }
.badge-archived { background: #e5e7eb; color: #374151; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-warning { background: #ffedd5; color: #9a3412; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-danger { background: #fee2e2; color: #991b1b; }

.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}

/* --- Form / Tabs --- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  overflow-x: auto;
}
.tab-btn {
  padding: 10px 18px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 20px;
}
.form-grid.single { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field .hint { font-size: 12px; color: var(--text-muted); font-weight: 400; }

input[type=text], input[type=number], input[type=date], input[type=email],
input[type=password], select, textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
textarea { resize: vertical; min-height: 70px; }

.slider-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row input[type=range] { flex: 1; }
.slider-value { width: 34px; text-align: right; font-weight: 700; color: var(--primary); font-size: 13px; }

.interest-row { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.interest-row input[type=text] { flex: 2; }
.interest-row input[type=range] { flex: 1; }
.interest-row .remove-interest { color: var(--danger); cursor: pointer; font-size: 18px; padding: 0 6px; }

.form-actions {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}

.avatar-upload { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.avatar-preview {
  width: 72px; height: 72px; border-radius: 50%; object-fit: cover;
  background: #e5e7eb; border: 1px solid var(--border);
}

.login-wrap {
  max-width: 380px;
  margin: 80px auto;
}
.login-wrap h1 { text-align: center; font-size: 20px; margin-bottom: 24px; }

/* --- Mahalle --- */
.neighborhood-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.neighborhood-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-align: center;
}
.neighborhood-avatar {
  width: 100%;
  height: 140px;
  object-fit: cover;
  background: #e5e7eb;
  display: block;
}
.neighborhood-avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  background: var(--primary);
}
.neighborhood-card-body { padding: 14px; }
.neighborhood-card-body h3 { margin: 0 0 4px; font-size: 15px; }
.neighborhood-meta { font-size: 12px; color: var(--text-muted); margin: 0 0 8px; }
.neighborhood-actions { margin-top: 10px; display: flex; gap: 6px; justify-content: center; }

/* --- Opinion Engine --- */
.persona-checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.persona-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}
.persona-checkbox input { width: auto; }

.opinion-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}
.opinion-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.opinion-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.opinion-text {
  font-size: 14px;
  line-height: 1.5;
  font-style: italic;
  color: var(--text);
  margin: 0 0 10px;
}

/* --- Visual Studio --- */
.visual-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.visual-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.visual-card img {
  width: 100%;
  height: 220px;
  object-fit: cover;
  display: block;
  background: #e5e7eb;
}
.visual-card-body { padding: 12px; }
.visual-card-body strong { font-size: 14px; }

/* --- Yükleme (spinner) --- */
.spinner-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 220px;
  padding: 20px;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spinnerRotate 0.8s linear infinite;
}
@keyframes spinnerRotate {
  to { transform: rotate(360deg); }
}

/* --- Kombin seçim kutucukları (Visual Studio) --- */
.outfit-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
  max-height: 220px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.outfit-picker-item {
  cursor: pointer;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
}
.outfit-picker-item img {
  width: 100%;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid transparent;
  display: block;
  margin-bottom: 4px;
}
.outfit-picker-item input:checked + img,
.outfit-picker-item input:checked ~ img {
  border-color: var(--primary);
}
.outfit-picker-item input { display: none; }
.outfit-picker-item.selected img { border-color: var(--primary); }

/* --- Sohbet --- */
.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.chat-conv-select {
  flex: 1;
  min-width: 200px;
  max-width: 400px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--surface);
}

.chat-window {
  height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}
.chat-bubble-row { display: flex; }
.chat-row-user { justify-content: flex-end; }
.chat-row-persona { justify-content: flex-start; }
.chat-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
}
.chat-bubble-user { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble-persona { background: #f0f1f5; color: var(--text); border-bottom-left-radius: 4px; }
.chat-bubble-error { background: #fee2e2; color: #991b1b; border-bottom-left-radius: 4px; }

.chat-bubble-text { white-space: pre-wrap; }
.chat-meta {
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.65;
}
.chat-bubble-user .chat-meta { text-align: right; }

@keyframes chatBubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.chat-bubble-enter {
  animation: chatBubbleIn 0.25s ease-out;
}

.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
}
.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  display: inline-block;
  animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.chat-form textarea {
  flex: 1;
  resize: none;
}

/* --- Tablo taşma güvenlik ağı: sadece tabloyu saran kaydırma alanı,
   .card'ın kendisini değil (açılır menüler .card dışına taşabilsin diye) --- */
.table-scroll { overflow-x: auto; }

/* --- Satır işlemleri açılır menüsü (İşlemler / ⋮) --- */
.row-actions {
  position: relative;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.action-menu-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
}
.action-menu-toggle:hover { background: #f3f4f6; }
.action-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  min-width: 190px;
  z-index: 30;
  padding: 6px;
  text-align: left;
}
.action-menu.open { display: block; }
.action-menu a, .action-menu form { display: block; }
.action-menu a, .action-menu button.action-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  font-weight: 500;
}
.action-menu a:hover, .action-menu button.action-menu-item:hover { background: #f3f4f6; text-decoration: none; }
.action-menu button.action-menu-item.danger { color: var(--danger); }
.mobile-only-menu-item { display: none; }

/* ============================================================
   MOBİL / DAR EKRAN İYİLEŞTİRMELERİ
   ============================================================ */
@media (max-width: 720px) {
  .page-container { padding: 16px 12px 40px; }

  .topbar-inner { position: relative; flex-wrap: nowrap; padding: 12px 16px; }
  .nav-hamburger { display: inline-block; }
  .topbar-user-desktop { display: none; }

  .topnav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    align-items: stretch;
    padding: 6px 16px 12px;
    box-shadow: 0 10px 24px rgba(0,0,0,0.1);
    z-index: 40;
    gap: 0;
    max-height: 80vh;
    overflow-y: auto;
  }
  .topnav.mobile-open { display: flex; }
  .topnav a { margin-right: 0; padding: 11px 4px; border-bottom: 1px solid var(--border); }
  .nav-dropdown { width: 100%; }
  .nav-dropdown-toggle { display: none; }
  .topnav .action-menu {
    display: block;
    position: static;
    box-shadow: none;
    border: none;
    padding: 0;
    min-width: auto;
  }
  .topnav .action-menu a { padding-left: 18px; color: var(--text-muted); }

  .topbar-user.topbar-user-mobile {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    margin-top: 6px;
  }

  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-header > div { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
  .page-header h1 { font-size: 19px; }

  .form-grid { grid-template-columns: 1fr; }

  table { font-size: 13px; }
  th, td { padding: 9px 8px; }

  /* Karakter listesi: mobilde yer kazanmak için ikincil sütunları gizle
     (Kullanıcı Adı: 3., Yaş: 5., Sosyal: 6. sütun) */
  .persona-table th:nth-child(3), .persona-table td:nth-child(3),
  .persona-table th:nth-child(5), .persona-table td:nth-child(5),
  .persona-table th:nth-child(6), .persona-table td:nth-child(6) {
    display: none;
  }
  /* Aksiyon sütununda mobilde sadece ⋮ menüsü görünsün, Sohbet/Düzenle menü içine taşınır */
  .row-primary-action { display: none; }
  .mobile-only-menu-item { display: block; }

  .btn { padding: 10px 14px; }
  .btn-sm { padding: 7px 10px; }

  .neighborhood-grid, .visual-gallery, .opinion-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

  .chat-toolbar { flex-direction: column; align-items: stretch; }
  .chat-conv-select { max-width: none; }

  .login-wrap { margin: 40px auto; padding: 0 16px; }
}

/* --- Persona Diversity Engine --- */
.dist-bar-row {
  display: grid;
  grid-template-columns: 160px 1fr 40px;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}
.dist-bar-label { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dist-bar-track { background: #f0f1f5; border-radius: 6px; height: 14px; overflow: hidden; }
.dist-bar-fill { background: var(--primary); height: 100%; border-radius: 6px; }
.dist-bar-count { text-align: right; color: var(--text-muted); font-weight: 600; }

.diversity-suggestion {
  margin-top: 16px;
  padding: 16px;
  background: #f5f3ff;
  border: 1px solid #ddd6fe;
  border-radius: 10px;
  font-size: 14px;
}

@media (max-width: 720px) {
  .dist-bar-row { grid-template-columns: 100px 1fr 30px; font-size: 12px; }
}

/* --- Lightbox (görsel büyütme) --- */
.lb-img { cursor: zoom-in; }
.lightbox-overlay {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(15, 15, 20, 0.9);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.lightbox-overlay.open { display: flex; }
.lightbox-content-img {
  max-width: 92vw;
  max-height: 85vh;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.lightbox-toolbar {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  gap: 10px;
  z-index: 1001;
}
.lightbox-btn {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}
.lightbox-btn:hover { background: rgba(255,255,255,0.22); text-decoration: none; color: #fff; }

@media (max-width: 720px) {
  .lightbox-toolbar { top: 12px; right: 12px; }
  .lightbox-btn { padding: 8px 12px; font-size: 12px; }
}

/* --- Özel dosya yükleme butonu --- */
.file-upload {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.file-upload-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.file-upload-label { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.file-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  transition: background 0.15s;
}
.file-upload-label:hover .file-upload-btn { background: #f3f4f6; border-color: #d1d5db; }
.file-upload-filename { font-size: 13px; color: var(--text-muted); }

/* --- Ana Dashboard --- */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.dashboard-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-decoration: none;
  transition: box-shadow 0.15s, transform 0.15s;
}
.dashboard-card:hover { box-shadow: 0 6px 16px rgba(0,0,0,0.08); transform: translateY(-1px); text-decoration: none; }
.dashboard-card-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.dashboard-card-value { font-size: 32px; font-weight: 700; color: var(--text); }
.dashboard-card-sub { font-size: 13px; color: var(--text-muted); }
.dashboard-card-warning .dashboard-card-value { color: #92400e; }
.dashboard-card-danger .dashboard-card-value { color: #991b1b; }
