/* Pazaryeri fiyat hesaplayıcı
   Fikir: sol tarafta sakin bir form, sağda pazaryerinin kestiği her kalemi
   tek tek gösteren bir satış fişi. Sayfanın tek gösterişli parçası fiş. */

@font-face { font-family: "Onest"; font-weight: 400; font-display: swap;
  src: url("../fonts/onest-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Onest"; font-weight: 400; font-display: swap;
  src: url("../fonts/onest-latin-ext-400-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Onest"; font-weight: 600; font-display: swap;
  src: url("../fonts/onest-latin-600-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Onest"; font-weight: 600; font-display: swap;
  src: url("../fonts/onest-latin-ext-600-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Onest"; font-weight: 700; font-display: swap;
  src: url("../fonts/onest-latin-700-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Onest"; font-weight: 700; font-display: swap;
  src: url("../fonts/onest-latin-ext-700-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }

:root {
  color-scheme: light;
  --bg: #e9edf1;
  --surface: #ffffff;
  --field: #f3f5f8;
  --ink: #16202c;
  --ink-2: #47525f;
  --muted: #6b7684;
  --line: #d5dce4;
  --line-strong: #b9c3ce;
  --accent: #1f4fd8;
  --accent-hover: #1a43b8;
  --on-accent: #ffffff;
  --loss: #b4271f;
  --focus: #1f4fd8;
  --dock-loss: #ff9b93;
  --band: #1e46c8;
  --band-ink: #ffffff;
  --band-ink-2: #d3defc;
  --gain: #0d7a45;
  --accent-soft: #e6ecfd;
  --shadow: 0 1px 0 rgba(22, 32, 44, .04), 0 18px 40px -24px rgba(22, 32, 44, .35);

  /* Kategorik renkler: sıra sabit, her renk bir kalemin kimliği */
  --slot-1: #2a78d6; --slot-2: #eb6834; --slot-3: #1baf7a; --slot-4: #eda100;
  --slot-5: #e87ba4; --slot-6: #008300; --slot-7: #6250d6; --slot-8: #e34948;

  --radius-s: 8px;
  --radius-m: 12px;
  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121821; --surface: #1a2230; --field: #141b26;
    --ink: #edf1f5; --ink-2: #b9c3cf; --muted: #8c97a6;
    --line: #2b3646; --line-strong: #3d4a5c;
    --accent: #7c9bff; --accent-hover: #9bb3ff; --on-accent: #0d1420;
    --loss: #ff8a80; --focus: #9bb3ff; --dock-loss: #b4271f;
    --band: #1b2b63; --band-ink: #ffffff; --band-ink-2: #b9c6ef; --gain: #4cd08a; --accent-soft: #1f2b4a;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 18px 40px -24px rgba(0, 0, 0, .8);
    --slot-1: #3987e5; --slot-2: #d95926; --slot-3: #199e70; --slot-4: #c98500;
    --slot-5: #d55181; --slot-6: #0ca30c; --slot-7: #9085e9; --slot-8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121821; --surface: #1a2230; --field: #141b26;
  --ink: #edf1f5; --ink-2: #b9c3cf; --muted: #8c97a6;
  --line: #2b3646; --line-strong: #3d4a5c;
  --accent: #7c9bff; --accent-hover: #9bb3ff; --on-accent: #0d1420;
  --loss: #ff8a80; --focus: #9bb3ff; --dock-loss: #b4271f;
    --band: #1b2b63; --band-ink: #ffffff; --band-ink-2: #b9c6ef; --gain: #4cd08a; --accent-soft: #1f2b4a;
  --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 18px 40px -24px rgba(0, 0, 0, .8);
  --slot-1: #3987e5; --slot-2: #d95926; --slot-3: #199e70; --slot-4: #c98500;
  --slot-5: #d55181; --slot-6: #0ca30c; --slot-7: #9085e9; --slot-8: #e66767;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }

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

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

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

/* ---------- Sayfa ---------- */

/* Üstte koyu mavi bir bant; form kartları ve fiş bandın üstüne biner. */
body {
  background:
    linear-gradient(var(--band), var(--band)) top / 100% 150px no-repeat,
    var(--bg);
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px 24px;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  color: var(--band-ink);
}

.masthead h1 {
  font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2rem);
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.lede {
  margin-top: 2px;
  color: var(--band-ink-2);
  font-size: 1rem;
}

.theme-toggle {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid color-mix(in srgb, var(--band-ink) 30%, transparent);
  border-radius: 50%;
  background: color-mix(in srgb, var(--band-ink) 10%, transparent);
  color: var(--band-ink);
  cursor: pointer;
}
.theme-toggle:hover { background: color-mix(in srgb, var(--band-ink) 20%, transparent); }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 400px);
  gap: 20px;
  align-items: start;
}

/* ---------- Form ---------- */

.calculator { display: grid; gap: 12px; min-width: 0; }

.group {
  margin: 0;
  padding: 14px 18px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--surface);
  min-width: 0;
}

/* legend'ı kenarlıktan çıkarıp normal başlık gibi akıtır */
.group legend {
  float: left;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  margin-bottom: 10px;
  font-size: 1rem;
  font-weight: 600;
}
.group legend .link-button { margin-left: auto; font-weight: 400; }
.group legend + * { clear: both; }
.group > * + *:not(legend) { margin-top: 12px; }
.group > legend + * { margin-top: 0; }

/* Soru kartı: hafif mavi zemin, seçili mod dolu mavi */
.group-mode {
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 25%, var(--line));
}

.group-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Kart rengi, fişteki ilgili kalemin rengiyle aynı */
.tone-1 { --tone: var(--slot-1); }
.tone-2 { --tone: var(--slot-2); }
.tone-5 { --tone: var(--slot-5); }
.card { border-top: 3px solid var(--tone); }

.chip {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--tone) 16%, var(--surface));
  color: var(--tone);
}
.chip svg { width: 17px; height: 17px; }

.field { display: grid; gap: 5px; min-width: 0; }
.field + .field { margin-top: 12px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-row .field + .field { margin-top: 0; }

.field label, .field-label {
  font-size: .875rem;
  font-weight: 600;
  color: var(--ink);
}

.label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.unit { font-weight: 400; color: var(--muted); font-size: .8125rem; }

.input-wrap { position: relative; }

.input-wrap input {
  width: 100%;
  height: 44px;
  padding: 0 40px 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--field);
  font-size: 1.0625rem;
  font-variant-numeric: tabular-nums;
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
.input-wrap input::placeholder { color: var(--muted); opacity: .7; }
.input-wrap input:hover { border-color: var(--muted); }
.input-wrap input:focus { outline: none; background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.input-wrap input[aria-invalid="true"] { border-color: var(--loss); }

.suffix {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.field-target { margin-top: 10px; }
.field-target .input-wrap input { height: 50px; font-size: 1.3125rem; font-weight: 600; background: var(--surface); }

.hint { color: var(--ink-2); font-size: .8125rem; }

.field-error { color: var(--loss); font-size: .8125rem; font-weight: 600; }
.field-error:empty { display: none; }

.form-error {
  padding: 10px 14px;
  border-radius: var(--radius-s);
  background: color-mix(in srgb, var(--loss) 10%, var(--surface));
  color: var(--loss);
  font-weight: 600;
}

/* Segmentli seçim */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  padding: 3px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ink) 7%, var(--surface));
}
.segmented-4 { grid-template-columns: repeat(4, 1fr); grid-auto-flow: row; }

.segment { position: relative; display: block; cursor: pointer; }
.segment input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segment span {
  display: grid;
  place-content: center;
  min-height: 38px;
  padding: 6px 8px;
  border-radius: 7px;
  text-align: center;
  font-size: .875rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--ink-2);
  transition: background-color .15s, color .15s;
}
.segment small { display: block; font-weight: 400; font-size: .75rem; color: var(--muted); }
.segment:hover span { color: var(--ink); }
.segment input:checked + span {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(22, 32, 44, .14), 0 0 0 1px var(--line);
}
.segment input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

/* Hesap türü: seçili olan dolu mavi */
.group-mode .segment input:checked + span {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 2px 6px -2px color-mix(in srgb, var(--accent) 70%, transparent);
}

/* Kartlardaki seçili segment, kartın rengini taşır */
.card .segment input:checked + span { box-shadow: inset 0 -2px 0 var(--tone), 0 1px 2px rgba(22, 32, 44, .14), 0 0 0 1px var(--line); }

/* KDV dahil / hariç küçük anahtar */
.mini-toggle {
  display: inline-flex;
  padding: 2px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 7%, var(--surface));
}
.mini-toggle label { position: relative; cursor: pointer; }
.mini-toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.mini-toggle span {
  display: block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  color: var(--ink-2);
  white-space: nowrap;
}
.mini-toggle input:checked + span { background: var(--tone, var(--accent)); color: #fff; }
.mini-toggle input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

.form-actions { display: flex; align-items: center; gap: 20px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 22px;
  border: 0;
  border-radius: var(--radius-s);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.button:hover { background: var(--accent-hover); }

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: .875rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link-button:hover { color: var(--ink); }

/* JS açıkken hesap yazdıkça yapılır, buton gereksiz */
.js .form-actions { display: none; }

/* ---------- Fiş ---------- */

.receipt {
  position: sticky;
  top: 16px;
  padding: 20px 22px 30px;
  background: var(--surface);
  border-radius: var(--radius-m) var(--radius-m) 0 0;
  box-shadow: var(--shadow);
  /* Fişin alt kenarı yırtık kâğıt gibi dişli */
  --tooth: 9px;
  -webkit-mask:
    linear-gradient(#000 0 0) top / 100% calc(100% - var(--tooth)) no-repeat,
    conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) bottom / calc(var(--tooth) * 2) var(--tooth) repeat-x;
  mask:
    linear-gradient(#000 0 0) top / 100% calc(100% - var(--tooth)) no-repeat,
    conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) bottom / calc(var(--tooth) * 2) var(--tooth) repeat-x;
}

.receipt-empty { display: none; padding: 40px 8px; color: var(--ink-2); text-align: center; }
.receipt[data-state="empty"] .receipt-empty { display: block; }
.receipt[data-state="empty"] .receipt-body { display: none; }
.receipt[data-state="error"] .receipt-body { opacity: .35; }

.hero {
  margin: -20px -22px 0;
  padding: 14px 22px 12px;
  background: var(--accent-soft);
  border-bottom: 1px dashed var(--line-strong);
}

.hero-label { color: var(--ink-2); font-weight: 600; font-size: .9375rem; }

.hero-value {
  font-size: clamp(2.5rem, 2rem + 1.5vw, 3rem);
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--accent);
  overflow-wrap: anywhere;
}
.receipt[data-reverse="true"] .hero-value { color: var(--gain); }
.hero-value[data-sign="negative"], .receipt[data-reverse="true"] .hero-value[data-sign="negative"] { color: var(--loss); }

.hero-sub {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-top: 6px;
  color: var(--ink-2);
}
.hero-sub strong { color: var(--gain); font-size: 1.1875rem; font-weight: 700; }
.receipt[data-reverse="true"] .hero-sub strong { color: var(--ink); }
.hero-sub[data-sign="negative"] strong { color: var(--loss); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line-strong);
}
.stats div { min-width: 0; }
.stats dt { color: var(--muted); font-size: .75rem; }
.stats dd { margin: 1px 0 0; font-weight: 600; font-size: 1rem; white-space: nowrap; }

.split { padding-top: 10px; }
.split-title { font-weight: 600; font-size: .9375rem; margin-bottom: 8px; }

.bar {
  display: flex;
  gap: 2px;
  height: 10px;
  margin-bottom: 8px;
}
.bar-seg {
  flex-basis: 0;
  min-width: 0;
  height: 100%;
  border-radius: 999px;
  transition: flex-grow .35s ease, opacity .15s;
}
.bar-seg[hidden] { display: none; }

.lines { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .9375rem; }
.lines th { text-align: left; font-weight: 400; }
.lines th, .lines td { padding: 3px 0; vertical-align: baseline; }
.lines tbody tr + tr th, .lines tbody tr + tr td { border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.lines .share { width: 56px; padding-right: 10px; text-align: right; color: var(--muted); font-size: .8125rem; }
.lines .amount { width: 1%; text-align: right; white-space: nowrap; font-weight: 600; }
.lines tr[data-sign="negative"] .amount { color: var(--loss); }
.lines tr[data-line="profit"]:not([data-sign="negative"]) .amount { color: var(--gain); }
.lines tr[data-zero="true"] { color: var(--muted); }
.lines tr[data-zero="true"] .amount { font-weight: 400; }
.lines tbody tr { transition: background-color .15s; }
.lines tbody tr.is-hot { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.lines tfoot th, .lines tfoot td {
  padding-top: 8px;
  border-top: 2px solid var(--ink);
  font-weight: 700;
  font-size: 1rem;
}

.swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 9px;
  border-radius: 3px;
  vertical-align: 0;
}

.bar.has-hot .bar-seg:not(.is-hot) { opacity: .3; }

.slot-1 { background: var(--slot-1); } .slot-2 { background: var(--slot-2); }
.slot-3 { background: var(--slot-3); } .slot-4 { background: var(--slot-4); }
.slot-5 { background: var(--slot-5); } .slot-6 { background: var(--slot-6); }
.slot-7 { background: var(--slot-7); } .slot-8 { background: var(--slot-8); }

.kdv { margin-top: 12px; border-top: 1px dashed var(--line-strong); padding-top: 10px; }
.kdv summary {
  cursor: pointer;
  font-weight: 600;
  font-size: .875rem;
  color: var(--ink-2);
  list-style-position: inside;
}
.kdv summary:hover { color: var(--ink); }
.kdv-table { width: 100%; margin-top: 8px; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .875rem; }
.kdv-table th { text-align: left; font-weight: 400; color: var(--ink-2); padding: 3px 0; }
.kdv-table td { text-align: right; padding: 3px 0; white-space: nowrap; }
.kdv-table tfoot th, .kdv-table tfoot td { padding-top: 6px; border-top: 1px solid var(--line-strong); font-weight: 700; color: var(--ink); }
.note { margin-top: 6px; font-size: .75rem; color: var(--muted); }

.footnote { margin-top: 10px; font-size: .75rem; color: var(--muted); }

/* ---------- Mobil alt çubuk ---------- */

.dock {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: var(--radius-m);
  background: var(--band);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, .45);
  transition: transform .2s ease, opacity .2s;
}
.dock[data-hidden="true"] { transform: translateY(140%); opacity: 0; pointer-events: none; }
.dock-item { display: grid; min-width: 0; font-size: .75rem; color: var(--band-ink-2); }
.dock-item strong { color: #fff; font-size: 1.0625rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dock-item[data-sign="negative"] strong { color: #ffb3ad; }
.dock-link { font-size: .875rem; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Hata sayfası ---------- */

.error-page { max-width: 520px; margin: 18vh auto 0; padding: 0 24px; display: grid; gap: 16px; justify-items: start; }
.error-page h1 { font-size: 2rem; letter-spacing: -0.02em; color: var(--band-ink); }
.error-page p { color: var(--ink-2); }

/* ---------- Duyarlı ---------- */

@media (max-width: 1000px) {
  .workspace { grid-template-columns: 1fr; }
  .receipt { position: static; }
  .page { padding-bottom: 110px; }
}

@media (min-width: 1001px) { .dock { display: none; } }

@media (max-width: 640px) {
  .page { padding: 18px 12px 110px; }
  body { background: linear-gradient(var(--band), var(--band)) top / 100% 190px no-repeat, var(--bg); }
  .group-grid { grid-template-columns: 1fr; }
  .group { padding: 14px 14px 16px; }
  .segmented-4 { grid-template-columns: 1fr 1fr; }
  .receipt { padding: 20px 16px 28px; }
  .hero { margin: -20px -16px 0; padding: 16px 16px 12px; }
}

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

@media (forced-colors: active) {
  .bar-seg, .swatch { forced-color-adjust: none; border: 1px solid CanvasText; }
}

@media print {
  body { background: #fff; }
  .calculator, .masthead .theme-toggle, .dock { display: none; }
  .masthead { color: #000; }
  .workspace { display: block; }
  .receipt { box-shadow: none; -webkit-mask: none; mask: none; position: static; }
}
