/* Libera — müşteri ve iş takibi */

@font-face { font-family: "Archivo"; src: url("/assets/fonts/Archivo-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Archivo"; src: url("/assets/fonts/Archivo-Medium.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Archivo"; src: url("/assets/fonts/Archivo-ExtraBold.woff2") format("woff2"); font-weight: 800; font-style: normal; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url("/assets/fonts/SourceSerif4-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }

:root {
  --ink: #192744;
  --ink-soft: #33415f;
  --muted: #5c6070;
  --paper: #fbf6eb;
  --card: #fffaf1;
  --line: #d9d3c4;
  --line-soft: #e8e2d4;
  --clay: #a94e36;
  --clay-dark: #8b3e2b;
  --clay-wash: #f6e4da;
  --wait: #3f5a7a;
  --wait-wash: #e6edf3;
  --ok: #2f5d46;
  --sans: "Archivo", "Helvetica Neue", Arial, system-ui, sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --r: 8px;
  --tap: 44px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 var(--sans);
  min-height: 100dvh;
}

h1, h2, h3 { margin: 0; line-height: 1.15; }
h1 { font-weight: 800; font-size: 1.6rem; letter-spacing: -0.02em; }
h2 { font-weight: 800; font-size: 1.35rem; letter-spacing: -0.01em; }
h3 { font-weight: 500; font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
p { margin: 0; }
a { color: var(--ink); text-underline-offset: 3px; }
small { font-size: 0.85em; color: var(--muted); font-weight: 400; }

:focus-visible { outline: 3px solid var(--clay); outline-offset: 2px; border-radius: 4px; }
h1:focus, h2:focus, main:focus { outline: none; }
h1:focus-visible, h2:focus-visible { outline: 3px solid var(--clay); }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; background: var(--ink); color: var(--paper); padding: 8px 12px; z-index: 20; border-radius: var(--r); }
.skip:focus { top: 8px; }

/* ---------- Düğmeler ve alanlar ---------- */

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: progress; opacity: 0.6; }

.primary, .quiet, .mini {
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: var(--r);
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}
.primary { background: var(--ink); color: var(--paper); }
.primary:hover { background: var(--ink-soft); }
.quiet { background: var(--card); border-color: var(--line); }
.quiet:hover { border-color: var(--ink); }
.mini { min-height: 36px; padding: 0 12px; font-size: 0.9rem; background: transparent; border-color: var(--line); }
.mini:hover { border-color: var(--ink); background: var(--card); }
.block { width: 100%; }
.link { background: none; border: 0; padding: 4px 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; font-weight: 500; min-height: 32px; text-align: left; }
.link:hover { color: var(--clay-dark); }

.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.field { display: grid; gap: 6px; margin: 0 0 14px; }
.field > span, .field > label, fieldset legend { font-weight: 500; font-size: 0.95rem; }
input[type=text], input[type=search], input[type=date], input[type=password], input:not([type]), select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* iOS yakınlaştırmasını önler */
}
textarea { resize: vertical; min-height: 96px; line-height: 1.45; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--clay); outline-offset: 0; border-color: var(--ink); border-radius: var(--r); }
[aria-invalid="true"] { border-color: var(--clay-dark) !important; box-shadow: inset 0 0 0 1px var(--clay-dark); }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.sub { border-left: 3px solid var(--line); padding: 4px 0 2px 14px; margin: 0 0 14px; }
.kind { display: flex; gap: 18px; margin: 0 0 14px; flex-wrap: wrap; }
.kind legend { margin-bottom: 6px; }
.kind label, .check { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); font-weight: 500; }
.check { margin: 0 0 10px; }
input[type=radio], input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--ink); margin: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.two .field { margin-bottom: 14px; }

.error { color: var(--clay-dark); font-weight: 500; margin: 0 0 12px; }
.error:empty { display: none; }
.hint, .notice { color: var(--muted); margin: 0 0 14px; }
.notice { background: var(--wait-wash); color: var(--ink); padding: 10px 12px; border-radius: var(--r); }

/* ---------- Üst bar ---------- */

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 20px;
  padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; min-height: var(--tap); }
.brand img { height: 30px; width: auto; display: block; }
.tabs { display: flex; gap: 4px; }
.tabs a {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap); padding: 0 12px;
  text-decoration: none; font-weight: 500; color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--clay); }
.count:not(:empty) { background: var(--clay); color: var(--card); border-radius: 999px; font-size: 0.78rem; padding: 1px 7px; line-height: 1.4; }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.95rem; }

/* ---------- Ana alan ---------- */

main { max-width: 1160px; margin: 0 auto; padding: 24px 20px 48px; }
.boot { padding: 48px 0; color: var(--muted); display: grid; gap: 12px; justify-items: start; }

.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.search { display: block; margin-bottom: 12px; }
.search input { background: var(--card); }

.empty { color: var(--muted); padding: 8px 0; }
.empty p { margin-bottom: 10px; }

.meta { color: var(--muted); font-size: 0.9rem; }

/* CRM: liste + ayrıntı */
.crm { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 32px; align-items: start; }

.customers { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line-soft); }
.cust-row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line-soft); }
.cust { flex: 1; min-width: 0; display: grid; gap: 1px; padding: 10px 8px; text-decoration: none; border-radius: var(--r); }
.cust:hover { background: var(--card); }
.cust[aria-current="true"] { background: var(--card); box-shadow: inset 3px 0 0 var(--clay); }
.cust-name { font-weight: 500; overflow-wrap: anywhere; }
.cust .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.customers .empty { border: 0; padding: 16px 0; }

.detail-pane { min-width: 0; }
.pane-empty { color: var(--muted); padding: 40px 0; display: grid; gap: 10px; justify-items: start; }
.back { display: none; min-height: var(--tap); align-items: center; text-decoration: none; font-weight: 500; color: var(--muted); }
.cust-head { margin-bottom: 14px; }
.cust-head h2 { font-size: 1.7rem; overflow-wrap: anywhere; }
.cust-head .meta { margin-top: 4px; font-size: 1rem; overflow-wrap: anywhere; }

.block { margin-top: 28px; }
.block > h3, .block > summary { margin-bottom: 8px; }
.block .n { color: var(--ink); }
details.block > summary { cursor: pointer; font-weight: 500; font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); min-height: var(--tap); display: flex; align-items: center; }

/* Görev satırı */
.tasks-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.task {
  width: 100%; text-align: left;
  display: grid; gap: 2px;
  padding: 10px 14px; min-height: 56px;
  background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r);
}
.task:hover { border-color: var(--ink); }
.task-title { font-weight: 500; overflow-wrap: anywhere; }
.task .meta { overflow-wrap: anywhere; }
.due { font-size: 0.9rem; font-weight: 500; color: var(--ink-soft); }
.due.late { color: var(--clay-dark); }
.due.today { color: var(--ink); }
.due.wait { color: var(--wait); font-weight: 400; }
.due.done { color: var(--ok); font-weight: 400; }
.task-done .task-title { color: var(--muted); }
.task:has(.due.late) { box-shadow: inset 3px 0 0 var(--clay); }
.task-waiting:has(.due.wait) { background: var(--paper); border-style: dashed; }

/* Satışlar */
.deals { list-style: none; margin: 0; padding: 0; }
.deal { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.deal-title { font-weight: 500; margin-right: 8px; overflow-wrap: anywhere; }
.deal-won .meta { color: var(--ok); }
.deal-lost .deal-title { color: var(--muted); }

/* Geçmiş */
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.ev { position: relative; padding: 4px 0 18px 18px; }
.ev::before { content: ""; position: absolute; left: -6px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--paper); border: 2px solid var(--ink); }
.ev-done::before { background: var(--ok); border-color: var(--ok); }
.when { color: var(--muted); font-size: 0.88rem; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; margin-bottom: 4px; }
.tag { background: var(--clay-wash); color: var(--clay-dark); border-radius: 999px; padding: 0 8px; font-size: 0.8rem; font-weight: 500; }
.note-body { font-family: var(--serif); font-size: 1.08rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 68ch; }
.result { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink-soft); }
.linked { list-style: none; margin: 6px 0 0; padding: 0; }
.ev.flash { animation: flash 2.4s ease-out; }
@keyframes flash { from { background: var(--clay-wash); } to { background: transparent; } }

/* Görevler ekranı */
.tasks { max-width: 760px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--card); }
.seg button { min-height: var(--tap); padding: 0 20px; border: 0; background: transparent; font-weight: 500; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.seg button:focus-visible { outline-offset: -3px; }

/* ---------- Diyaloglar ---------- */

dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0; border: 0; border-radius: 12px;
  background: var(--card); color: var(--ink);
  box-shadow: 0 20px 60px rgb(25 39 68 / 0.25);
  overflow: auto;
  overscroll-behavior: contain;
}
dialog::backdrop { background: rgb(25 39 68 / 0.45); }
dialog form { margin: 0; }
.dlg-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 20px 12px; background: var(--card); border-bottom: 1px solid var(--line-soft);
}
.dlg-head h2 { padding-top: 8px; overflow-wrap: anywhere; }
.x { flex: none; width: var(--tap); height: var(--tap); border: 0; background: transparent; font-size: 1.6rem; line-height: 1; border-radius: var(--r); color: var(--muted); }
.x:hover { background: var(--paper); color: var(--ink); }
.dlg-body { padding: 16px 20px 8px; }
.dlg-foot {
  position: sticky; bottom: 0;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line-soft);
}
.dlg-foot .primary:only-child { margin-left: auto; }

/* Müşteri seçici */
.picker > label { font-weight: 500; font-size: 0.95rem; }
.chip { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); padding: 6px 12px; background: #fff; border: 1px solid var(--ink); border-radius: var(--r); }
.chip span { overflow-wrap: anywhere; }
.matches { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.matches:empty { display: none; }
.match { width: 100%; text-align: left; min-height: var(--tap); padding: 8px 12px; background: var(--paper); border: 1px solid var(--line-soft); border-radius: var(--r); overflow-wrap: anywhere; }
.match span { color: var(--muted); }
.match:hover { border-color: var(--ink); }
.match.new { background: transparent; border-style: dashed; border-color: var(--line); font-weight: 500; }
.match-note { color: var(--muted); font-size: 0.9rem; padding: 4px 0; }
.newbox { margin-top: 10px; }
.newbox legend { color: var(--clay-dark); margin-bottom: 4px; }
.similar:empty { display: none; }
.similar { margin: -4px 0 14px; }
.similar a { display: block; padding: 6px 0; }

/* Görev ayrıntısı */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0 0 16px; }
.facts dt { color: var(--muted); font-size: 0.92rem; }
.facts dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.badge { display: inline-block; border-radius: 999px; padding: 0 10px; font-size: 0.85rem; font-weight: 500; background: var(--paper); border: 1px solid var(--line); }
.st-waiting { background: var(--wait-wash); border-color: transparent; color: var(--wait); }
.st-done { background: #e5efe8; border-color: transparent; color: var(--ok); }
.origin { margin: 0 0 18px; padding: 12px 14px; background: var(--paper); border-radius: var(--r); border-left: 3px solid var(--clay); }
.origin figcaption { color: var(--muted); font-size: 0.88rem; margin-bottom: 4px; }
.origin blockquote { margin: 0 0 6px; }
.conflict { background: var(--clay-wash); border-radius: var(--r); padding: 12px 14px; margin: 0 0 16px; display: grid; gap: 10px; justify-items: start; }
.block-form, .status-actions { border-top: 1px solid var(--line-soft); padding: 14px 0 6px; }
.block-form h3, .status-actions h3 { margin-bottom: 10px; }
.status-actions .error { margin-top: 8px; }
#taskDone, #taskWait { border-top: 0; padding-top: 4px; }

/* Giriş */
.login { width: min(400px, calc(100vw - 32px)); }
.login form { padding: 28px 24px 24px; }
.login-logo { height: 40px; width: auto; display: block; margin-bottom: 18px; }
.login h2 { margin-bottom: 16px; }
.login::backdrop { background: var(--paper); }

/* Bildirim */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30;
  max-width: min(520px, calc(100vw - 32px));
  background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: var(--r);
  box-shadow: 0 8px 24px rgb(25 39 68 / 0.25);
}
.toast:empty { padding: 0; box-shadow: none; }
.toast.err { background: var(--clay-dark); }

.dock { display: none; }

/* ---------- Telefon ---------- */

@media (max-width: 899px) {
  .crm { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .crm.has-detail .list-pane { display: none; }
  .crm:not(.has-detail) .detail-pane { display: none; }
  .back { display: inline-flex; }
}

@media (max-width: 640px) {
  body { font-size: 16px; }
  main { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
  .top { gap: 8px; padding-top: 4px; padding-bottom: 4px; flex-wrap: wrap; }
  .brand img { height: 24px; }
  .tabs { order: 3; width: 100%; }
  .tabs a { flex: 1; justify-content: center; }
  .who { font-size: 0.9rem; }
  h1 { font-size: 1.4rem; }
  .cust-head h2 { font-size: 1.45rem; }
  .wide-only { display: none; }
  .dock {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: var(--paper); border-top: 1px solid var(--line);
  }
  .dock .primary { width: 100%; min-height: 48px; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .two { grid-template-columns: 1fr; gap: 0; }
  .row-actions > .primary, .row-actions > .quiet { flex: 1 1 auto; }
  .pane-head .row-actions { flex: 0 0 auto; }

  dialog:not(.login) {
    width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh;
    margin: 0; border-radius: 0;
  }
  dialog:not(.login) > form { min-height: 100%; display: flex; flex-direction: column; }
  dialog:not(.login) .dlg-body { flex: 1; }
  .dlg-head, .dlg-body, .dlg-foot { padding-left: 16px; padding-right: 16px; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .ev.flash { animation: none; background: var(--clay-wash); }
}
