:root {
  --desk: #e6eaf0;
  --surface: #ffffff;
  --ink: #18202f;
  --muted: #5d6677;
  --line: #d6dce5;
  --ink-blue: #2f3fa8;
  --ink-blue-dark: #232f82;
  --green: #0d7a55;
  --wa: #1a8f4c;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --desk: #12161e; --surface: #1a202b; --ink: #e8ecf3; --muted: #9aa4b6; --line: #2c3442;
    --ink-blue: #8d9cff; --ink-blue-dark: #aab5ff; --green: #4cc596; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --desk: #12161e; --surface: #1a202b; --ink: #e8ecf3; --muted: #9aa4b6; --line: #2c3442;
  --ink-blue: #8d9cff; --ink-blue-dark: #aab5ff; --green: #4cc596; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--desk); color: var(--ink); font: 15px/1.45 'Onest', system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink-blue); outline-offset: 2px; }

/* top bar */
.bar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; letter-spacing: -.02em; }
.bar-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 6px; cursor: pointer; text-decoration: none; color: var(--ink); font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.btn.primary { background: var(--ink-blue); border-color: var(--ink-blue); color: #fff; }
.btn.primary:hover { background: var(--ink-blue-dark); }
.btn.pro-btn { border: 1.5px dashed var(--ink-blue); color: var(--ink-blue); font-weight: 600; }
.btn.pro-btn.is-pro { border-style: solid; }
.btn.whatsapp { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; padding: 12px; font-size: 16px; }
.btn.add { width: 100%; border-style: dashed; color: var(--ink-blue); margin-top: 8px; }
.btn:disabled { opacity: .45; cursor: default; }
.count:not(:empty) { background: var(--ink-blue); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }

/* layout */
.workspace { display: grid; grid-template-columns: minmax(360px, 520px) 1fr; gap: 0; min-height: calc(100vh - 57px); }
.editor { background: var(--surface); border-right: 1px solid var(--line); padding: 4px 22px 60px; }
.preview-wrap { padding: 20px 28px 60px; position: sticky; top: 57px; align-self: start; max-height: calc(100vh - 57px); overflow: auto; }
.preview { position: relative; }
.preview .doc { transform-origin: top left; box-shadow: 0 1px 2px rgba(20, 30, 60, .08), 0 12px 32px -8px rgba(20, 30, 60, .22); }
.preview-summary { display: flex; gap: 22px; justify-content: flex-end; margin-bottom: 12px; color: var(--muted); font-size: 14px; }
.preview-summary b { color: var(--ink); font-size: 16px; }
.preview-summary span:last-child:not(:first-child) b { color: var(--green); }
.mobile-switch { display: none; }

/* panels: plain sections divided by rules, not floating cards */
.panel { padding: 20px 0 22px; border-bottom: 1px solid var(--line); }
.panel:last-child { border-bottom: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.panel h2 { font-size: 17px; margin: 0; letter-spacing: -.01em; }
.hint { color: var(--muted); font-size: 13px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.span2 { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=color]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 8px 10px; color: var(--ink); font-size: 15px;
}
input:focus, select:focus, textarea:focus { border-color: var(--ink-blue); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink-blue) 18%, transparent); }
textarea { resize: vertical; }
input[type=color] { width: 100%; height: 38px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: var(--surface); }
input[type=file] { font-size: 13px; color: var(--muted); }
.fine { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }
.fine.center { text-align: center; }

/* items */
.item { border-left: 3px solid var(--line); padding: 2px 0 10px 12px; margin-bottom: 12px; }
.item:focus-within { border-left-color: var(--ink-blue); }
.item-top { display: flex; align-items: center; gap: 8px; }
.item-n { color: var(--muted); font-size: 13px; width: 16px; }
.item-name { font-weight: 600; }
.item-tools { display: flex; }
.item-tools button { border: 0; background: none; width: 28px; height: 30px; cursor: pointer; color: var(--muted); border-radius: 4px; font-size: 15px; }
.item-tools button:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); }
.item-tools button:disabled { opacity: .3; cursor: default; }
.item-grid { display: grid; grid-template-columns: 1fr 1.1fr 1.5fr .9fr .9fr; gap: 8px; margin: 8px 0 0 24px; }
.item-more { margin: 6px 0 0 24px; font-size: 13px; color: var(--muted); }
.item-more summary { cursor: pointer; }
.item-more textarea { margin-top: 6px; }

.netcalc { margin-top: 14px; background: color-mix(in srgb, var(--green) 7%, var(--surface)); border-radius: var(--radius); padding: 10px 14px; }
.netcalc summary { cursor: pointer; font-weight: 600; color: var(--green); }
.netcalc-body { display: grid; gap: 8px; margin-top: 10px; }
.netcalc output { font-size: 14px; }
.netcalc output b { color: var(--green); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -2px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.chip:hover { border-color: var(--ink-blue); color: var(--ink-blue); }

.tag-pro { font-size: 12px; font-weight: 700; color: var(--ink-blue); border: 1.5px solid var(--ink-blue); border-radius: 4px; padding: 0 6px; transform: rotate(-4deg); display: inline-block; }
.tpl-pick { display: flex; gap: 10px; }
.tpl { flex: 1; align-items: center; text-align: center; color: var(--ink); cursor: pointer; font-size: 13px; }
.tpl input { position: absolute; opacity: 0; pointer-events: none; }
.tpl small { color: var(--ink-blue); font-weight: 700; }
.tpl-thumb { display: block; width: 100%; aspect-ratio: 210 / 150; border: 1.5px solid var(--line); border-radius: 6px; background: #fff; margin-bottom: 4px; position: relative; overflow: hidden; }
.tpl.on .tpl-thumb { border-color: var(--ink-blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink-blue) 20%, transparent); }
.tpl:has(input:focus-visible) .tpl-thumb { outline: 2px solid var(--ink-blue); outline-offset: 2px; }
.tpl-thumb::before, .tpl-thumb::after { content: ''; position: absolute; left: 10%; right: 10%; }
.tpl-thumb--sade::before { top: 14%; height: 8%; right: 55%; background: #1f2a44; }
.tpl-thumb--sade::after { top: 38%; height: 40%; background: repeating-linear-gradient(#dfe3ea 0 2px, transparent 2px 9px); }
.tpl-thumb--kurumsal::before { top: 0; left: 0; right: 0; height: 28%; background: #2f3fa8; }
.tpl-thumb--kurumsal::after { top: 42%; height: 40%; background: repeating-linear-gradient(#e9ebf7 0 6px, #fff 6px 12px); }
.tpl-thumb--zarif::before { top: 26%; height: 2px; background: #6a2c91; }
.tpl-thumb--zarif::after { top: 10%; height: 10%; right: 50%; background: #444; border-radius: 1px; }
.pro-panel.locked .grid > :not(.tpl-pick) { opacity: .75; }

/* dialogs */
dialog { border: 0; border-radius: 12px; padding: 22px; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .45); }
dialog::backdrop { background: rgba(15, 20, 35, .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dlg-head h2 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.x { border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); width: 36px; height: 36px; border-radius: 6px; }
.x:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
dialog p { color: var(--muted); font-size: 14px; }
.share-row { display: flex; gap: 8px; margin-top: 12px; }
.share-row input { flex: 1; min-width: 0; }
.share-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
dialog > label { margin-top: 10px; }

.drawer { margin-right: 0; height: 100vh; max-height: 100vh; border-radius: 0; width: min(440px, 100vw); display: none; flex-direction: column; }
.drawer[open] { display: flex; }
.saved { list-style: none; margin: 8px 0; padding: 0; flex: 1; overflow: auto; }
.saved li { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); }
.saved li.empty { color: var(--muted); padding: 20px 0; border: 0; }
.saved button { border: 0; background: none; cursor: pointer; color: var(--muted); width: 40px; font-size: 17px; }
.saved button:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 5%, transparent); }
.saved .saved-main { flex: 1; text-align: left; display: grid; grid-template-columns: auto 1fr; gap: 0 10px; padding: 12px 6px; color: var(--ink); font-size: 15px; }
.s-no { font-weight: 600; }
.s-client { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-meta { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.dlg-foot { display: flex; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.file-btn input { display: none; }

.pro-grid { display: grid; grid-template-columns: 150px 1fr; gap: 18px; align-items: center; margin: 8px 0 14px; }
.pro-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 15px; }
.price { text-align: center; margin: 6px 0 12px; color: var(--muted); }
.price strong { font-size: 30px; color: var(--ink); letter-spacing: -.02em; margin-right: 4px; }
#license-msg:empty { display: none; }
.havale { margin-top: 10px; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.havale summary { cursor: pointer; font-weight: 600; }
.havale ol { padding-left: 20px; margin: 10px 0 0; display: grid; gap: 10px; font-size: 14px; }
.havale ol input { margin-top: 4px; }
#dlg-pro.active .havale { display: none; }
.pro-active { display: none; text-align: center; font-weight: 600; color: var(--green) !important; font-size: 16px !important; }
#dlg-pro.active .pro-active { display: block; }
#dlg-pro.active :is(.price, #pro-buy, .fine, .share-row) { display: none; }
#license-msg { color: #b4321f; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; font-size: 14px; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

#print-root { display: none; }

summary.panel-head { cursor: pointer; list-style: none; margin-bottom: 0; }
summary.panel-head::-webkit-details-marker { display: none; }
summary.panel-head h2::after { content: ''; display: inline-block; width: 7px; height: 7px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); margin: 0 0 3px 10px; transition: transform .15s; }
details[open] > summary.panel-head { margin-bottom: 12px; }
details[open] > summary.panel-head h2::after { transform: rotate(-135deg); margin-bottom: -1px; }

@media (max-width: 1100px) {
  .bar-actions .btn.ghost#btn-new { display: none; }
}
@media (max-width: 900px) {
  body { padding-bottom: 64px; }
  .bar { position: static; padding: 8px 16px; }
  .bar-actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1.1fr .9fr 1.2fr 1.1fr; gap: 4px; }
  .bar-actions .btn { padding: 8px 4px; font-size: 13px; white-space: normal; line-height: 1.15; text-align: center; }
  .bar-actions #btn-new { display: none !important; }
  #btn-pro { padding: 5px 12px; }
  .toast { bottom: 80px; }
  .workspace { grid-template-columns: 1fr; }
  .mobile-switch { display: flex; position: sticky; top: 0; z-index: 15; background: var(--surface); border-bottom: 1px solid var(--line); }
  .mobile-switch button { flex: 1; border: 0; background: none; padding: 10px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
  .mobile-switch button[aria-selected=true] { color: var(--ink-blue); border-bottom-color: var(--ink-blue); }
  .workspace[data-view=edit] .preview-wrap { display: none; }
  .workspace[data-view=preview] .editor { display: none; }
  .editor { border-right: 0; padding: 0 16px 60px; }
  .preview-wrap { position: static; max-height: none; padding: 14px 16px 60px; }
  .item-grid { grid-template-columns: repeat(6, 1fr); margin-left: 0; }
  .item-grid > :nth-child(1) { grid-area: 1 / 1 / 2 / 3; }
  .item-grid > :nth-child(2) { grid-area: 1 / 3 / 2 / 5; }
  .item-grid > :nth-child(4) { grid-area: 1 / 5 / 2 / 7; }
  .item-grid > :nth-child(3) { grid-area: 2 / 1 / 3 / 5; }
  .item-grid > :nth-child(5) { grid-area: 2 / 5 / 3 / 7; }
  .item-more { margin-left: 0; }
}
@media (max-width: 520px) {
  .grid { grid-template-columns: 1fr; }
  .pro-grid { grid-template-columns: 1fr; justify-items: center; }
  .bar-actions .btn.ghost { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

@media print {
  body > :not(#print-root) { display: none !important; }
  #print-root { display: block; }
  body { padding: 0 !important; }
}
