/* Düzen: tam ekran hesap tablosu — üstte şerit + formül çubuğu, ortada ızgara, altta sayfa sekmeleri (Excel gibi). */
:root {
  --bg: #ffffff;
  --chrome: #f3f4f6;
  --chrome-2: #e7e9ec;
  --line: #e1e3e6;
  --line-strong: #c6c9ce;
  --fg: #1d1f22;
  --muted: #6b7078;
  --brand: #1f7244;
  --brand-fg: #ffffff;
  --brand-soft: #e3f1e8;
  --sel: #1f7244;
  --sel-bg: #e6f2ea;
  --hdr-sel: #d3e7da;
  --sec: #eef3f9;
  --sec-fg: #1f3a5f;
  --tot: #f6f7f8;
  --input: #fff4cc;
  --neg: #c0271d;
  --sector: #8a6400;
  --font: "Segoe UI", system-ui, -apple-system, Calibri, Roboto, Arial, sans-serif;
  --num: "Segoe UI", system-ui, -apple-system, Calibri, Roboto, Arial, sans-serif;
  --rowh: 24px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1d20; --chrome: #24272b; --chrome-2: #2d3136; --line: #33373c; --line-strong: #474c53; --fg: #e8eaed;
    --muted: #9aa0a8; --brand: #2f9a5d; --brand-fg: #ffffff; --brand-soft: #1f3a2b; --sel: #4cc38a; --sel-bg: #1f3a2b;
    --hdr-sel: #2a4a37; --sec: #22303f; --sec-fg: #9cc2f0; --tot: #23262a; --input: #3d3416; --neg: #ff8a80; --sector: #e3c060;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1d20; --chrome: #24272b; --chrome-2: #2d3136; --line: #33373c; --line-strong: #474c53; --fg: #e8eaed;
  --muted: #9aa0a8; --brand: #2f9a5d; --brand-fg: #ffffff; --brand-soft: #1f3a2b; --sel: #4cc38a; --sel-bg: #1f3a2b;
  --hdr-sel: #2a4a37; --sec: #22303f; --sec-fg: #9cc2f0; --tot: #23262a; --input: #3d3416; --neg: #ff8a80; --sector: #e3c060;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 13px/1.35 var(--font); overflow: hidden; }
.app { height: 100%; display: grid; grid-template-rows: auto auto auto 1fr auto; }
[hidden] { display: none !important; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--chrome); border-bottom: 1px solid var(--line);
  padding: 6px max(14px, env(safe-area-inset-right, 0px)) 6px max(14px, env(safe-area-inset-left, 0px)); }
.tl { font-weight: 700; }
.toolbar .seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 4px; overflow: hidden; }
.toolbar .seg button { font: inherit; border: 0; background: var(--bg); color: var(--fg); padding: 5px 12px; cursor: pointer; }
.toolbar .seg button + button { border-left: 1px solid var(--line-strong); }
.toolbar .seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-fg); font-weight: 600; }
.toolbar .seg button:focus-visible, .toolbar select:focus-visible { outline: 2px solid var(--sel); outline-offset: 1px; }
.tsel { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.toolbar select { font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line-strong); border-radius: 4px; padding: 4px 6px; }
.tnote { color: var(--muted); font-size: 12px; }
.tnote.busy::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .tnote.busy::before { animation: none; } }
.grid td.input { cursor: cell; }
.grid td.editing { padding: 0; }
.grid td.editing input { width: 100%; height: 100%; border: 2px solid var(--sel); font: inherit; text-align: right; padding: 0 6px;
  background: var(--bg); color: var(--fg); outline: none; }

.ribbon {
  background: var(--brand); color: var(--brand-fg); display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px max(14px, env(safe-area-inset-right, 0px)) 8px max(14px, env(safe-area-inset-left, 0px)); flex-wrap: wrap;
}
.doc { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 28px; height: 28px; border-radius: 4px; background: var(--brand-fg); color: var(--brand); font-weight: 800; display: grid; place-items: center; flex: none; }
.doc-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-sub { font-size: 12px; opacity: 0.85; }
.actions { display: flex; gap: 8px; }
.rb { font: inherit; font-weight: 600; color: var(--brand-fg); background: transparent; border: 1px solid rgba(255,255,255,0.55); border-radius: 4px; padding: 6px 12px; cursor: pointer; text-decoration: none; }
.rb.primary { background: var(--brand-fg); color: var(--brand); border-color: var(--brand-fg); }
.rb:focus-visible { outline: 2px solid var(--brand-fg); outline-offset: 2px; }
.rb:disabled { opacity: 0.6; }

.fbar { display: grid; grid-template-columns: 90px 32px 1fr; border-bottom: 1px solid var(--line-strong); background: var(--chrome); }
.fbar > div { padding: 5px 8px; border-right: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ref { font-weight: 600; }
.fx { color: var(--muted); font-style: italic; text-align: center; }
.fval { border-right: 0; background: var(--bg); font-variant-numeric: tabular-nums; }

.grid-wrap { overflow: auto; position: relative; outline: none; }
.msg { padding: 24px; color: var(--muted); }
table.grid { border-collapse: separate; border-spacing: 0; table-layout: fixed; font-variant-numeric: tabular-nums; }
.grid th, .grid td { height: var(--rowh); padding: 0 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--bg); }
.grid thead th { position: sticky; top: 0; z-index: 3; background: var(--chrome); color: var(--muted); font-weight: 500; text-align: center;
  border-bottom: 1px solid var(--line-strong); }
.grid th.rn { position: sticky; left: 0; z-index: 2; background: var(--chrome); color: var(--muted); font-weight: 400; text-align: center;
  border-right: 1px solid var(--line-strong); width: 46px; min-width: 46px; }
.grid thead th.rn { z-index: 5; }
.grid td.fc { position: sticky; left: 46px; z-index: 1; box-shadow: 1px 0 0 var(--line-strong); }
.grid tr.frz td, .grid tr.frz th.rn { position: sticky; z-index: 2; }
.grid tr.frz td.fc { z-index: 4; }
.grid tr.frz-last td { box-shadow: 0 1px 0 var(--line-strong); }

.grid td.n { text-align: right; }
.grid td.neg { color: var(--neg); }
.grid td.title { font-weight: 700; font-size: 14px; overflow: visible; }
.grid td.hdr { background: var(--chrome-2); font-weight: 600; text-align: center; }
.grid td.hdr.fc { text-align: left; }
.grid td.sec { background: var(--sec); color: var(--sec-fg); font-weight: 700; }
.grid td.tot { background: var(--tot); font-weight: 700; }
.grid td.sub { color: var(--muted); }
.grid td.sub.fc { padding-left: 22px; }
.grid td.base { color: var(--muted); font-style: italic; }
.grid td.sector { color: var(--sector); font-style: italic; }
.grid td.input { background: var(--input); }
.grid td.muted { color: var(--muted); }
.grid td.overflow { overflow: visible; }
.grid td.sel { outline: 2px solid var(--sel); outline-offset: -2px; background: var(--sel-bg); }
.grid th.hsel { background: var(--hdr-sel); color: var(--fg); font-weight: 700; }

.tabs { display: flex; gap: 2px; overflow-x: auto; background: var(--chrome); border-top: 1px solid var(--line-strong);
  padding: 0 max(8px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(8px, env(safe-area-inset-left, 0px)); }
.tabs button { font: inherit; border: 0; background: transparent; color: var(--fg); padding: 7px 14px; cursor: pointer; white-space: nowrap;
  border-bottom: 3px solid transparent; }
.tabs button[aria-selected="true"] { background: var(--bg); color: var(--brand); font-weight: 700; border-bottom-color: var(--brand); }
.tabs button:hover { background: var(--chrome-2); }
.tabs button:focus-visible { outline: 2px solid var(--sel); outline-offset: -2px; }


/* Sohbet balonu ve paneli */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.chat-fab { position: fixed; right: calc(18px + env(safe-area-inset-right, 0px)); bottom: calc(52px + env(safe-area-inset-bottom, 0px)); z-index: 20;
  display: inline-flex; align-items: center; gap: 8px; font: inherit; font-weight: 700; color: var(--brand-fg); background: var(--brand);
  border: 0; border-radius: 999px; padding: 11px 18px; cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,0.25); }
.chat-fab:hover { filter: brightness(1.08); }
.chat-fab:focus-visible { outline: 3px solid var(--sel); outline-offset: 2px; }
.chat { position: fixed; right: calc(18px + env(safe-area-inset-right, 0px)); bottom: calc(52px + env(safe-area-inset-bottom, 0px)); z-index: 21;
  width: min(440px, calc(100vw - 24px)); height: min(680px, calc(100vh - 120px)); display: grid; grid-template-rows: auto 1fr auto auto;
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,0.3); overflow: hidden; }
@media (max-width: 520px) { .chat { right: 12px; left: 12px; width: auto; } }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; background: var(--brand); color: var(--brand-fg); }
.chat-title { font-weight: 700; font-size: 14px; }
.chat-sub { font-size: 11.5px; opacity: 0.85; }
.chat-actions { display: flex; gap: 4px; }
.chat-actions button { font: inherit; color: var(--brand-fg); background: transparent; border: 1px solid rgba(255,255,255,0.5); border-radius: 4px; padding: 3px 9px; cursor: pointer; }
#chat-close { font-size: 18px; line-height: 1; padding: 2px 9px; }
.chat-log { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--chrome); }
.msg-b { max-width: 92%; padding: 9px 12px; border-radius: 12px; line-height: 1.5; font-size: 13.5px; overflow-wrap: anywhere; }
.msg-b.user { align-self: flex-end; background: var(--brand); color: var(--brand-fg); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg-b.bot { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg-b.err { align-self: stretch; background: transparent; color: var(--neg); border: 1px dashed var(--neg); }
.msg-b.bot h3, .msg-b.bot h4 { margin: 8px 0 4px; font-size: 14px; }
.msg-b.bot h3:first-child, .msg-b.bot h4:first-child, .msg-b.bot p:first-child { margin-top: 0; }
.msg-b.bot p { margin: 6px 0; }
.msg-b.bot ul, .msg-b.bot ol { margin: 6px 0; padding-left: 20px; }
.msg-b.bot blockquote { margin: 6px 0; padding: 4px 10px; border-left: 3px solid var(--brand); color: var(--muted); }
.msg-b.bot .tbl { overflow-x: auto; }
.msg-b.bot table { border-collapse: collapse; font-size: 12px; margin: 6px 0; }
.msg-b.bot th, .msg-b.bot td { border: 1px solid var(--line); padding: 3px 6px; text-align: left; white-space: nowrap; }
.msg-b.bot hr { border: 0; border-top: 1px solid var(--line); margin: 8px 0; }
.msg-tools { display: flex; gap: 6px; margin-top: 6px; }
.msg-tools button { font: inherit; font-size: 11.5px; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 4px; padding: 2px 8px; cursor: pointer; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; } .typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; } }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px 0; background: var(--bg); border-top: 1px solid var(--line); }
.chips button { font: inherit; font-size: 12px; color: var(--brand); background: var(--brand-soft); border: 1px solid transparent; border-radius: 999px; padding: 4px 10px; cursor: pointer; }
.chips button:hover { border-color: var(--brand); }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 8px 12px 12px; background: var(--bg); }
.chat-form textarea { font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 9px; resize: none; min-width: 0; }
.chat-form textarea:focus-visible { outline: 2px solid var(--sel); outline-offset: 0; }
.chat-form button { font: inherit; font-weight: 700; color: var(--brand-fg); background: var(--brand); border: 0; border-radius: 8px; padding: 0 14px; cursor: pointer; }
.chat-form button:disabled { opacity: 0.6; cursor: wait; }
