:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --border: #e3e0d9;
  --brand: #1f3a5f;
  --brand-contrast: #ffffff;
  --ok: #1e7a46;      --ok-bg: #e3f3e9;
  --warn: #8a5a00;    --warn-bg: #fdf0d5;
  --err: #b42318;     --err-bg: #fde8e6;
  --info: #1f4f8f;    --info-bg: #e3edf9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 1px rgba(0,0,0,.03);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413; --surface: #1e1e1c; --surface-2: #262624; --text: #ecebe7; --muted: #a09e98;
    --border: #34332f; --brand: #8fb3e6; --brand-contrast: #10161f;
    --ok: #6fd39b; --ok-bg: #173826; --warn: #f0c060; --warn-bg: #3b2e10;
    --err: #ff8a80; --err-bg: #42201d; --info: #9cc3ff; --info-bg: #1b2c45;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; line-height: 1.2; }
h2 { font-size: 15px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; justify-content: space-between; align-items: baseline; }
h2 .more { text-transform: none; letter-spacing: 0; font-weight: 500; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 13px; }
.err-text { color: var(--err); }

main { max-width: 1080px; margin: 0 auto; padding: 16px; }
main.center { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
section { margin: 22px 0; }

/* --- üst bar / navigasyon --- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-contrast);
}
.brand { color: var(--brand-contrast); font-weight: 700; font-size: 17px; }
.brand span { font-weight: 400; opacity: .75; }
.topnav { display: none; gap: 4px; flex: 1; }
.topnav a { color: var(--brand-contrast); opacity: .8; padding: 6px 10px; border-radius: 8px; }
.topnav a.active, .topnav a:hover { opacity: 1; background: rgba(255,255,255,.14); text-decoration: none; }
.logout { margin-left: auto; }
button.link { background: none; border: 0; color: var(--brand-contrast); opacity: .8; font: inherit; cursor: pointer; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; font-size: 11px; color: var(--muted);
}
.bottomnav a.active { color: var(--brand); }
.bottomnav a:hover { text-decoration: none; }
.bottomnav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bottomnav .badge { position: absolute; top: 3px; left: calc(50% + 6px); }

@media (min-width: 820px) {
  .topnav { display: flex; }
  .bottomnav { display: none; }
  body { padding-bottom: 24px; }
  main { padding: 24px; }
}

.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; line-height: 18px; text-align: center; font-weight: 700; }
.badge.warn { background: #f5b83d; color: #3a2700; }
.badge.err { background: #e5484d; color: #fff; }
.badge.info { background: #5b8def; color: #fff; }

/* --- genel bileşenler --- */
.pagehead { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 0 14px; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 6px; font-size: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.grid2 { display: grid; gap: 14px; }
.grid2 > .card { margin: 0; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 1fr; align-items: start; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.small { min-height: 34px; padding: 5px 11px; font-size: 14px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.btn.ok { color: var(--ok); border-color: var(--ok); }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--border)); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.actions form { margin: 0; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.err { background: var(--err-bg); color: var(--err); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.muted { background: var(--surface-2); color: var(--muted); }

.flash, .banner { padding: 10px 14px; border-radius: 10px; margin: 0 0 12px; background: var(--ok-bg); color: var(--ok); }
.flash.err, .banner.err { background: var(--err-bg); color: var(--err); }
.banner.info { background: var(--info-bg); color: var(--info); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner a { color: inherit; text-decoration: underline; }

.health { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin: 0 0 14px; }
.health .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.health.err .dot { background: var(--err); }

/* --- istatistik kartları --- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 820px) { .stats { grid-template-columns: repeat(5, 1fr); } }
.stat { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; color: var(--text); box-shadow: var(--shadow); }
a.stat:hover { text-decoration: none; border-color: var(--brand); }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 28px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--muted); }
.stat.warn { background: var(--warn-bg); } .stat.err { background: var(--err-bg); } .stat.info { background: var(--info-bg); }

/* --- liste satırları --- */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.row { display: flex; gap: 12px; justify-content: space-between; padding: 12px 14px; border-top: 1px solid var(--border); color: var(--text); }
.list > .row:first-child { border-top: 0; }
a.row:hover { background: var(--surface-2); text-decoration: none; }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.reason { padding: 0 14px 12px; font-size: 13px; color: var(--err); }
.empty { color: var(--muted); padding: 24px; text-align: center; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* --- filtreler / formlar --- */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.filters input[type=search] { grid-column: 1 / -1; }
.filters .btn { grid-column: 1 / -1; }
@media (min-width: 820px) { .filters { grid-template-columns: 2fr 1fr 1fr auto; } .filters input[type=search], .filters .btn { grid-column: auto; } }
input, select, textarea {
  width: 100%; min-height: 42px; padding: 8px 11px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; /* iOS zoom'u engeller */
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
.form label, .login label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.form label input, .form label select, .login label input { margin-top: 4px; color: var(--text); }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label.check { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--text); padding: 10px 0; border-bottom: 1px solid var(--border); margin: 0; }
label.check input { width: 20px; height: 20px; min-height: 0; flex: none; }
label.check.danger-check { color: var(--err); font-weight: 600; }
.form .btn.block { margin-top: 14px; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; }
.inline-form input { flex: 1; }
.login { width: 100%; max-width: 360px; }
.login h1 { margin-bottom: 18px; }

/* --- detay --- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0 0 14px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; word-break: break-word; }
.items { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.items td { padding: 8px 0; border-top: 1px solid var(--border); vertical-align: top; }
.items .num { text-align: right; white-space: nowrap; padding-left: 12px; font-variant-numeric: tabular-nums; }
.items tr.sub td { color: var(--muted); }
.items tr.total td { font-weight: 700; border-top: 2px solid var(--text); }
.mail { border-top: 1px solid var(--border); padding: 10px 0; }
.mail:first-child { border-top: 0; padding-top: 0; }
.mail-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
pre.mailbody { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); padding: 12px; border-radius: 8px; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; max-height: 520px; overflow: auto; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 14px; border-left: 2px solid var(--border); font-size: 14px; }
.raw summary { font-weight: 600; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 14px 0; }

/* --- mail metni düzenleme --- */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }
textarea.mono { line-height: 1.5; resize: vertical; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 999px;
        padding: 4px 10px; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; cursor: pointer; }
.chip:hover { border-color: var(--brand); }
.flash ul { margin: 6px 0 0; padding-left: 20px; }
.settings-links { display: grid; gap: 10px; margin-bottom: 14px; }
.settings-links a { display: flex; justify-content: space-between; align-items: center; }
.preview pre.mailbody { max-height: none; }

/* --- çalışma modu --- */
.banner.good { background: var(--ok-bg); color: var(--ok); }
.mode-banner { font-size: 14px; }
fieldset.modes { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px 4px; margin: 0 0 14px; }
fieldset.modes legend { font-size: 13px; color: var(--muted); padding: 0 6px; }
.mode-option { display: flex; gap: 10px; align-items: flex-start; padding: 10px 6px; border-radius: 8px; cursor: pointer; }
.mode-option + .mode-option { border-top: 1px solid var(--border); }
.mode-option.selected { background: var(--surface-2); }
.mode-option input { width: 20px; height: 20px; min-height: 0; flex: none; margin-top: 2px; }

.legal h2 { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 16px; margin-top: 18px; }
.legal p, .legal li { line-height: 1.6; }

/* --- mail önizlemesi (müşteride görüneceği gibi, kalın yazılarla) --- */
.mailbody.mailhtml { white-space: normal; font: 14px/1.55 Arial, Helvetica, sans-serif; color: var(--text);
  background: var(--surface-2); padding: 14px 16px; border-radius: 8px; max-height: 620px; overflow: auto; }
.preview .mailbody.mailhtml { max-height: none; }
.mailbody.mailhtml b { font-weight: 700; }
