/* =====================================================================
   PDF Stüdyosu — düzenleyici arayüzü
   ===================================================================== */

:root {
  --s-bg: #eef2f7;
  --s-surface: #ffffff;
  --s-panel: #ffffff;
  --s-ink: #0b1220;
  --s-ink-2: #33415c;
  --s-ink-3: #6b7c93;
  --s-line: #e2e8f0;
  --s-line-2: #cbd5e1;
  --s-brand: #c81f26;
  --s-brand-dark: #a3161d;
  --s-brand-soft: #fee2e2;
  --s-accent: #1d4ed8;
  --s-ok: #047857;
  --s-warn: #b45309;
  --s-danger: #b91c1c;
  --s-radius: 10px;
  --s-radius-sm: 7px;
  --s-shadow: 0 10px 30px -18px rgba(11, 18, 32, 0.45);
  --s-topbar: 56px;
  --s-status: 30px;
  --s-font: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* hidden özniteliği her zaman kazansın (display: grid/flex kuralları ezmesin) */
[hidden] { display: none !important; }

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

body.studio-body {
  font-family: var(--s-font);
  background: var(--s-bg);
  color: var(--s-ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.studio {
  display: grid;
  grid-template-rows: var(--s-topbar) minmax(0, 1fr) var(--s-status);
  height: 100vh;
  height: 100dvh;
}

/* ---------- üst çubuk ---------- */
.studio-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  background: var(--s-ink);
  color: #e6ecf7;
  border-bottom: 1px solid #1f2a3d;
}

.studio-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.studio-brand__mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(145deg, #e02d2d, var(--s-brand-dark));
}

.studio-brand__mark svg { width: 17px; height: 17px; }

.studio-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.studio-title__input {
  min-width: 0;
  width: min(340px, 100%);
  padding: 6px 10px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--s-radius-sm);
}

.studio-title__input:focus {
  outline: 2px solid #ff8f8f;
  outline-offset: 1px;
  background: rgba(255, 255, 255, 0.14);
}

.studio-save {
  font-size: 0.72rem;
  white-space: nowrap;
  color: #93a1b8;
}

.studio-save[data-state="saved"] { color: #6ee7b7; }
.studio-save[data-state="saving"] { color: #fcd34d; }
.studio-save[data-state="error"] { color: #fca5a5; }

.studio-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.sbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 12px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  border-radius: var(--s-radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.sbtn--primary { background: var(--s-brand); color: #fff; }
.sbtn--primary:hover { background: var(--s-brand-dark); }
.sbtn--primary:disabled { opacity: 0.6; cursor: progress; }

.sbtn--ghost {
  background: rgba(255, 255, 255, 0.07);
  color: #dbe3f0;
  border-color: rgba(255, 255, 255, 0.12);
}

.sbtn--ghost:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }

.sbtn--light {
  background: #fff;
  color: var(--s-ink);
  border-color: var(--s-line-2);
}
.sbtn--light:hover { background: #f7f9fc; }

.sbtn--icon { padding: 0 9px; }
.sbtn svg { width: 15px; height: 15px; }

/* ---------- gövde ---------- */
.studio-body-grid {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr) 300px;
  min-height: 0;
  overflow: hidden;
}

/* ---------- sol ray ---------- */
.studio-rail {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0;
  background: var(--s-surface);
  border-right: 1px solid var(--s-line);
  min-height: 0;
}

.studio-tools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--s-line);
}

.tool-btn {
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 7px 2px;
  font: inherit;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--s-ink-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--s-radius-sm);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.tool-btn svg { width: 18px; height: 18px; }
.tool-btn:hover { background: #f2f5f9; }
.tool-btn.is-active {
  color: var(--s-brand);
  background: var(--s-brand-soft);
  border-color: #fecaca;
}

.studio-pages {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.studio-pages__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--s-ink-3);
  border-bottom: 1px solid var(--s-line);
}

.studio-pages__actions { display: flex; gap: 2px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1;
  color: var(--s-ink-2);
  background: #fff;
  border: 1px solid var(--s-line);
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.icon-btn:hover { background: #f2f5f9; border-color: var(--s-line-2); }
.icon-btn svg { width: 14px; height: 14px; }
.icon-btn--wide { width: auto; padding: 0 8px; font-size: 0.7rem; }

.page-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 10px;
  list-style: none;
  overflow-y: auto;
  min-height: 0;
}

.page-item {
  position: relative;
  display: grid;
  gap: 4px;
  padding: 6px;
  background: #fff;
  border: 1.5px solid var(--s-line);
  border-radius: var(--s-radius);
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.page-item:hover { border-color: var(--s-line-2); }

.page-item.is-active {
  border-color: var(--s-brand);
  box-shadow: 0 0 0 3px rgba(200, 31, 38, 0.12);
}

.page-item canvas {
  width: 100%;
  height: auto;
  border-radius: 5px;
  background: #fff;
  display: block;
}

.page-item__label {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--s-ink-3);
  padding: 0 2px;
}

.page-item__label strong { color: var(--s-ink-2); }

/* ---------- tuval ---------- */
.studio-stage {
  display: grid;
  grid-template-rows: 40px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  background: var(--s-bg);
}

.studio-stage__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.72);
  border-bottom: 1px solid var(--s-line);
  backdrop-filter: blur(6px);
}

.zoom-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.zoom-label {
  min-width: 46px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--s-ink-2);
  font-variant-numeric: tabular-nums;
}

.stage-toggles {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.72rem;
  color: var(--s-ink-2);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
}

.switch input { accent-color: var(--s-brand); width: 14px; height: 14px; }

.stage-hint {
  color: var(--s-ink-3);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.canvas-wrap {
  position: relative;
  display: grid;
  place-items: start center;
  padding: 22px;
  overflow: auto;
  min-height: 0;
}

.canvas-holder {
  position: relative;
  box-shadow: var(--s-shadow);
  background: #fff;
}

#studio-canvas {
  display: block;
  touch-action: none;
  cursor: default;
}

#studio-canvas:focus-visible {
  outline: 3px solid var(--s-accent);
  outline-offset: 3px;
}

.canvas-wrap[data-tool="text"] #studio-canvas { cursor: text; }
.canvas-wrap[data-tool="rect"] #studio-canvas,
.canvas-wrap[data-tool="ellipse"] #studio-canvas,
.canvas-wrap[data-tool="line"] #studio-canvas { cursor: crosshair; }

.inline-editor {
  position: absolute;
  z-index: 20;
  margin: 0;
  padding: 2px;
  font-family: var(--s-font);
  color: #111827;
  background: #fff;
  border: 2px solid var(--s-brand);
  border-radius: 3px;
  resize: none;
  overflow: hidden;
  box-shadow: 0 8px 24px -10px rgba(11, 18, 32, 0.4);
}

.inline-editor:focus { outline: none; }

/* ---------- sağ panel ---------- */
.studio-panel {
  display: grid;
  grid-template-rows: 40px minmax(0, 1fr);
  background: var(--s-panel);
  border-left: 1px solid var(--s-line);
  min-height: 0;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--s-line);
}

.panel-tab {
  flex: 1;
  padding: 0 10px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--s-ink-3);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.panel-tab.is-active {
  color: var(--s-ink);
  border-bottom-color: var(--s-brand);
}

.panel-body {
  padding: 12px;
  overflow-y: auto;
  min-height: 0;
}

.panel-section {
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--s-line);
}

.panel-section:last-child { border-bottom: 0; margin-bottom: 0; }

.panel-title {
  margin: 0 0 8px;
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--s-ink-3);
}

.panel-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 6px;
}

.panel-field {
  display: grid;
  gap: 3px;
  margin-bottom: 7px;
}

.panel-field > span {
  font-size: 0.66rem;
  font-weight: 650;
  color: var(--s-ink-3);
}

.panel-field .input,
.panel-field .select,
.panel-field textarea {
  min-height: 30px;
  padding: 4px 7px;
  font-size: 0.76rem;
  border-radius: 6px;
  border: 1px solid var(--s-line-2);
  background: #fff;
  color: var(--s-ink);
  font-family: inherit;
  width: 100%;
}

.panel-field textarea { min-height: 68px; resize: vertical; line-height: 1.45; }

.panel-field .input:focus,
.panel-field .select:focus,
.panel-field textarea:focus {
  outline: none;
  border-color: var(--s-brand);
  box-shadow: 0 0 0 3px rgba(200, 31, 38, 0.12);
}

.panel-field input[type="color"] {
  padding: 2px;
  height: 30px;
  cursor: pointer;
}

.seg {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: #f2f5f9;
  border-radius: 6px;
}

.seg button {
  flex: 1;
  min-height: 26px;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--s-ink-2);
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}

.seg button.is-active {
  background: #fff;
  color: var(--s-ink);
  box-shadow: 0 1px 3px rgba(11, 18, 32, 0.12);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chip {
  min-height: 26px;
  padding: 0 8px;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--s-ink-2);
  background: #fff;
  border: 1px solid var(--s-line-2);
  border-radius: 999px;
  cursor: pointer;
}

.chip.is-active {
  color: var(--s-brand);
  background: var(--s-brand-soft);
  border-color: #fecaca;
}

.panel-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.panel-empty {
  padding: 22px 8px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--s-ink-3);
  line-height: 1.6;
}

/* katman listesi */
.layer-list { display: grid; gap: 3px; margin: 0; padding: 0; list-style: none; }

.layer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  font-size: 0.74rem;
  color: var(--s-ink-2);
  background: #fff;
  border: 1px solid var(--s-line);
  border-radius: 6px;
  cursor: pointer;
}

.layer-item.is-active { border-color: var(--s-brand); background: #fff7f7; }
.layer-item__icon { display: grid; place-items: center; width: 20px; height: 20px; color: var(--s-ink-3); flex-shrink: 0; }
.layer-item__icon svg { width: 13px; height: 13px; }
.layer-item__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-item__lock { border: 0; background: transparent; cursor: pointer; color: var(--s-ink-3); padding: 0 2px; font-size: 0.75rem; }
.layer-item__lock.is-locked { color: var(--s-brand); }

/* ---------- durum çubuğu ---------- */
.studio-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px;
  font-size: 0.7rem;
  color: var(--s-ink-3);
  background: #fff;
  border-top: 1px solid var(--s-line);
}

/* ---------- modallar ---------- */
.smodal {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 0;
  border: 0;
  border-radius: 14px;
  box-shadow: 0 40px 90px -40px rgba(11, 18, 32, 0.6);
  color: var(--s-ink);
  font-family: var(--s-font);
  overflow: hidden;
}

.smodal::backdrop {
  background: rgba(11, 18, 32, 0.45);
  backdrop-filter: blur(2px);
}

.smodal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--s-line);
}

.smodal__head h2 { margin: 0; font-size: 1rem; }

.smodal__body {
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 190px);
}

.smodal__foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.smodal .form { display: grid; gap: 10px; }
.smodal .field { display: grid; gap: 4px; }
.smodal .field label { font-size: 0.76rem; font-weight: 650; color: var(--s-ink-2); }
.smodal .field .hint { font-size: 0.68rem; color: var(--s-ink-3); }

.smodal .input,
.smodal .select {
  min-height: 34px;
  padding: 6px 9px;
  font: inherit;
  font-size: 0.82rem;
  border: 1px solid var(--s-line-2);
  border-radius: 7px;
  background: #fff;
  width: 100%;
}

.smodal .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.smodal .grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.template-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  text-align: left;
  font: inherit;
  color: inherit;
  background: #fff;
  border: 1px solid var(--s-line);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

.template-card:hover {
  border-color: var(--s-line-2);
  transform: translateY(-2px);
  box-shadow: 0 10px 24px -18px rgba(11, 18, 32, 0.5);
}

.template-card strong { font-size: 0.85rem; }
.template-card span { font-size: 0.72rem; color: var(--s-ink-3); line-height: 1.45; }
.template-card em {
  font-style: normal;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--s-brand);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.export-ready {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: 10px;
}

.export-ready strong { color: var(--s-ok); }
.export-ready p { margin: 0; font-size: 0.8rem; color: #065f46; }

.export-error {
  padding: 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  color: var(--s-danger);
  font-size: 0.82rem;
}

.export-warn {
  padding: 10px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  color: var(--s-warn);
  font-size: 0.76rem;
}

/* ---------- yardımcılar ---------- */
.muted { color: var(--s-ink-3); }
.small { font-size: 0.78rem; }
.mb-0 { margin-bottom: 0; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.85em; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

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

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .studio-body-grid { grid-template-columns: 190px minmax(0, 1fr) 268px; }
  .stage-hint { display: none; }
}

@media (max-width: 900px) {
  .studio-body-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .studio-rail {
    display: flex;
    align-items: stretch;
    gap: 0;
    border-right: 0;
    border-bottom: 1px solid var(--s-line);
    overflow-x: auto;
    min-width: 0;
  }

  .studio-tools {
    grid-template-columns: repeat(6, minmax(46px, 1fr));
    border-bottom: 0;
    border-right: 1px solid var(--s-line);
    flex-shrink: 0;
  }

  .studio-pages { flex: 1; min-width: 0; }
  .studio-pages__head { display: none; }

  .page-list {
    flex-direction: row;
    padding: 6px;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .page-item { width: 84px; flex-shrink: 0; }
  .page-item__label { display: none; }

  .studio-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--s-status);
    z-index: 40;
    max-height: 46vh;
    border-left: 0;
    border-top: 1px solid var(--s-line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -18px 40px -24px rgba(11, 18, 32, 0.5);
    transform: translateY(calc(100% - 0px));
    display: none;
  }

  .studio-panel.is-open { display: grid; }

  .canvas-wrap { padding: 12px; }
  .studio-brand__text { display: none; }
  .studio-title__input { width: 100%; }
  .studio-save { display: none; }
}

@media (max-width: 700px) {
  .studio {
    grid-template-rows: auto minmax(0, 1fr) var(--s-status);
  }

  .studio-topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 6px 8px;
    padding: 7px 8px;
  }

  .studio-brand { grid-column: 1; grid-row: 1; }

  .studio-title {
    grid-column: 2; grid-row: 1;
    min-width: 0;
  }

  .studio-title__input { width: 100%; }

  .studio-actions {
    grid-column: 1 / -1;
    grid-row: 2;
    overflow-x: auto;
    justify-content: flex-start;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .studio-actions > * { flex-shrink: 0; }

  .studio-save { display: none; }
  .stage-hint { display: none; }
}

@media (max-width: 560px) {
  .sbtn { padding: 0 9px; font-size: 0.74rem; }
  .studio-brand__text { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}
