/* ==========================================================================
   FlaskChat — koyu tema
   Dış font/CDN yok: sistem yazı tipi yığını kullanılır.
   ========================================================================== */

:root {
  --bg:          #0b0e14;
  --bg-soft:     #10141d;
  --surface:     #161b26;
  --surface-2:   #1c2331;
  --surface-3:   #222b3b;
  --line:        #262f40;
  --line-soft:   #1e2634;

  --text:        #e7ebf3;
  --text-dim:    #9aa5b8;
  --text-faint:  #6b7688;

  --accent:      #6d8cff;
  --accent-soft: #2a3557;
  --danger:      #ff6b74;
  --ok:          #4ade80;
  --warn:        #fbbf24;

  --radius-sm: 8px;
  --radius:    14px;
  --radius-lg: 20px;

  --shadow:    0 10px 30px rgba(0, 0, 0, .45);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .3);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

/* --------------------------------------------------------------------- */
/* Temel                                                                  */
/* --------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

h1, h2, h3, p, ul, figure, blockquote { margin: 0; padding: 0; }
ul { list-style: none; }

button, input, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  background: none;
  border: 0;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.is-hidden { display: none !important; }

* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 99px; }
*::-webkit-scrollbar-track { background: transparent; }

/* --------------------------------------------------------------------- */
/* Giriş sayfası                                                          */
/* --------------------------------------------------------------------- */

.page-home {
  background:
    radial-gradient(60rem 40rem at 15% -10%, rgba(109, 140, 255, .16), transparent 60%),
    radial-gradient(45rem 35rem at 100% 100%, rgba(109, 140, 255, .08), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

.home {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-t)) calc(18px + var(--safe-r))
           calc(24px + var(--safe-b)) calc(18px + var(--safe-l));
}

.card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 28px 24px 22px;
}

.card__head { margin-bottom: 22px; }

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }

.brand__mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), #8f6dff);
  color: #fff;
  box-shadow: 0 6px 18px rgba(109, 140, 255, .35);
}

.brand__name { font-size: 21px; font-weight: 650; letter-spacing: -.02em; }

.card__sub { color: var(--text-dim); font-size: 14px; }

.form { display: grid; gap: 16px; }

.field { display: grid; gap: 6px; }

.field__label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.field__input {
  width: 100%;
  /* 16px: iOS'ta odaklanınca sayfanın kendiliğinden zoomlanmasını engeller */
  font-size: 16px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s, background .15s;
}

.field__input::placeholder { color: var(--text-faint); }
.field__input:hover { border-color: var(--surface-3); }

.field__input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-soft);
  box-shadow: 0 0 0 3px rgba(109, 140, 255, .18);
}

.field__input--code {
  font-family: var(--font-mono);
  letter-spacing: .32em;
  text-transform: uppercase;
  font-size: 18px;
  padding-right: 6px;
}

.field__hint { font-size: 12px; color: var(--text-faint); line-height: 1.4; }

.actions { display: grid; gap: 10px; margin-top: 4px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 46px;
  padding: 0 16px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: transform .08s, background .15s, border-color .15s, filter .15s;
}

.btn:active { transform: translateY(1px); }

.btn--primary {
  background: linear-gradient(135deg, var(--accent), #7b7dff);
  color: #fff;
  box-shadow: 0 6px 18px rgba(109, 140, 255, .3);
}

.btn--primary:hover { filter: brightness(1.07); }

.btn--ghost { background: var(--surface-2); border-color: var(--line); color: var(--text); }
.btn--ghost:hover { background: var(--surface-3); }

.alert {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 18px;
  padding: 11px 13px;
  font-size: 13.5px;
  color: #ffd7d9;
  background: rgba(255, 107, 116, .1);
  border: 1px solid rgba(255, 107, 116, .3);
  border-radius: var(--radius);
}

.alert svg { flex: none; margin-top: 1px; color: var(--danger); }

.privacy {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
  display: grid;
  gap: 7px;
}

.privacy li {
  position: relative;
  padding-left: 20px;
  font-size: 12.5px;
  color: var(--text-faint);
  line-height: 1.45;
}

.privacy li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: .55em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: .65;
}

/* --------------------------------------------------------------------- */
/* Oda düzeni                                                             */
/* --------------------------------------------------------------------- */

.page-room { background: var(--bg); overflow: hidden; }

/* Flex kullanılıyor: bağlantı çubuğu gizlendiğinde grid satırlarının
   kayıp .stage'in yüksekliğini çökertmesini önler. */
.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

.topbar, .conn { flex: none; }

/* Üst çubuk ------------------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  padding-top: calc(10px + var(--safe-t));
  background: rgba(16, 20, 29, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
  min-height: 56px;
}

.topbar__title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.topbar__label {
  font-size: 10.5px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.topbar__actions { display: flex; align-items: center; gap: 4px; }
.topbar__actions form { display: flex; }

.icon-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 11px;
  color: var(--text-dim);
  background: transparent;
  transition: background .15s, color .15s;
}

.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { background: var(--surface-3); }
.icon-btn--danger:hover { color: var(--danger); background: rgba(255, 107, 116, .12); }
.icon-btn--sm { width: 30px; height: 30px; border-radius: 9px; }

.badge {
  position: absolute;
  top: 0;
  right: -1px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 99px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  border: 2px solid var(--bg-soft);
  box-sizing: content-box;
}

.code-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 10px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  transition: background .15s, border-color .15s;
}

.code-chip:hover { background: var(--surface-3); border-color: var(--surface-3); }

.code-chip__text {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .16em;
  padding-left: .16em;
}

.code-chip__icon { color: var(--text-faint); flex: none; }
.code-chip.is-copied { border-color: var(--ok); }
.code-chip.is-copied .code-chip__icon { color: var(--ok); }

/* Bağlantı durumu ------------------------------------------------------ */

.conn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 12.5px;
  background: rgba(251, 191, 36, .1);
  color: var(--warn);
  border-bottom: 1px solid rgba(251, 191, 36, .2);
}

.conn[hidden] { display: none; }

.conn__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.4s ease-in-out infinite;
}

.conn.is-error {
  background: rgba(255, 107, 116, .1);
  color: var(--danger);
  border-bottom-color: rgba(255, 107, 116, .22);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .25; }
}

/* Sahne ---------------------------------------------------------------- */

.stage {
  position: relative;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr;
  min-height: 0;
}

.chat {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

/* Mesaj listesi -------------------------------------------------------- */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  .messages { scroll-behavior: auto; }
}

.empty {
  margin: auto;
  max-width: 320px;
  text-align: center;
  padding: 24px 8px;
  color: var(--text-faint);
}

.empty__icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin: 0 auto 14px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--accent);
}

.empty__title { color: var(--text-dim); font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.empty__text { font-size: 13px; line-height: 1.55; }

/* Mesaj ---------------------------------------------------------------- */

.msg {
  display: flex;
  max-width: 100%;
  margin-top: 8px;
  animation: rise .18s ease-out;
}

.msg.is-grouped { margin-top: 2px; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .msg, .jump, .reply-bar, .toast { animation: none; }
}

.msg__bubble {
  position: relative;
  max-width: min(78%, 560px);
  padding: 8px 12px 6px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  overflow-wrap: anywhere;
}

.msg--mine { justify-content: flex-end; }

.msg--mine .msg__bubble {
  background: linear-gradient(160deg, #33437a, #2b3766);
  border-color: #3c4d87;
  border-bottom-right-radius: 6px;
}

.msg--theirs .msg__bubble { border-bottom-left-radius: 6px; }

.msg__author {
  display: block;
  font-size: 12.5px;
  font-weight: 650;
  margin-bottom: 2px;
  color: var(--author, var(--accent));
}

.msg.is-grouped .msg__author,
.msg--mine .msg__author { display: none; }

.msg__text {
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg__time {
  display: block;
  margin-top: 2px;
  font-size: 10.5px;
  color: var(--text-faint);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.msg--mine .msg__time { color: rgba(231, 235, 243, .5); }

.msg__quote {
  display: block;
  margin: 2px 0 6px;
  padding: 5px 9px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: rgba(0, 0, 0, .22);
  font-size: 12.5px;
  line-height: 1.35;
}

.msg__quote[hidden] { display: none; }

.msg__quote-who {
  display: block;
  font-weight: 650;
  color: var(--accent);
  margin-bottom: 1px;
}

.msg__quote-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text-dim);
}

.msg__reply {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text-dim);
  opacity: 0;
  transform: scale(.85);
  transition: opacity .13s, transform .13s, color .13s;
  pointer-events: none;
}

.msg__bubble:hover .msg__reply,
.msg__reply:focus-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.msg__reply:hover { color: var(--text); }

/* Dokunmatik cihazlarda hover yok: buton hep dokunulabilir kalsın */
@media (hover: none) {
  .msg__reply { opacity: .5; transform: none; pointer-events: auto; }
}

/* Sistem mesajı -------------------------------------------------------- */

.sys {
  align-self: center;
  max-width: 90%;
  margin: 10px 0 2px;
  padding: 4px 12px;
  border-radius: 99px;
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
  animation: rise .18s ease-out;
}

.sys--join  { color: #86c9a0; border-color: rgba(74, 222, 128, .2); }
.sys--leave { color: #c9a086; border-color: rgba(251, 191, 36, .18); }
.sys--warn  { color: var(--warn); border-color: rgba(251, 191, 36, .25); }

/* "Yeni mesaj" düğmesi -------------------------------------------------- */

.jump {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 99px;
  background: var(--accent);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  animation: rise .2s ease-out;
}

.jump[hidden] { display: none; }

/* Yazıyor -------------------------------------------------------------- */

.typing {
  min-height: 17px;
  padding: 0 6px 2px;
  font-size: 12px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Yazma alanı ---------------------------------------------------------- */

.composer {
  flex: none;
  padding: 6px 12px calc(10px + var(--safe-b));
  background: var(--bg-soft);
  border-top: 1px solid var(--line-soft);
}

.composer__row { display: flex; align-items: flex-end; gap: 8px; }

.composer__input {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 132px;
  padding: 11px 14px;
  /* 16px: iOS odaklanma zoom'unu engeller */
  font-size: 16px;
  line-height: 1.4;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 20px;
  transition: border-color .15s, box-shadow .15s;
}

.composer__input::placeholder { color: var(--text-faint); }

.composer__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109, 140, 255, .15);
}

.send {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  transition: transform .1s, background .15s, filter .15s;
}

.send:disabled { background: var(--surface-3); color: var(--text-faint); cursor: default; }
.send:not(:disabled):hover { filter: brightness(1.08); }
.send:not(:disabled):active { transform: scale(.93); }

/* Yanıt çubuğu --------------------------------------------------------- */

.reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  padding: 6px 6px 6px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  background: var(--surface);
  animation: rise .15s ease-out;
}

.reply-bar[hidden] { display: none; }

.reply-bar__body { flex: 1; min-width: 0; display: grid; gap: 1px; }
.reply-bar__who { font-size: 12px; font-weight: 650; color: var(--accent); }

.reply-bar__text {
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Kullanıcı listesi ---------------------------------------------------- */

.people {
  position: fixed;
  z-index: 30;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(80vw, 288px);
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 34px rgba(0, 0, 0, .5);
  padding: calc(12px + var(--safe-t)) 12px calc(12px + var(--safe-b));
  transform: translateX(102%);
  transition: transform .22s cubic-bezier(.32, .72, 0, 1), visibility .22s;
  visibility: hidden;
}

.people.is-open { transform: none; visibility: visible; }

.people__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px 10px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 8px;
}

.people__title {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.people__list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 2px;
}

.person { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 10px; }
.person:hover { background: var(--surface); }

.person__avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--avatar, var(--surface-3));
  color: #0b0e14;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.person__name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.person__tag {
  flex: none;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--surface-3);
  color: var(--text-dim);
}

.person__tag--owner { background: rgba(251, 191, 36, .15); color: var(--warn); }
.person__tag--me    { background: var(--accent-soft); color: #a9bcff; }

.people__note {
  padding: 10px 4px 0;
  border-top: 1px solid var(--line-soft);
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text-faint);
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, .55);
  animation: fade .18s ease-out;
}

.scrim[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* --------------------------------------------------------------------- */
/* Onay kutusu                                                            */
/* --------------------------------------------------------------------- */

.dialog {
  width: min(92vw, 360px);
  margin: auto;
  padding: 22px 20px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(2px);
}

.dialog__title { font-size: 17px; font-weight: 650; margin-bottom: 6px; }
.dialog__text { font-size: 14px; color: var(--text-dim); line-height: 1.5; }

.dialog__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.dialog__actions .btn { min-height: 42px; font-size: 14.5px; }

/* --------------------------------------------------------------------- */
/* Bildirim balonları                                                     */
/* --------------------------------------------------------------------- */

.toasts {
  position: fixed;
  z-index: 60;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(88px + var(--safe-b));
  display: grid;
  gap: 8px;
  justify-items: center;
  width: max-content;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}

.toast {
  padding: 9px 16px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: rise .18s ease-out;
}

.toast--error { border-color: rgba(255, 107, 116, .4); color: #ffd7d9; }
.toast--ok    { border-color: rgba(74, 222, 128, .4); color: #c9f7d8; }

/* --------------------------------------------------------------------- */
/* Geniş ekran                                                            */
/* --------------------------------------------------------------------- */

@media (min-width: 860px) {
  .app {
    max-width: 1180px;
    margin: 0 auto;
    border-left: 1px solid var(--line-soft);
    border-right: 1px solid var(--line-soft);
  }

  .topbar { padding-left: 16px; padding-right: 16px; }
  .topbar__title { align-items: flex-start; }
  .topbar__menu { display: none; }

  .stage { grid-template-columns: minmax(0, 1fr) 272px; }

  .messages { padding: 18px 20px 8px; }
  .composer { padding: 8px 20px calc(14px + var(--safe-b)); }

  .people {
    position: static;
    width: auto;
    transform: none;
    visibility: visible;
    box-shadow: none;
    padding-top: 14px;
  }

  .people__close { display: none; }
  .scrim { display: none !important; }

  .toasts { bottom: 96px; }
  .msg__bubble { max-width: min(70%, 560px); }
}

@media (min-width: 1100px) {
  .stage { grid-template-columns: minmax(0, 1fr) 300px; }
}

/* Çok dar telefonlar */
@media (max-width: 360px) {
  .code-chip__text { font-size: 13.5px; letter-spacing: .12em; }
  .msg__bubble { max-width: 86%; }
  .card { padding: 24px 18px 20px; }
}
