/* Bileşen katmanı: Tailwind yardımcı sınıflarını tamamlar, çerçeve/kostüm kuralları burada. */

:root {
  --ring: 139 92 246;
  --rail-w: 74px;
}

html, body { height: 100%; }
body { font-family: "Inter", system-ui, "Segoe UI", sans-serif; overscroll-behavior: none; }

.ic {
  width: 17px; height: 17px; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}

/* --------------------------------------------------------------- üst çubuk */
.tb {
  display: grid; place-items: center;
  height: 30px; width: 30px; border-radius: 9px;
  color: rgb(203 213 225);
  transition: background .15s, color .15s;
}
.tb:hover:not(:disabled) { background: rgb(51 65 85 / .7); color: #fff; }
.tb.is-on { background: rgb(124 58 237 / .22); color: rgb(216 180 254); box-shadow: inset 0 0 0 1px rgb(139 92 246 / .45); }
.tb.lg { height: 32px; width: 32px; }
.vr { width: 1px; height: 18px; background: rgb(51 65 85 / .8); margin: 0 2px; }

.title-input {
  width: 210px; max-width: 34vw;
  background: transparent; border: 1px solid transparent; border-radius: 7px;
  padding: 1px 6px; margin-left: -6px;
  font-size: 13px; font-weight: 700; color: #f1f5f9;
}
.title-input:hover { border-color: rgb(51 65 85); }
.title-input:focus { outline: none; border-color: rgb(139 92 246); background: rgb(15 23 42 / .7); }

/* --------------------------------------------------------------- butonlar */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 13px; border-radius: 10px;
  font-size: 12.5px; font-weight: 600; color: #e2e8f0;
  background: rgb(30 41 59); border: 1px solid rgb(51 65 85);
  transition: transform .12s, background .15s, border-color .15s, filter .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  border-color: rgb(148 163 184 / .25); color: #fff;
  box-shadow: 0 8px 22px -10px rgb(124 58 237 / .8);
}
.btn-secondary { background: rgb(51 65 85 / .55); }
.btn-xs { height: 26px; padding: 0 9px; font-size: 11.5px; border-radius: 8px; }
.btn-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 9px; border-radius: 8px; font-size: 11.5px; font-weight: 500;
  color: rgb(148 163 184); background: rgb(30 41 59 / .6); border: 1px solid rgb(51 65 85 / .7);
  transition: color .15s, background .15s, border-color .15s;
}
.btn-ghost:hover { color: #e2e8f0; background: rgb(51 65 85 / .8); border-color: rgb(71 85 105); }

.btn-icon {
  display: grid; place-items: center; height: 30px; width: 30px; border-radius: 8px;
  color: rgb(148 163 184); background: rgb(30 41 59 / .75); border: 1px solid rgb(51 65 85 / .8);
  transition: color .15s, background .15s, border-color .15s;
}
.btn-icon:hover { color: #fff; background: rgb(51 65 85); border-color: rgb(100 116 139); }
.btn-icon.is-on {
  color: rgb(221 214 254); background: rgb(124 58 237 / .25); border-color: rgb(139 92 246 / .6);
}
.btn-icon svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.mini {
  display: grid; place-items: center; height: 24px; width: 24px; border-radius: 7px;
  color: rgb(100 116 139); transition: color .15s, background .15s;
}
.mini:hover { color: #e2e8f0; background: rgb(51 65 85 / .8); }
.mini.is-on { color: rgb(251 191 36); }
.mini svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* --------------------------------------------------------------- form */
.lbl {
  display: block; font-size: 10.5px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: rgb(148 163 184); margin-bottom: 4px;
}
.inp {
  height: 30px; padding: 0 8px; border-radius: 8px;
  font-size: 12.5px; color: #f1f5f9;
  background: rgb(15 23 42 / .85); border: 1px solid rgb(51 65 85 / .9);
  transition: border-color .15s, box-shadow .15s;
}
textarea.inp { height: auto; padding: 7px 8px; line-height: 1.45; }
.inp:focus { outline: none; border-color: rgb(139 92 246); box-shadow: 0 0 0 3px rgb(124 58 237 / .18); }
.inp::placeholder { color: rgb(100 116 139); }
select.inp { appearance: none; background-image: linear-gradient(45deg, transparent 50%, rgb(148 163 184) 50%), linear-gradient(135deg, rgb(148 163 184) 50%, transparent 50%); background-position: calc(100% - 13px) 13px, calc(100% - 8px) 13px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 22px; }

.rng { -webkit-appearance: none; appearance: none; height: 4px; border-radius: 999px; background: rgb(51 65 85); }
.rng::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 999px; background: #a855f7; border: 2px solid #ede9fe; cursor: pointer; }
.rng::-moz-range-thumb { width: 12px; height: 12px; border-radius: 999px; background: #a855f7; border: 2px solid #ede9fe; cursor: pointer; }
.rng:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgb(124 58 237 / .3); }

.chk { width: 15px; height: 15px; accent-color: #7c3aed; }

.swatch {
  width: 30px; height: 30px; padding: 0; border-radius: 8px; cursor: pointer;
  background: rgb(15 23 42); border: 1px solid rgb(51 65 85);
}
.swatch::-webkit-color-swatch-wrapper { padding: 2px; }
.swatch::-webkit-color-swatch { border: none; border-radius: 6px; }

kbd {
  display: inline-block; padding: 1px 6px; border-radius: 6px;
  font-family: ui-monospace, "Cascadia Mono", monospace; font-size: 11px;
  background: rgb(30 41 59); border: 1px solid rgb(71 85 105); color: rgb(226 232 240);
}
#help-modal td { padding: 5px 0; color: rgb(203 213 225); border-bottom: 1px solid rgb(30 41 59 / .8); }
#help-modal td + td { text-align: right; }

/* --------------------------------------------------------------- sol ray */
.rail-tab svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.rail-tab.is-on { color: rgb(221 214 254); background: rgb(124 58 237 / .16); }
.rail-tab.is-on::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: #a855f7;
}

/* --------------------------------------------------------------- tuval */
.stage {
  display: flex; align-items: center; justify-content: center;
  min-height: 0; overflow: hidden; position: relative;
  background:
    radial-gradient(900px 520px at 50% -10%, rgb(30 41 59 / .9), transparent 70%),
    linear-gradient(rgb(2 6 23 / .96), rgb(2 6 23 / .96))
    ;
  background-color: #070b16;
}
.stage::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(rgb(148 163 184 / .16) 1px, transparent 1.6px);
  background-size: 22px 22px;
}
.stage .canvas-container {
  position: relative; z-index: 2;
  border-radius: 3px;
  box-shadow: 0 30px 70px -30px rgb(0 0 0 / .9), 0 0 0 1px rgb(148 163 184 / .22);
}
.stage-hint {
  position: absolute; z-index: 1; bottom: 12px; left: 0; right: 0;
  text-align: center; font-size: 11px; line-height: 1.6; color: rgb(100 116 139);
  pointer-events: none;
}
.drop-overlay {
  position: absolute; inset: 0; z-index: 5; display: none;
  place-items: center; background: rgb(124 58 237 / .16);
  border: 2px dashed rgb(167 139 250); border-radius: 12px; margin: 14px;
  backdrop-filter: blur(1px);
}
.drop-overlay span {
  padding: 8px 16px; border-radius: 10px; background: rgb(15 23 42 / .92);
  color: #e9d5ff; font-size: 13px; font-weight: 700;
}
.stage.drop-live .drop-overlay { display: grid; }

.bg-checker {
  background-image:
    linear-gradient(45deg, rgb(148 163 184 / .18) 25%, transparent 25%),
    linear-gradient(-45deg, rgb(148 163 184 / .18) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgb(148 163 184 / .18) 75%),
    linear-gradient(-45deg, transparent 75%, rgb(148 163 184 / .18) 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
}

/* --------------------------------------------------------------- katman listesi */
.layer-row:focus-visible { outline: 2px solid rgb(139 92 246); outline-offset: 1px; }

/* --------------------------------------------------------------- kaydırma çubuğu */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: rgb(15 23 42 / .5); }
::-webkit-scrollbar-thumb { background: rgb(51 65 85); border-radius: 999px; border: 2px solid rgb(15 23 42 / .5); }
::-webkit-scrollbar-thumb:hover { background: rgb(71 85 105); }

/* --------------------------------------------------------------- toast girişi */
#toasts > div { opacity: 0; transform: translateY(6px); }
#toasts > div.opacity-100 { opacity: 1; transform: none; }

/* --------------------------------------------------------------- iletişim */
.iletisim {
  font-weight: 600; text-decoration: none;
  padding: 2px 6px; margin-left: -6px; border-radius: 6px; white-space: nowrap;
}
.iletisim:hover { text-decoration: underline; }
.iletisim:focus-visible { outline: 2px solid rgb(139 92 246); outline-offset: 1px; }

/* --------------------------------------------------------------- dar ekran */
/* Çekmeceler çalışma alanına göre konumlanır: üst/alt çubuk yükseklikleri
   mobilde sardığı için sabit piksel ofsetleri (56px/32px) geçersiz kalırdı. */
#btn-right-close { display: none; }
@media (max-width: 1279px) {
  #btn-right-close { display: grid; }
  #right.right-panel {
    position: absolute; top: 0; bottom: 0; right: 0; z-index: 40;
    width: min(326px, 92vw);
    transform: translateX(103%); transition: transform .22s ease;
    box-shadow: -20px 0 45px -20px rgb(0 0 0 / .8);
  }
  #app.right-open .right-panel { transform: none; }
  #scrim { display: block; }
  #app.right-open #scrim, #workspace.lib-open #scrim { opacity: 1; pointer-events: auto; }
}
@media (max-width: 900px) {
  #library {
    position: absolute; top: 0; bottom: 0; left: var(--rail-w); z-index: 40;
    width: min(300px, 86vw);
    transform: translateX(calc(-100% - var(--rail-w))); transition: transform .22s ease;
    box-shadow: 20px 0 45px -20px rgb(0 0 0 / .8);
  }
  #workspace.lib-open #library { transform: none; }
  .title-input { width: 150px; }
}

/* --------------------------------------------------------------- mobil */
html { -webkit-text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }

/* Mobil tarayıcıda adres çubuğu inip kalkarken 100% yükseklik tuvali kesiyordu. */
@supports (height: 100dvh) {
  html, body, #app { height: 100dvh; }
}

#app { touch-action: manipulation; }
/* Kapalı çekmece sürükleyerek dışarıda durur; taşan genişlik mobilde belgenin
   kaydırılabilir olmasına yol açıyordu. */
#workspace { position: relative; overflow: hidden; }
#rail { width: var(--rail-w); }
header { position: relative; z-index: 45; }

/* Tuvalde tarayıcı jestleri sürüklemeyi bozmasın. */
.stage, .stage .canvas-container { touch-action: none; }

#scrim {
  display: none; position: absolute; inset: 0; z-index: 35;
  background: rgb(2 6 23 / .62); opacity: 0; pointer-events: none;
  transition: opacity .22s ease;
}
.hint-touch { display: none; }

/* İkincil eylemler geniş ekranda üst çubukta durur; ••• düğmesi gereksiz.
   Sınıf seçicileri Tailwind yardımcı sınıflarının ardında kalıyor: display
   kuralları bu yüzden alt çubuk taşısa da id ile verildi. */
#topbar-more { display: contents; }
.menu-etiket { display: none; }
#btn-more { display: none; }

/* --------------------------------------------------------------- dokunmatik hedefler */
@media (pointer: coarse) {
  .tb { height: 40px; width: 40px; border-radius: 11px; }
  .tb.lg { height: 42px; width: 42px; }
  .tb .ic { width: 20px; height: 20px; }
  .btn { height: 44px; padding: 0 16px; font-size: 14px; border-radius: 12px; }
  .btn-xs { height: 36px; padding: 0 12px; font-size: 13px; }
  .btn-ghost { padding: 9px 12px; font-size: 13px; }
  .btn-icon { height: 40px; width: 40px; }
  .btn-icon svg { width: 18px; height: 18px; }
  .mini { height: 36px; width: 36px; }
  .mini svg { width: 18px; height: 18px; }
  /* iOS, 16px altı yazıya odaklanınca sayfayı yakınlaştırıyor: formda 16px zorunlu. */
  .inp { height: 42px; padding: 0 11px; font-size: 16px; }
  textarea.inp { font-size: 16px; padding: 10px 11px; }
  select.inp { background-position: calc(100% - 13px) 18px, calc(100% - 8px) 18px; }
  .swatch { height: 42px; width: 42px; }
  .chk { width: 20px; height: 20px; }
  .rng { height: 6px; }
  .rng::-webkit-slider-thumb { width: 26px; height: 26px; }
  .rng::-moz-range-thumb { width: 24px; height: 24px; }
  .lbl { font-size: 11.5px; }
  /* İpucu metni parmağa göre değişir; genişlik değil dokunma biçimi belirleyici. */
  .hint-mouse { display: none; }
  .hint-touch { display: block; }
  .stage-hint { font-size: 12px; }
}

/* --------------------------------------------------------------- dar üst çubuk */
/* 1024 px altında üç blok birden sığmıyor: ikincil eylemler ••• menüsüne iner,
   başlık bloğu küçülebilir bırakılır, araç takımı gerekirse yatay kayar. */
@media (max-width: 1023px) {
  .topbar-left { flex: 1 1 0; min-width: 0; }
  .topbar-meta { flex: 1 1 0; min-width: 0; }
  .meta-row { flex-wrap: nowrap; white-space: nowrap; overflow: hidden; }
  /* Şablon adı panelde de okunuyor; yer kazanmak için dar çubukta düşurulur,
   * veritabanı durumu kırpılırsa ... ile belli olur (ayrıntı başlıkta).
   * Otomatik kayıt damgası da toast ile zaten bildiriliyor. */
  #tpl-chip, #save-state { display: none; }
  #db-chip { flex: 1 1 0; min-width: 0; display: block; overflow: hidden; text-overflow: ellipsis; }
  .topbar-tools { min-width: 0; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; }
  .topbar-tools::-webkit-scrollbar { display: none; }
  .topbar-tools .tb { flex: 0 0 auto; }
  .topbar-actions { flex: 0 0 auto; }

  #btn-more { display: grid; }
  #topbar-more { display: none; }
  #app.more-open #topbar-more {
    display: flex; flex-direction: column; gap: 2px;
    position: absolute; top: 100%; right: 10px; margin-top: 6px;
    min-width: 226px; max-height: 72dvh; overflow-y: auto;
    padding: 6px; border-radius: 14px;
    border: 1px solid rgb(71 85 105); background: rgb(15 23 42 / .98);
    box-shadow: 0 26px 60px -22px rgb(0 0 0 / .9);
  }
  #app.more-open #topbar-more .tb {
    display: flex; align-items: center; gap: 11px;
    width: 100%; height: 44px; padding: 0 12px; border-radius: 10px;
    font-size: 13.5px; font-weight: 600; color: #dbeafe;
  }
  #app.more-open #topbar-more .menu-etiket { display: inline; }
}

/* --------------------------------------------------------------- telefon düzeni */
@media (max-width: 700px) {
  :root { --rail-w: 56px; }

  /* h-14 / h-8 yardımcı sınıfları öğe seçicisini eziyor: yükseklik id ile açılır. */
  #app > header { flex-wrap: wrap; height: auto; gap: 8px; padding-top: calc(6px + env(safe-area-inset-top)); padding-bottom: 6px; }
  .topbar-tools { order: 3; flex: 0 0 100%; margin: 0; }
  .topbar-meta .title-input { width: 100%; max-width: 100%; min-width: 0; }
  #db-chip { display: none; }

  .rail-tab span { display: none; }

  #app > footer { height: auto; padding: 6px 12px calc(6px + env(safe-area-inset-bottom)); }
  #toasts { left: 10px; right: 10px; bottom: calc(52px + env(safe-area-inset-bottom)); align-items: stretch; }
  #toasts > div { width: 100%; }

  /* Öneşleme tek sütuna iner; kart taşarsa kendi içinde kayar. */
  #export-modal > div, #help-modal > div { max-height: 92dvh; overflow-y: auto; }
  #exp-preview { max-height: 30vh; }
}
