:root {
  --accent: #0078ED;
  --accent-soft: rgba(0, 120, 237, .12);
  --danger: #E5383B;
}

html, body { height: 100%; }
body { overflow-x: hidden; }

.view { display: none; min-height: 100%; }
body[data-view="library"] #view-library,
body[data-view="camera"] #view-camera,
body[data-view="editor"] #view-editor { display: flex; flex-direction: column; }
body[data-view="camera"], body[data-view="editor"] { overflow: hidden; }

svg { flex: none; }

/* ---------- Üst çubuk ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.bar > :last-child { justify-self: end; }
.bar-title { margin: 0; font-size: 16px; font-weight: 700; text-align: center; }
.home-link { color: var(--accent); }
.text-btn {
  background: none; border: 0; padding: 6px 4px; cursor: pointer; color: var(--accent);
  font-size: 15px; justify-self: start;
}
.text-btn.strong { font-weight: 700; }
.text-btn:disabled { opacity: .4; cursor: default; }

/* ---------- Belgelerim ---------- */
.library { width: 100%; max-width: 860px; margin: 0 auto; padding: 20px 16px 40px; }
.start { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; border-radius: 18px; }
.start.drag { outline: 3px dashed var(--accent); outline-offset: 6px; }
.big-action {
  display: flex; align-items: center; gap: 14px; text-align: left; cursor: pointer;
  padding: 18px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow);
}
.big-action svg { width: 34px; height: 34px; color: var(--accent); }
.big-action span { display: flex; flex-direction: column; }
.big-action strong { font-size: 16px; }
.big-action small { color: var(--ink-soft); font-size: 13px; }
.big-action.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.big-action.primary svg, .big-action.primary small { color: rgba(255,255,255,.9); }
.big-action:active { transform: scale(.99); }

.section-title { font-size: 13px; letter-spacing: 1px; text-transform: uppercase; color: var(--ink-soft); margin: 30px 0 10px; }
.doc-list { display: grid; gap: 10px; }
.doc {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 14px; align-items: center;
  padding: 10px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
}
.doc img { width: 56px; height: 72px; object-fit: cover; border-radius: 4px; background: #fff; border: 1px solid var(--line); }
.doc-info { min-width: 0; }
.doc-info strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-info small { color: var(--ink-soft); }
.doc-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer;
  border-radius: 10px; border: 0; background: var(--surface-2); color: var(--accent);
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.danger { color: var(--danger); }
.icon-btn:hover { background: var(--accent-soft); }
.empty { color: var(--ink-soft); text-align: center; padding: 24px 0; }
.privacy-note { color: var(--ink-soft); font-size: 12.5px; text-align: center; margin-top: 28px; }
@media (max-width: 480px) {
  .doc { grid-template-columns: 48px 1fr; }
  .doc img { width: 48px; height: 62px; }
  .doc-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ---------- Kamera ---------- */
.dark { background: #000; color: #fff; }
#view-camera { position: fixed; inset: 0; }
.cam-stage { position: absolute; inset: 0; display: grid; place-items: center; overflow: hidden; }
#cam-video, #cam-overlay { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
.cam-flash.on { opacity: .8; transition: none; }
.cam-hint {
  position: absolute; top: calc(76px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  margin: 0; padding: 6px 14px; border-radius: 99px; background: rgba(0,0,0,.55); font-size: 14px; white-space: nowrap;
}
.cam-top, .cam-bottom { position: absolute; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; }
.cam-top { top: 0; padding-top: calc(14px + env(safe-area-inset-top)); }
.cam-bottom { bottom: 0; padding-bottom: calc(22px + env(safe-area-inset-bottom)); padding-top: 18px; background: linear-gradient(transparent, rgba(0,0,0,.6)); }
.round-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  background: rgba(0,0,0,.5); color: #fff;
}
.round-btn svg { width: 22px; height: 22px; }
.auto-toggle { display: flex; align-items: center; gap: 6px; font-size: 14px; background: rgba(0,0,0,.5); padding: 8px 12px; border-radius: 99px; }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 4px solid #fff; background: none; padding: 4px; cursor: pointer; }
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform .1s; }
.shutter:active span { transform: scale(.9); }
.cam-thumb { position: relative; width: 56px; height: 56px; border-radius: 8px; border: 2px solid #fff; background: #222; padding: 0; overflow: visible; cursor: pointer; }
.cam-thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; display: block; }
.cam-thumb img:not([src]) { visibility: hidden; }
.cam-thumb span { position: absolute; top: -8px; right: -8px; min-width: 22px; height: 22px; border-radius: 11px; background: var(--accent); font-size: 12px; font-weight: 700; display: grid; place-items: center; padding: 0 5px; }
.cam-done { min-width: 56px; height: 40px; border-radius: 20px; border: 0; padding: 0 16px; background: #fff; color: #000; font-weight: 700; cursor: pointer; }
.cam-done:disabled { opacity: .4; }

/* ---------- Düzenleyici ---------- */
#view-editor { position: fixed; inset: 0; background: var(--bg); }
.ed-main { position: relative; flex: 1; min-height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; padding: 16px 52px; }
.ed-preview { position: relative; width: 100%; height: 100%; min-height: 0; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; }
.ed-preview canvas { max-width: 100%; max-height: 100%; background: #fff; box-shadow: 0 4px 20px rgba(0,0,0,.25); }
.ed-preview canvas.dim { opacity: .55; }
.ed-preview .spinner { position: absolute; }
.nav-arrow {
  position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); display: grid; place-items: center; cursor: pointer;
}
.nav-arrow svg { width: 20px; height: 20px; }
.nav-arrow.left { left: 6px; } .nav-arrow.right { right: 6px; }
.nav-arrow:disabled { opacity: .3; cursor: default; }

.ed-controls {
  position: relative; z-index: 2;
  padding: 10px 0 calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px;
}
.thumbs { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px; scrollbar-width: none; }
.thumbs:empty { display: none; }
.thumbs button { flex: none; width: 40px; height: 54px; padding: 0; border-radius: 4px; border: 2px solid transparent; background: #fff; cursor: pointer; overflow: hidden; }
.thumbs button.sel { border-color: var(--accent); }
.thumbs canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px; scrollbar-width: none; justify-content: safe center; }
.chip {
  flex: none; padding: 8px 14px; border-radius: 99px; border: 0; cursor: pointer;
  background: var(--surface-2); font-size: 14px; font-weight: 500;
}
.chip.sel { background: var(--accent); color: #fff; }
.tools { display: flex; justify-content: space-around; padding: 0 8px; }
.tool, .menu-wrap { flex: 1; display: flex; justify-content: center; }
.tool {
  flex-direction: column; align-items: center; gap: 3px; min-width: 52px; padding: 4px; cursor: pointer;
  border: 0; background: none; color: var(--accent); font-size: 11.5px; border-radius: 10px;
}
.tool svg { width: 24px; height: 24px; }
.tool:disabled { opacity: .35; cursor: default; }
.tool.danger { color: var(--danger); }
.menu-wrap { position: relative; }
.menu {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); z-index: 20;
  min-width: 230px; padding: 6px; border-radius: 14px; background: var(--surface);
  border: 1px solid var(--line); box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.menu button { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 9px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; font-size: 14px; }
.menu button:hover { background: var(--accent-soft); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu-label { font-size: 12px; color: var(--ink-soft); padding: 6px 10px 2px; }
.menu .check { width: 16px; color: var(--accent); }
.menu button.on .check::before { content: "✓"; font-weight: 700; }
.name-field { display: flex; align-items: center; gap: 8px; margin: 0 16px; color: var(--ink-soft); }
.name-field svg { width: 20px; height: 20px; }
.name-field input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.name-field input:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* ---------- Köşe ayarı ---------- */
.crop { position: fixed; inset: 0; z-index: 30; background: #000; color: #fff; display: flex; flex-direction: column; }
.crop[hidden] { display: none; }
.crop-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; }
.crop-bar.bottom { display: flex; justify-content: space-between; padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); }
.crop-bar h2 { margin: 0; font-size: 16px; }
.crop-bar > :last-child { justify-self: end; }
.crop .text-btn { color: #FFD60A; }
.crop-stage { position: relative; flex: 1; min-height: 0; touch-action: none; }
#crop-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.loupe { position: absolute; top: 16px; width: 116px; height: 116px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 4px 16px rgba(0,0,0,.6); pointer-events: none; }

/* ---------- Ortak katmanlar ---------- */
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.busy { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4); display: grid; place-items: center; padding: 16px; }
.busy[hidden] { display: none; }
.busy-card { width: min(360px, 100%); padding: 22px; border-radius: 18px; background: var(--surface); display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.busy-card small { color: var(--ink-soft); }
.progress { width: 100%; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.4); display: grid; place-items: center; padding: 16px; }
.sheet-backdrop[hidden] { display: none; }
.sheet { width: min(400px, 100%); padding: 22px; border-radius: 18px; background: var(--surface); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.sheet h3 { margin: 0 0 6px; font-size: 18px; }
.sheet p { margin: 0 0 18px; color: var(--ink-soft); }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.btn { padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 99px; background: rgba(20,20,22,.92); color: #fff; font-size: 14px;
}
.toast[hidden] { display: none; }
