:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --surface-2: #f3ece2;
  --line: #e4d9ca;
  --text: #2a2622;
  --muted: #6b6259;
  --accent: #0f5e5a;
  --accent-2: #0b4744;
  --accent-soft: #dcefec;
  --pos: #1d6b3a;
  --neg: #a2332a;
  --warn-bg: #fff1d6;
  --warn: #7a4b00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
  --nav-row: 64px;
  --nav-h: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.mt { margin-top: 1rem; }
.scope-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: .75rem; margin-bottom: .75rem; }
.import-scope { border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .8rem; overflow-wrap: anywhere; min-width: 0; }
.import-scope h3 { margin-bottom: .25rem; }
.scope-file { background: var(--surface-2); border-style: dashed; }
.scope-import { background: var(--accent-soft); border-color: var(--accent); }
.scope-dl { display: grid; grid-template-columns: auto 1fr; gap: .15rem .75rem; margin: 0; font-size: .875rem; }
.scope-dl dt { color: var(--muted); }
.scope-dl dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.scope-dl .nowrap { white-space: nowrap; }
.scope-dl dd { min-width: 0; overflow-wrap: anywhere; }
/* Etsy variant links: long normalized keys wrap instead of widening the table/dialog */
.vl-key { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; overflow-wrap: anywhere; word-break: break-word; }
.vl-actions { flex-direction: column; align-items: stretch; }
.vl-table td { overflow-wrap: anywhere; }
.vl-table .vl-actions .btn { white-space: nowrap; }
/* Read-only Etsy reconciliation: three separate source blocks; tables scroll inside their own box */
.recon-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; margin-top: 1rem; }
.recon-grid > section { min-width: 0; }
.recon-warn { margin: .5rem 0 0; padding-left: 1.1rem; overflow-wrap: anywhere; }
.recon-warn li { margin-bottom: .35rem; }
.recon-status { min-width: 0; overflow-wrap: anywhere; }
/* Per-order Etsy fee match: wide table scrolls inside .table-wrap; warnings fold into <details> on phones */
.order-fees { min-width: 0; margin-top: 1.25rem; overflow-wrap: anywhere; }
.order-fees h4 { margin: 1rem 0 .4rem; }
/* The section's overflow-wrap: anywhere (kept for notices/warnings) let every table cell shrink to one character, so the
   10-column order table squeezed into the content width instead of scrolling. Inside tables, wrap only at normal break
   points (break-word still splits an overlong SKU/name as a last resort); the order table gets a dedicated minimum width
   and scrolls inside .table-wrap on desktop and phones without widening the page. */
.order-fees .table-wrap > table { overflow-wrap: break-word; }
.order-fees .table-wrap > table.of-orders { min-width: 1200px; }
.of-orders td:first-child { white-space: nowrap; }
.of-orders td:nth-child(2) { min-width: 14rem; }
.of-products { margin: .25rem 0 0; padding-left: 1rem; }
/* Direct cost + contribution columns: fixed readable width, amounts right-aligned, item lists/notes wrap inside the cell
   (never nowrap like .num) so the 12-column table keeps its 1200px minimum and only scrolls inside .table-wrap. */
.of-orders td.of-cost, .of-orders td.of-contrib { min-width: 13rem; max-width: 20rem; text-align: right; font-variant-numeric: tabular-nums; }
.of-orders th.of-cost, .of-orders th.of-contrib { min-width: 13rem; }
.of-dc { text-align: left; margin-top: .25rem; }
.of-dc-items { margin: .25rem 0 .35rem; padding-left: 1rem; text-align: left; overflow-wrap: anywhere; }
.of-dc-items li { margin-bottom: .3rem; }
.of-calc { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .1rem .5rem; margin: .25rem 0 0; }
.of-calc dt { color: var(--muted); overflow-wrap: anywhere; }
.of-calc dd { margin: 0; text-align: right; white-space: nowrap; }
.of-dc-actions { display: flex; flex-wrap: wrap; gap: .25rem; justify-content: flex-end; margin-top: .35rem; }
.of-dc-head { margin: .5rem 0; }
.of-dc-history .item { overflow-wrap: anywhere; }
/* Katalog › Etsy yükleme paketleri: long English text, SKUs and planned filenames wrap inside the card/dialog; the variant
   and image-plan tables keep a readable minimum and scroll inside their own .table-wrap on phones (never widen the page). */
.up-pkg { min-width: 0; overflow-wrap: anywhere; }
.up-pkg .table-wrap > table.up-table { min-width: 640px; overflow-wrap: break-word; }
.up-text { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.up-tags { display: flex; flex-wrap: wrap; gap: .35rem; margin: .25rem 0 .5rem; padding-left: 0; list-style: none; counter-reset: up-tag; }
.up-tags li { counter-increment: up-tag; background: var(--surface-2); border-radius: 999px; padding: 2px 10px; font-size: .85rem; overflow-wrap: anywhere; max-width: 100%; }
.up-tags li::before { content: counter(up-tag) ". "; color: var(--muted); }
.up-tag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 11rem), 1fr)); gap: 0 .75rem; }
.up-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0; }
.up-list .main { flex: 1 1 auto; overflow-wrap: anywhere; }
.up-dl { display: grid; grid-template-columns: minmax(0, 10rem) minmax(0, 1fr); gap: .25rem .75rem; margin: 0; }
.up-dl dt { color: var(--muted); }
.up-dl dd { margin: 0; min-width: 0; }
@media (max-width: 480px) { .up-dl { grid-template-columns: minmax(0, 1fr); } }
.of-warn summary { cursor: pointer; }
.of-warn ul { margin: .25rem 0 0; padding-left: 1rem; min-width: 12rem; }
.scope-warn { background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); padding: .5rem .8rem; margin-bottom: .75rem; font-size: .875rem; overflow-wrap: anywhere; }
.scope-reasons { margin: 0 0 .75rem; padding-left: 1.2rem; }
details summary { cursor: pointer; min-height: 32px; color: var(--accent-2); font-weight: 600; margin-bottom: .5rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

:focus-visible { outline: 3px solid #e2a03f; outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff; padding: .5rem 1rem; z-index: 100; }
.skip:focus { left: .5rem; top: .5rem; }

/* ---------- shell ---------- */
/* minmax(0, 1fr): a plain 1fr track grows to its content's min-content width, so one wide table widened the whole
   page on phones. With a 0 minimum the view stays at the viewport width and wide tables scroll inside .table-wrap. */
.shell { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem 1rem; background: rgba(250, 246, 240, .94); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 1rem; }
.view { padding: 1rem 1rem calc(var(--nav-h) + env(safe-area-inset-bottom) + 2rem); max-width: 1100px; width: 100%; min-width: 0; margin: 0 auto; outline: none; }

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(9, minmax(0, 1fr));
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--nav-row); min-width: 44px; color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 600;
}
.nav a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav .ico { font-size: 1.25rem; line-height: 1; }
@media (max-width: 899px) {
  .nav a { font-size: .66rem; }
  .nav a[aria-current="page"] .ico { padding: 4px 10px; }
}
@media (max-width: 480px) {
  :root { --nav-row: 56px; --nav-h: 168px; }
  .nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.nav a[aria-current="page"] { color: var(--accent); }
.nav a[aria-current="page"] .ico { background: var(--accent-soft); border-radius: 999px; padding: 4px 16px; }

@media (min-width: 900px) {
  .shell { grid-template-columns: 220px minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; }
  .nav {
    position: sticky; top: 57px; align-self: start; height: calc(100vh - 57px);
    display: flex; flex-direction: column; gap: .25rem; padding: 1rem .75rem;
    border-top: 0; border-right: 1px solid var(--line); background: transparent;
  }
  .nav a { flex-direction: row; justify-content: flex-start; gap: .75rem; min-height: 44px; padding: 0 .9rem; border-radius: 10px; font-size: .95rem; }
  .nav a:hover { background: var(--surface-2); color: var(--text); }
  .nav a[aria-current="page"] { background: var(--accent-soft); }
  .nav a[aria-current="page"] .ico { background: none; padding: 0; }
  .nav .ico { width: 1.4rem; text-align: center; }
  .view { padding: 1.5rem 2rem 3rem; }
}

/* ---------- building blocks ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head p { margin: 0; }
.page-head > * { min-width: 0; max-width: 100%; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
/* Dashboard summary cards are <a class="card">: anchors are inline by default, so the card box and its stats grid were not
   constrained to the column width. Make them real blocks that can shrink with the viewport. */
a.card { display: block; min-width: 0; color: inherit; text-decoration: none; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.stats { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); min-width: 0; }
.stat { background: var(--surface-2); border-radius: 10px; padding: .75rem; min-width: 0; overflow-wrap: anywhere; }
.stat .label { display: block; font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat .value { display: block; font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cur-tag { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent); color: #fff; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: 0 1rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-danger { color: var(--neg); }
.btn-sm { min-height: 36px; padding: 0 .7rem; font-size: .875rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-icon { min-width: 40px; min-height: 40px; border: 0; background: transparent; font-size: 1.1rem; cursor: pointer; border-radius: 8px; color: var(--muted); }
.btn-icon:hover { background: var(--surface-2); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-ok { background: #def3e4; color: var(--pos); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-off { background: #eee7df; color: var(--muted); }
.badge-accent { background: var(--accent-soft); color: var(--accent-2); }

.notice { border-radius: 10px; padding: .75rem 1rem; margin-bottom: 1rem; background: var(--warn-bg); color: var(--warn); border: 1px solid #f0d9a8; }
.notice-info { background: var(--accent-soft); color: var(--accent-2); border-color: #bfe0db; }

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty .ico { display: block; font-size: 2rem; margin-bottom: .5rem; color: var(--accent); }
.empty p { max-width: 36ch; margin: 0 auto .75rem; }

/* tabs */
.tabs { display: flex; gap: .25rem; padding: 4px; background: var(--surface-2); border-radius: 12px; margin-bottom: 1rem; overflow-x: auto; }
.tabs button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; padding: 0 .8rem; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

/* tables */
/* position: relative keeps absolutely positioned children (e.g. the .sr "İşlemler" header text) inside the scroll
   area; otherwise they escape to the page root and widen the whole page. */
.table-wrap { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: .6rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
caption { text-align: left; font-weight: 700; padding-bottom: .5rem; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .main { min-width: 0; }
.list .title { font-weight: 600; overflow-wrap: anywhere; }
.list .sub { font-size: .85rem; color: var(--muted); }
/* Social calendar: unbroken hashtags/notes/shop names must wrap instead of overflowing a 390 px screen. */
.social-day .main { flex: 1 1 auto; overflow-wrap: anywhere; }
.social-day h3 { overflow-wrap: anywhere; }

.item { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; padding: .85rem 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item.overdue { border-left: 4px solid var(--warn); padding-left: .6rem; }
dl.small dt { margin-top: .5rem; } dl.small dd { margin: 0; }
.item .main { flex: 1 1 220px; min-width: 0; }
.sku { font-family: ui-monospace, Consolas, monospace; font-size: .82rem; background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }

/* forms */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.field label, .field .lbl { font-weight: 600; font-size: .92rem; }
.field .hint { font-size: .8rem; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: #fff; border: 1px solid #cfc2b1; border-radius: 10px;
  min-height: 44px; padding: .5rem .75rem; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.check { flex-direction: row; align-items: center; gap: .6rem; }
.check input { width: 22px; min-height: 22px; height: 22px; accent-color: var(--accent); }
.production-step { border: 1px solid var(--line); border-radius: 12px; padding: .8rem; margin: 0 0 1rem; }
.phys-facts { list-style: none; margin: .4rem 0; padding: 0; min-width: 0; }
.phys-facts li { margin: .3rem 0; overflow-wrap: anywhere; }
.production-step legend { padding: 0 .35rem; font-weight: 700; color: var(--accent-2); }
.queue-item { align-items: flex-start; flex-wrap: wrap; }
.queue-item .main { min-width: 0; overflow-wrap: anywhere; }
.step-week-list { list-style: none; padding: 0; margin: .4rem 0 0; }
.step-week-row { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; justify-content: space-between; padding: .35rem 0; border-top: 1px solid var(--line); }
.step-week-row .actions, .step-week .actions { display: flex; flex-wrap: wrap; gap: .4rem; }
@media (max-width: 480px) { .step-week-row .btn { flex: 1 1 100%; } }
@media (max-width: 480px) { .queue-item { flex-direction: column; } .queue-item .main { flex: 0 0 auto; } .queue-item .actions, .queue-item .btn { width: 100%; } }
.capacity-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: .6rem; }
.capacity-table { width: 100%; border-collapse: collapse; min-width: 520px; }
.capacity-table th, .capacity-table td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.capacity-table td.num { white-space: nowrap; }
.production-work-step { align-items: flex-start !important; }
.production-work-step.is-done { opacity: .78; }
.production-work-step .actions { flex: 0 1 auto; }
@media (max-width: 480px) {
  .production-work-step { flex-direction: column; }
  .production-work-step .actions, .production-work-step .btn { width: 100%; }
}
.row { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filters .field { margin: 0; flex: 1 1 150px; min-width: 0; }
.filters > .actions { max-width: 100%; }
@media (max-width: 480px) {
  /* Finans date range on phones: date fields stack full width, the three buttons share one row */
  #range .field { flex-basis: 100%; }
  #range > .actions { flex: 1 1 100%; }
  #range > .actions .btn { flex: 1 1 auto; }
}
.form-error { color: var(--neg); background: #fbe9e6; border-radius: 8px; padding: .6rem .8rem; margin: 0 1rem 0; }

/* dialog */
dialog { width: min(560px, calc(100vw - 1.5rem)); max-height: calc(100vh - 2rem); padding: 0; border: 0; border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.25); color: var(--text); background: var(--surface); }
dialog::backdrop { background: rgba(30, 24, 18, .45); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 2rem); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1rem .5rem; }
.dlg-head h2 { margin: 0; }
.dlg-body { padding: .5rem 1rem; overflow-y: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: 1rem; border-top: 1px solid var(--line); }
.dlg-foot.view-only #dlg-submit { display: none; }

/* meters for cost comparison */
.cmp { display: grid; gap: .2rem; }
.cmp meter { width: 100%; height: 10px; }
.cmp .lbl { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); }

/* assistant */
.chat { display: flex; flex-direction: column; gap: .75rem; min-height: 200px; max-height: 55vh; overflow-y: auto; padding: .25rem; }
.msg { max-width: 85%; padding: .7rem .9rem; border-radius: 14px; white-space: pre-line; overflow-wrap: anywhere; }
.msg-user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg-bot { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg .meta { display: block; font-size: .72rem; opacity: .75; margin-bottom: .2rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin: .75rem 0; }
.chip { min-height: 36px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); padding: 0 .9rem; font: inherit; font-size: .88rem; cursor: pointer; color: var(--accent-2); }
.chip:hover { background: var(--accent-soft); }
.ask { display: flex; gap: .5rem; }
.ask input { flex: 1; }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 1rem); transform: translateX(-50%); z-index: 50; pointer-events: none; }
.toast div { background: #2a2622; color: #fff; padding: .7rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow); margin-top: .5rem; max-width: 90vw; }
.toast div.err { background: var(--neg); }
@media (min-width: 900px) { .toast { bottom: 1.5rem; } }

@media (prefers-reduced-motion: no-preference) {
  .btn, .chip, .nav a { transition: background-color .15s ease, color .15s ease; }
}
/* Owner sign-in, available when password protection is enabled. */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card { width: min(100%, 24rem); display: grid; gap: 1rem; padding: 2rem; background: var(--surface, #fff); border: 1px solid #bbc9c6; border-radius: 1rem; }
.auth-card h1, .auth-card p { margin: 0; }
.auth-card input { width: 100%; padding: .8rem; font: inherit; border: 1px solid #718784; border-radius: .5rem; }
