/**
 * Uygulama geneli açılır pencereler — style.css .modal ile uyumlu ortak kabuk.
 * Arkadaşlık, DJ, yasak, ayarlar ve mobil (layout-compact) dahil.
 * Bu dosya diğer modül CSS'lerinden SONRA yüklenmelidir (index.html).
 */

/* —— Eksik düğme varyantları (modallarda yaygın) —— */
.btn-secondary {
  background: var(--bg-light);
  color: var(--text-dark);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border-light);
  border-color: var(--text-light);
  color: var(--text-dark);
}

body.theme-dark .btn-secondary {
  background: var(--bg-light);
  border-color: var(--border);
  color: var(--text-dark);
}

.btn-xs {
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.3;
}

.modal-body .btn-primary,
.friend-modal-body .btn-primary,
.friend-modal-footer .btn-primary,
.market-item-card .btn-primary,
.dj-request-dialog .btn-primary,
.room-ban-dialog .btn-primary {
  width: auto;
  min-width: 0;
}

.modal-body .form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.modal-body .form-actions .btn {
  margin-top: 0;
  flex: 1 1 auto;
}

.modal-body .form-actions .btn-secondary {
  flex: 0 1 auto;
}

/* —— Ana modal (#modalOverlay) —— */
.modal-overlay {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  padding: 16px;
  align-items: center;
  justify-content: center;
}

#modalOverlay > .modal {
  color: var(--text-dark);
  max-width: min(520px, 100%);
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--bg-white);
  background-clip: padding-box;
  border: none;
  box-shadow:
    0 0 0 1px var(--border),
    0 20px 60px rgba(15, 23, 42, 0.18);
  isolation: isolate;
}

#modalOverlay > .modal:has(.user-settings-layout) {
  max-width: min(640px, 100%);
}

.modal-header {
  background: var(--bg-white);
  color: var(--text-dark);
  gap: 12px;
}

.modal-header > span,
.modal-header #modalTitle {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dark);
  line-height: 1.3;
}

.modal-close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--text-mid);
  transition: background 0.15s, color 0.15s;
}

.modal-close .icon {
  width: 20px;
  height: 20px;
}

.modal-close:hover {
  background: var(--bg-light);
  color: var(--text-dark);
}

.modal-body {
  background: var(--bg-white);
  color: var(--text-dark);
  font-size: 14px;
  line-height: 1.45;
}

.modal-body .modal-hint {
  font-size: 13px;
  color: var(--text-mid);
  line-height: 1.45;
}

/* Form öğeleri modal içinde auth/sohbet ile aynı */
.modal-body .form-group label {
  color: var(--text-mid);
  font-size: 13px;
  font-weight: 500;
}

.modal-body .form-group input:not([type='checkbox']):not([type='color']):not([type='radio']),
.modal-body .form-group select,
.modal-body .form-group textarea,
.modal-body select#prefPmPolicy,
.modal-body input[type='text'],
.modal-body input[type='number'],
.modal-body input[type='password'],
.modal-body input[type='search'],
.modal-body textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dark);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.modal-body .form-group input:focus,
.modal-body .form-group select:focus,
.modal-body .form-group textarea:focus,
.modal-body select#prefPmPolicy:focus,
.modal-body input[type='text']:focus,
.modal-body input[type='number']:focus {
  border-color: var(--accent);
}

.modal-body .btn {
  font-family: inherit;
}

.modal-body .btn-primary {
  background: var(--accent);
  color: #fff;
}

.modal-body .btn-primary:hover {
  background: var(--accent-hover);
}

.modal-body .form-actions .btn {
  margin-top: 0;
}

.modal-body .settings-toggle {
  color: var(--text-dark);
  border-bottom-color: var(--border-light);
}

.modal-body .settings-toggle span {
  flex: 1;
  padding-right: 8px;
}

.modal-body .user-pref-section-title {
  color: var(--text-light);
}

/* —— Ortak kabuk: alternatif modal yapıları —— */
.friend-modal-overlay,
.dj-request-modal,
.room-ban-modal {
  z-index: var(--z-ui-overlay, 25000);
}

.friend-modal-overlay {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.friend-modal {
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  max-width: min(520px, 100%);
}

.friend-modal-header {
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
}

.friend-modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dark);
}

.friend-modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-mid);
}

.friend-modal-close:hover {
  background: var(--bg-light);
  color: var(--text-dark);
}

.friend-modal-body {
  background: var(--bg-white);
  color: var(--text-dark);
  padding: 20px;
}

.friend-modal-footer {
  background: var(--bg-light);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
}

.friend-modal-footer .btn-primary {
  background: var(--accent);
  color: #fff;
}

.dj-request-backdrop,
.room-ban-backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.dj-request-dialog,
.room-ban-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  color: var(--text-dark);
}

.dj-request-title {
  color: var(--text-dark);
  font-size: 16px;
  font-weight: 600;
}

.dj-request-dialog .btn-primary,
.room-ban-dialog .btn-primary {
  background: var(--accent);
  color: #fff;
}

.room-owner-overlay {
  background: var(--room-owner-overlay-bg, rgba(15, 23, 42, 0.45));
  backdrop-filter: blur(2px);
}

.room-owner-panel {
  border: 1px solid var(--border);
  color: var(--text-dark);
}

.room-owner-header {
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
}

.room-owner-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dark);
}

.room-owner-close {
  color: var(--text-mid);
  border-radius: var(--radius-sm);
}

.room-owner-close:hover {
  background: var(--bg-light);
  color: var(--text-dark);
}

/* —— Koyu tema —— */
body.theme-dark .modal-overlay,
body.theme-dark .friend-modal-overlay {
  background: rgba(0, 0, 0, 0.62);
}

body.theme-dark .modal,
body.theme-dark .modal-header,
body.theme-dark .modal-body,
body.theme-dark .friend-modal,
body.theme-dark .friend-modal-header,
body.theme-dark .friend-modal-body,
body.theme-dark .dj-request-dialog,
body.theme-dark .room-ban-dialog {
  background: var(--bg-white);
  border-color: var(--border);
  color: var(--text-dark);
}

body.theme-dark .friend-modal-footer {
  background: var(--bg-light);
}

body.theme-dark .modal-close:hover,
body.theme-dark .friend-modal-close:hover {
  background: var(--bg-light);
  color: var(--text-dark);
}

body.theme-dark .modal-body .form-group input:not([type='checkbox']):not([type='color']),
body.theme-dark .modal-body select,
body.theme-dark .modal-body textarea,
body.theme-dark .modal-body input[type='text'],
body.theme-dark .modal-body input[type='number'] {
  background: var(--bg-light);
  border-color: var(--border);
  color: var(--text-dark);
}

/* —— Mobil / layout-compact: pencereler ortada —— */
@media (max-width: 640px) {
  .modal-overlay {
    align-items: center;
    justify-content: center;
    padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px));
  }

  .modal {
    width: 100%;
    max-width: min(520px, 100%);
    max-height: min(88dvh, 100%);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
  }

  .modal-header {
    padding: 14px 16px;
  }

  .modal-body {
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
  }

  .friend-modal-overlay {
    align-items: center;
    justify-content: center;
    padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px));
  }

  .friend-modal {
    max-height: min(88dvh, 100%);
    border-radius: var(--radius-lg);
  }

  .dj-request-modal,
  .room-ban-modal {
    align-items: center;
    justify-content: center;
    padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px));
  }

  .dj-request-dialog,
  .room-ban-dialog {
    width: 100%;
    max-width: min(520px, 100%);
    border-radius: var(--radius-lg);
  }
}

html.layout-compact .modal-overlay {
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px));
}

html.layout-compact .modal {
  width: 100%;
  max-width: min(520px, 100%);
  max-height: min(88dvh, 100%);
  border-radius: var(--radius-lg);
}

/* —— Market / çanta — mobil ortada —— */
@media (max-width: 640px) {
  .market-shop-overlay {
    align-items: center;
    justify-content: center;
    padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px));
  }

  .market-shop-panel {
    width: 100%;
    max-width: min(560px, 100%);
    max-height: min(88dvh, 100%);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
  }
}

html.layout-compact .market-shop-overlay {
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px));
}

html.layout-compact .market-shop-panel {
  width: 100%;
  max-width: min(560px, 100%);
  max-height: min(88dvh, 100%);
  border-radius: var(--radius-lg);
}

.market-shop-overlay .btn-secondary,
.market-item-card .btn-secondary {
  background: var(--bg-light);
  color: var(--text-dark);
  border: 1px solid var(--border);
}

body.theme-dark .gift-picker-panel,
body.theme-dark .chip-wallet-panel,
body.theme-dark .gift-picker-header,
body.theme-dark .chip-wallet-sticky {
  background: var(--bg-white);
  border-color: var(--border);
  color: var(--text-dark);
}

body.theme-dark .gift-picker-close:hover,
body.theme-dark .chip-wallet-close:hover {
  background: var(--bg-light);
  color: var(--text-dark);
}

/* ========== Sohbet modal tasarım sistemi (ortak kart / sekme / tipografi) ========== */
:root {
  --chat-modal-card-radius: 12px;
  --chat-modal-gap: 10px;
  --chat-modal-title: 15px;
  --chat-modal-body-text: 14px;
  --chat-modal-caption: 13px;
  --chat-modal-label: 13px;
}

.modal-body .form-hint,
.modal-body .modal-hint,
.friend-modal-body .form-hint,
.room-info-form .form-hint,
.room-info-hint-muted {
  font-size: var(--chat-modal-caption);
  color: var(--text-mid);
  line-height: 1.45;
  margin: 0;
}

.modal-body .form-msg,
.modal-body .modal-success,
.modal-body .modal-error,
.friend-modal-body .form-msg {
  font-size: var(--chat-modal-caption);
  margin-top: 8px;
  line-height: 1.4;
}

.modal-body .form-msg.success,
.modal-body .modal-success {
  color: var(--success);
}

.modal-body .form-msg.error,
.modal-body .modal-error {
  color: var(--danger);
}

.modal-body .form-group label,
.room-info-form .form-group label {
  color: var(--text-mid);
  font-size: var(--chat-modal-label);
  font-weight: 500;
}

.modal-body h3,
.modal-body h4,
.friend-modal-body h4 {
  font-size: var(--chat-modal-title);
  font-weight: 600;
  color: var(--text-dark);
  line-height: 1.3;
}

.modal-body .btn-sm,
.modal-body .btn-s {
  font-size: var(--chat-modal-caption);
}

/* Ortak kart yüzeyi — oda bilgisi, whois, yasak, liste satırları */
.modal-body .room-info-tile,
.modal-body .whois-card,
.modal-body .profile-view-field,
.modal-body .alan-room-ban-row,
.modal-body .alan-rs-report,
.modal-body .room-info-inbox-item,
.modal-body .admin-action-item,
.friend-modal-body .friend-add-item,
.friend-modal-body .friend-request-row {
  border-radius: var(--chat-modal-card-radius);
  border: 1px solid var(--border);
  background: var(--bg-light);
}

.modal-body .admin-action-item {
  padding: 14px 16px;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.modal-body .admin-action-item:hover {
  border-color: var(--accent);
  background: var(--bg-light);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

.modal-body .admin-action-title {
  font-size: var(--chat-modal-body-text);
  font-weight: 600;
  color: var(--text-dark);
}

.modal-body .admin-action-desc {
  font-size: var(--chat-modal-caption);
  color: var(--text-mid);
}

/* Profil / whois üst alanı — gradient yerine nötr kart */
.modal-body .profile-view-hero,
.modal-body .whois-hero {
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--chat-modal-card-radius);
  margin: 0;
  padding: 16px;
}

body.theme-dark .modal-body .profile-view-hero,
body.theme-dark .modal-body .whois-hero {
  background: var(--bg-light);
  border-color: var(--border);
}

.modal-body .whois-card-head {
  background: transparent;
  border-bottom: 1px solid var(--border);
  color: var(--text-dark);
  font-size: var(--chat-modal-label);
}

.modal-body .whois-card {
  overflow: hidden;
}

.modal-body .whois-label {
  color: var(--text-mid);
  font-size: var(--chat-modal-caption);
}

.modal-body .whois-value {
  color: var(--text-dark);
  font-size: var(--chat-modal-body-text);
}

.modal-body .whois-empty {
  border-radius: var(--chat-modal-card-radius);
  border: 1px dashed var(--border);
  background: var(--bg-light);
  color: var(--text-mid);
  font-size: var(--chat-modal-caption);
}

/* Yasak formu — hedef kartı diğer kartlarla aynı */
.modal-body .alan-room-ban-form .alan-ban-target-card {
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--chat-modal-card-radius);
}

.modal-body .alan-room-ban-form .alan-ban-scope-card {
  border-radius: var(--chat-modal-card-radius);
  border-width: 1px;
}

.modal-body .alan-room-ban-form .alan-ban-scope-card.is-selected {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: none;
}

/* Sekmeler — Yetkili paneli + Oda yönetimi aynı pill stili */
#modalOverlay .alan-rs-tab,
#modalOverlay .alan-rm-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-mid);
  font-size: var(--chat-modal-caption);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

#modalOverlay .alan-rs-tab.is-active,
#modalOverlay .alan-rm-tab.is-active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: none;
}

#modalOverlay .alan-rs-tabs,
#modalOverlay .alan-rm-tabs {
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  gap: 6px;
}

/* Mobil: ikon üstte, küçük başlık altta — Yetkili + Oda yönetimi */
@media (max-width: 768px) {
  #modalOverlay .alan-rs-tabs,
  #modalOverlay .alan-rm-tabs,
  .alan-rs-tabs,
  .alan-rm-tabs {
    flex-wrap: nowrap;
    justify-content: space-between;
    overflow-x: visible;
    gap: 4px;
  }

  #modalOverlay .alan-rs-tab,
  #modalOverlay .alan-rm-tab,
  .alan-rs-tab,
  .alan-rm-tab {
    flex: 1 1 0;
    min-width: 0;
    max-width: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px 10px;
    white-space: normal;
    text-align: center;
    border-radius: var(--radius-sm);
  }

  #modalOverlay .alan-tab-icon,
  .alan-tab-icon {
    font-size: 1.15rem;
    line-height: 1;
  }

  #modalOverlay .alan-tab-label,
  .alan-tab-label {
    display: block;
    font-size: 10px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0.01em;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: inherit;
    opacity: 0.92;
  }

  #modalOverlay .alan-rs-tab.is-active .alan-tab-label,
  #modalOverlay .alan-rm-tab.is-active .alan-tab-label,
  .alan-rs-tab.is-active .alan-tab-label,
  .alan-rm-tab.is-active .alan-tab-label {
    opacity: 1;
  }
}

#modalOverlay .alan-rm-section-title,
.modal-body .alan-rs-mod-grid h4,
.modal-body .alan-rs-ann-block h4 {
  font-size: var(--chat-modal-body-text);
  font-weight: 600;
  color: var(--text-dark);
}

/* Ayarlar sol menü — sekme stiliyle uyumlu */
.modal-body .user-pref-nav-item {
  font-size: var(--chat-modal-caption);
  color: var(--text-mid);
  border-radius: var(--radius-sm);
}

.modal-body .user-pref-nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

.modal-body .user-pref-section-title {
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--text-light);
  font-weight: 600;
}

.modal-body .room-info-tile {
  background: var(--bg-light);
  border-color: var(--border);
}

.modal-body .room-info-tile h4 {
  font-size: var(--chat-modal-title);
}

.modal-body .room-info-tile p {
  font-size: var(--chat-modal-caption);
  color: var(--text-mid);
  opacity: 1;
}

.modal-body .room-info-form-actions,
.modal-body .alan-ban-form-actions,
.modal-body .room-info-form-actions {
  gap: 10px;
}

@media (max-width: 640px) {
  .chip-wallet-overlay,
  .gift-picker-overlay {
    align-items: center;
    justify-content: center;
    padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px));
  }

  .chip-wallet-panel,
  .gift-picker-panel {
    width: 100%;
    max-width: min(560px, 100%);
    max-height: min(88dvh, 100%);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
  }
}

/* Kompakt/mobil: tüm overlay pencereleri ortala (öncelikli) */
@media (max-width: 1024px) {
  .modal-overlay,
  #modalOverlay,
  .friend-modal-overlay,
  .dj-request-modal,
  .room-ban-modal,
  .market-shop-overlay,
  .market-room-setup-overlay,
  .chip-wallet-overlay,
  .gift-picker-overlay,
  .room-owner-overlay,
  .image-crop-overlay {
    align-items: center !important;
    justify-content: center !important;
  }

  .modal,
  #modalOverlay > .modal,
  .friend-modal,
  .dj-request-dialog,
  .room-ban-dialog,
  .market-shop-panel,
  .chip-wallet-panel,
  .gift-picker-panel,
  .room-owner-panel {
    border-radius: var(--radius-lg, 16px) !important;
    border-bottom: 1px solid var(--border) !important;
  }
}
