/* Calibri-compatible font for the sheets: the device's own Calibri if it has one, otherwise the
   bundled Carlito (SIL Open Font License, see fonts/OFL.txt), which has the same letter widths. */
@font-face { font-family: "XL Calibri"; src: local("Calibri"), url(../fonts/Carlito-Regular.ttf) format("truetype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "XL Calibri"; src: local("Calibri Bold"), local("Calibri-Bold"), url(../fonts/Carlito-Bold.ttf) format("truetype"); font-weight: 700; font-style: normal; font-display: swap; }
:root {
  --brand: #0f4c64; --brand-2: #156082; --brand-ink: #ffffff; --accent: #e97132;
  --ink: #1d2329; --ink-2: #4a5560; --muted: #7a8792; --line: #d9dee3; --line-2: #eef1f4;
  --bg: #f4f6f8; --card: #ffffff; --ok: #1f7a3f; --warn: #a15c00; --bad: #b3261e;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 12px rgba(16,24,40,.06);
  --grid-head: #f3f4f6; --grid-line: #e1e4e8; --sel: #1a73e8;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.4 var(--font); color: var(--ink); background: var(--bg); -webkit-text-size-adjust: 100%; }
#app { height: 100%; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-2); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1; }

/* boot & spinners */
.boot { margin: auto; text-align: center; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--brand-2); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 7px 12px; cursor: pointer; white-space: nowrap; line-height: 1.2; }
.btn:hover { background: #f7f9fa; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.primary:hover { background: var(--brand); }
.btn.danger { color: var(--bad); border-color: #f0c9c6; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn.icon { padding: 6px 8px; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff; min-width: 0; }
textarea { width: 100%; min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid #9cc3e6; outline-offset: 0; }
label.field { display: grid; gap: 4px; margin-bottom: 10px; }
label.field > span { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }

/* auth screens */
.auth { margin: auto; width: min(420px, 94vw); background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 28px; }
.auth h1 { font-size: 20px; margin: 0 0 4px; }
.auth .brandmark { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; }
.auth .brandmark img { width: 40px; height: 40px; }
.auth .err { color: var(--bad); min-height: 20px; margin: 6px 0; }
.auth .btn.primary { width: 100%; justify-content: center; padding: 10px; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--brand); color: #fff; min-height: 50px; }
.topbar .title { font-weight: 700; font-size: 16px; white-space: nowrap; }
.topbar .ver { font-size: 12px; opacity: .9; background: rgba(255,255,255,.12); padding: 4px 8px; border-radius: 12px; white-space: nowrap; cursor: pointer; border: 0; color: #fff; }
.topbar .btn { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.2); color: #fff; }
.topbar .btn:hover { background: rgba(255,255,255,.22); }
.topbar .who { font-size: 12px; opacity: .85; white-space: nowrap; }
.topbar .title, .topbar .btn { flex-shrink: 0; }
.topbar .ver { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.menu { position: absolute; right: 8px; top: 48px; background: #fff; color: var(--ink); border-radius: 8px; box-shadow: var(--shadow); border: 1px solid var(--line); min-width: 230px; z-index: 50; padding: 6px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--line-2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* tabs */
.tabs { display: flex; gap: 2px; overflow-x: auto; background: #e9edf1; border-bottom: 1px solid var(--line); padding: 4px 6px 0; scrollbar-width: thin; }
.tabs button { border: 1px solid transparent; border-bottom: 0; background: transparent; padding: 7px 12px; border-radius: 6px 6px 0 0; cursor: pointer; white-space: nowrap; color: var(--ink-2); font-size: 13px; }
.tabs button.active { background: #fff; border-color: var(--line); color: var(--ink); font-weight: 600; }
.tabs button.dash { color: var(--brand-2); font-weight: 600; }
.tabselect { display: none; padding: 6px; background: #e9edf1; border-bottom: 1px solid var(--line); }
.tabselect select { width: 100%; }

/* main area */
.main { flex: 1 1 auto; min-height: 0; display: flex; }
.content { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.page { flex: 1 1 auto; overflow: auto; padding: 16px; }
.page.narrow { max-width: 1100px; width: 100%; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 1px rgba(0,0,0,.02); }
.card h2 { font-size: 16px; margin: 0 0 10px; }
.card h3 { font-size: 14px; margin: 14px 0 8px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; background: var(--line-2); color: var(--ink-2); }
.badge.ok { background: #e3f4e8; color: var(--ok); } .badge.warn { background: #fff1dd; color: var(--warn); } .badge.bad { background: #fde8e6; color: var(--bad); }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.list th { font-size: 12px; color: var(--ink-2); font-weight: 600; }

/* sheet toolbar & formula bar */
.sheetbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.sheetbar .period { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.sheetbar input[type=date] { padding: 4px 6px; }
.fbar { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); background: #fff; min-height: 30px; }
.fbar .ref { width: 92px; border-right: 1px solid var(--line); padding: 5px 8px; font: 12px ui-monospace, Menlo, Consolas, monospace; color: var(--ink-2); }
.fbar .fx { padding: 5px 8px; color: var(--muted); font-style: italic; border-right: 1px solid var(--line); }
.fbar .ftext { flex: 1; padding: 5px 8px; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: text; }

/* grid */
.gridwrap { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; background: #fff; }
.grid-scroll { position: absolute; inset: 0; overflow: auto; }
.grid-space { position: relative; }
.grid-cells { position: absolute; left: 0; top: 0; }
.gc { position: absolute; overflow: hidden; white-space: nowrap; padding: 1px 3px; border-right: 1px solid var(--grid-line); border-bottom: 1px solid var(--grid-line); background: #fff; font-family: "Aptos Narrow", "XL Calibri", Calibri, Carlito, Arial, sans-serif; font-size: 14.67px; line-height: 1.15; display: flex; }
.gc > span { display: block; width: 100%; overflow: hidden; text-overflow: clip; align-self: flex-end; }
.gc.mid > span { align-self: center; } .gc.top > span { align-self: flex-start; }
.gc.wrap > span { white-space: pre-wrap; word-break: break-word; }
.gc.num { justify-content: flex-end; text-align: right; }
.gc.ovf { overflow: visible; z-index: 1; }
.gc.ovf > span { overflow: visible; }
.gc.sel { outline: 2px solid var(--sel); outline-offset: -2px; z-index: 3; }
.gc.err { color: var(--bad); }
.gh { position: absolute; background: var(--grid-head); color: #555; font: 11px var(--font); display: flex; align-items: center; justify-content: center; border-right: 1px solid #d4d7db; border-bottom: 1px solid #d4d7db; z-index: 4; user-select: none; }
.gh.cur { background: #d3e3fd; color: #0b57d0; font-weight: 600; }
.gh.flt { color: #1a5fb4; }
.gcorner { position: absolute; left: 0; top: 0; background: var(--grid-head); border-right: 1px solid #d4d7db; border-bottom: 1px solid #d4d7db; z-index: 6; }
.grid-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); padding: 20px; text-align: center; }

/* side panel */
.side { width: 380px; max-width: 92vw; border-left: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; min-height: 0; }
.side header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 600; }
.side .body { padding: 12px; overflow: auto; flex: 1; }
.side pre, .codebox { white-space: pre-wrap; word-break: break-word; background: #f6f8fa; border: 1px solid var(--line-2); border-radius: 6px; padding: 8px; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; margin: 6px 0; }
.explain li { margin: 4px 0; }
.explain .val { font-weight: 600; }
.chat { display: flex; flex-direction: column; gap: 8px; }
.chat .msg { padding: 8px 10px; border-radius: 8px; background: #f2f5f8; white-space: pre-wrap; word-break: break-word; }
.chat .msg.me { background: #e5f0fb; align-self: flex-end; max-width: 90%; }

/* modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,32,.45); display: grid; place-items: center; z-index: 100; padding: 12px; }
.modal { background: #fff; border-radius: 12px; box-shadow: var(--shadow); width: min(560px, 100%); max-height: 92vh; overflow: auto; }
.modal.wide { width: min(980px, 100%); }
.modal header { padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 700; display: flex; align-items: center; }
.modal .body { padding: 16px; }
.modal footer { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; }
.toast { background: #1f2933; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 90vw; }
.toast.bad { background: var(--bad); } .toast.ok { background: var(--ok); }
.progress { height: 6px; background: var(--line-2); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--brand-2); width: 0; transition: width .2s; }
.overlay { position: fixed; inset: 0; background: rgba(255,255,255,.82); z-index: 150; display: grid; place-items: center; }
.overlay .box { text-align: center; width: min(420px, 90vw); }

/* uploads */
.uploads { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.drop { border: 2px dashed var(--line); border-radius: 8px; padding: 14px; text-align: center; color: var(--muted); cursor: pointer; margin-top: 8px; }
.drop.over { border-color: var(--brand-2); background: #eef6fb; color: var(--ink); }
.drop.big { padding: 34px 16px; border-width: 3px; background: #fafcfd; }
.drop .droptitle { font-size: 18px; font-weight: 700; color: var(--brand); margin-bottom: 4px; }
.warnbox { border-left: 4px solid #e0a800; background: #fff8e1; padding: 8px 10px; border-radius: 4px; margin: 6px 0 10px; font-size: 13px; }
table.publist td { vertical-align: top; } table.publist select { max-width: 280px; }
table.list .num { text-align: right; white-space: nowrap; }
table.publist tr.unused td { color: var(--muted); }
.btn.big { font-size: 15px; padding: 10px 18px; }
.mapgrid { font-size: 12px; max-height: 220px; overflow: auto; border: 1px solid var(--line-2); border-radius: 6px; }
.mapgrid table { border-collapse: collapse; width: 100%; }
.mapgrid td, .mapgrid th { padding: 3px 6px; border-bottom: 1px solid var(--line-2); text-align: left; white-space: nowrap; }

/* QR */
.qr { display: grid; place-items: center; padding: 10px; }
.qr canvas, .qr svg { width: 240px; height: 240px; image-rendering: pixelated; }

/* ---------------- dashboard (Power BI replica) ---------------- */
.dash { background: #fff; padding: 12px; min-height: 100%; }
.dash .slicers { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 12px; align-items: end; margin-bottom: 10px; }
.dash .slicer label { display: block; font-size: 12px; color: #444; margin-bottom: 2px; font-weight: 600; }
.dash .slicer select, .dash .slicer input { width: 100%; padding: 5px 6px; font-size: 13px; border-color: #c8c8c8; }
.dash .slicer .ms { position: relative; }
.dash .slicer .ms-btn { width: 100%; text-align: left; border: 1px solid #c8c8c8; border-radius: 4px; padding: 5px 24px 5px 6px; background: #fff; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; position: relative; }
.dash .slicer .ms-btn::after { content: '▾'; position: absolute; right: 7px; top: 5px; color: #666; }
.dash .slicer .ms-pop { position: absolute; z-index: 30; top: 100%; left: 0; min-width: 100%; max-width: 360px; max-height: 300px; overflow: auto; background: #fff; border: 1px solid #c8c8c8; box-shadow: var(--shadow); border-radius: 4px; padding: 6px; }
.dash .slicer .ms-pop label { display: flex; gap: 6px; align-items: center; font-weight: 400; padding: 2px 0; white-space: nowrap; }
.dash .timegone { background: #d8ad00; color: #3b2f00; border-radius: 4px; padding: 6px 10px; text-align: left; min-width: 110px; box-shadow: inset 0 0 0 2px #c79f00; }
.dash .timegone b { display: block; font-size: 22px; line-height: 1.1; color: #2b2300; }
.dash .timegone span { font-size: 14px; color: #4d4100; }
.dash .grid2 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
.dash .visual { min-width: 0; display: flex; flex-direction: column; }
.dash .visual.span2 { grid-column: span 2; } .dash .visual.span3 { grid-column: 1 / -1; }
.dash .vtitle { font: italic 700 21px/1.2 "Segoe UI", Arial, sans-serif; color: #e0201b; text-decoration: underline; text-underline-offset: 3px; margin: 4px 0 6px; text-align: center; text-shadow: 0 1px 0 rgba(0,0,0,.05); }
.dash .tbl { border: 1px solid #e3e3e3; overflow: auto; max-height: 300px; position: relative; }
.dash .tbl.tall { max-height: 360px; }
.dash table.mx { border-collapse: separate; border-spacing: 0; width: 100%; font: 12.5px "Segoe UI", Arial, sans-serif; color: #222; }
.dash table.mx th { background: #e97132; color: #222; font-weight: 400; padding: 6px 6px; position: sticky; top: 0; z-index: 2; text-align: right; border-right: 1px solid #f2a679; cursor: pointer; vertical-align: top; }
.dash table.mx th:first-child { text-align: left; }
.dash table.mx th .arrow { font-size: 10px; margin-left: 3px; }
.dash table.mx td { padding: 4px 6px; text-align: right; white-space: nowrap; border-bottom: 1px solid #f1f1f1; }
.dash table.mx td:first-child { text-align: left; white-space: normal; min-width: 150px; }
.dash table.mx tr.data { cursor: pointer; }
.dash table.mx tr.data:hover td { background: #fbf3ee; }
.dash table.mx tr.sel td { background: #fde3d3; font-weight: 600; }
.dash table.mx tr.dim td { color: #b5b5b5; }
.dash table.mx tfoot td { font-weight: 700; position: sticky; bottom: 0; background: #fff; border-top: 2px solid #222; }
.dash .note { font-size: 12px; color: var(--muted); margin-top: 8px; }
.dash .chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.dash .chip { background: #fde3d3; border: 1px solid #f2a679; border-radius: 12px; padding: 2px 8px; font-size: 12px; cursor: pointer; }

/* responsive */
@media (max-width: 860px) {
  .tabs { display: none; } .tabselect { display: block; }
  .side { position: fixed; inset: auto 0 0 0; width: 100%; max-width: none; height: 62vh; border-left: 0; border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(0,0,0,.15); z-index: 60; border-radius: 12px 12px 0 0; }
  .topbar .who, .topbar .title small { display: none; }
  .dash .grid2 { grid-template-columns: 1fr; }
  .dash .visual.span2, .dash .visual.span3 { grid-column: auto; }
  .dash .vtitle { font-size: 18px; }
  .page { padding: 10px; }
  .hide-sm { display: none !important; }
}
@media (max-width: 520px) {
  .hide-xs { display: none !important; }
  .topbar { gap: 6px; padding: 8px; }
  .topbar .title { font-size: 15px; }
}
@media print { .topbar, .tabs, .sheetbar, .fbar, .side { display: none !important; } }
