/* Sign Badgers Admin hub — styles
   Mobile first: bottom tab bar; ≥ 900px: left rail. */

:root {
  color-scheme: light dark;
  --green: #02c570;
  --green-ink: #027a46;
  --bg: #f4f5f4;
  --surface: #ffffff;
  --surface-2: #eef0ef;
  --line: #dfe3e1;
  --ink: #141816;
  --ink-2: #4f5753;
  --ink-3: #7a827e;
  --danger: #c93232;
  --warn-bg: #fff6df;
  --warn-ink: #7a5300;
  --shadow: 0 1px 1px rgba(20,24,22,.04), 0 2px 8px rgba(20,24,22,.04);
  --hairline: rgba(20,24,22,.08);
  --radius: 14px;
  --tab-h: 62px;
  --top-h: 52px;
  --series-1: #2a78d6;
  --series-ref: #a5aba8;
  --good: #0ca30c;
  --serious: #ec835a;
  --critical: #d03b3b;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151716;
    --surface: #1f2321;
    --surface-2: #272c2a;
    --line: #343a37;
    --ink: #f2f4f3;
    --ink-2: #c3c8c5;
    --ink-3: #8d948f;
    --warn-bg: #3a3012;
    --warn-ink: #ffd985;
    --shadow: 0 1px 1px rgba(0,0,0,.3), 0 2px 10px rgba(0,0,0,.25);
    --hairline: rgba(255,255,255,.08);
    --series-1: #3987e5;
    --series-ref: #6d746f;
  }
}
:root[data-theme="dark"] {
  --bg: #151716; --surface: #1f2321; --surface-2: #272c2a; --line: #343a37;
  --ink: #f2f4f3; --ink-2: #c3c8c5; --ink-3: #8d948f; --warn-bg: #3a3012; --warn-ink: #ffd985;
  --shadow: 0 1px 1px rgba(0,0,0,.3), 0 2px 10px rgba(0,0,0,.25); --hairline: rgba(255,255,255,.08); --series-1: #3987e5; --series-ref: #6d746f;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.4; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
a { color: var(--green-ink); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }
svg use { pointer-events: none; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 600; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--green); border-color: var(--green); color: #052b1a; }
.btn-primary:hover { background: #05d87c; }
.btn-ghost { background: transparent; }
.btn-lg { min-height: 48px; padding: 10px 22px; font-size: 17px; width: 100%; }
.btn-small { min-height: 32px; padding: 4px 12px; font-size: 14px; }
.btn[disabled] { opacity: .55; cursor: default; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- sign-in ---- */
.signin { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; padding-top: calc(24px + var(--sat)); }
.signin-card {
  width: 100%; max-width: 420px; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow);
  padding: 28px 22px; text-align: center;
}
.signin-logo { border-radius: 18px; margin-bottom: 10px; }
.signin h1 { font-size: 24px; margin-bottom: 6px; }
.signin p { margin: 0 0 18px; }
.signin .small { margin-top: 16px; margin-bottom: 0; }

/* ---- shell ---- */
.shell { height: 100%; display: grid; grid-template-rows: auto auto 1fr auto; grid-template-areas: "top" "banner" "main" "tabs"; }
.top {
  grid-area: top; height: calc(var(--top-h) + var(--sat)); padding-top: var(--sat);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding-left: 14px; padding-right: 8px; background: var(--surface); border-bottom: 1px solid var(--hairline);
  position: relative; z-index: 5;
}
.top-title { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; min-width: 0; }
.top-title img { border-radius: 8px; }
.top-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 2px; position: relative; }
.avatar-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.avatar-btn img { border-radius: 50%; }
#avatar-fallback { width: 30px; height: 30px; border-radius: 50%; background: var(--green); color: #052b1a; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.menu {
  position: absolute; right: 4px; top: 46px; min-width: 230px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 20;
}
.menu-user { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

.banner {
  grid-area: banner; display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--warn-bg); color: var(--warn-ink); font-size: 13px; border-bottom: 1px solid var(--hairline);
}
.banner span { flex: 1; }
.banner .icon-btn { width: 32px; height: 32px; color: inherit; }

.main { grid-area: main; position: relative; min-height: 0; }
.view { position: absolute; inset: 0; }
.view-scroll { overflow: auto; -webkit-overflow-scrolling: touch; }
.page { padding: 16px; max-width: 1100px; margin: 0 auto; }
.page-narrow { max-width: 720px; }

/* frames */
#view-frames { background: var(--surface); }
.frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--surface); }
.frame-status {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 14px; font-size: 14px;
  background: var(--warn-bg); color: var(--warn-ink); display: flex; gap: 10px; align-items: center; justify-content: center;
}

/* tabs (bottom bar on phones) */
.tabs {
  grid-area: tabs; display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--tab-h) + var(--sab)); padding-bottom: var(--sab);
  background: var(--surface); border-top: 1px solid var(--hairline); z-index: 5;
}
.tab {
  flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: transparent; color: var(--ink-3); font-size: 11px; font-weight: 600; cursor: pointer; padding: 6px 2px 4px;
  position: relative; min-width: 0;
}
.tab span { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }
.tab.is-active { color: var(--green-ink); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tab.is-active { color: var(--green); } }
.tab .dot { position: absolute; top: 8px; right: calc(50% - 16px); width: 8px; height: 8px; border-radius: 50%; background: var(--critical); }

/* ---- Home cards ---- */
.section { margin-bottom: 22px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.section-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 600; }
.section-tools { display: flex; align-items: center; gap: 6px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 12px; }
.cards-inline { display: contents; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--hairline); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 6px; min-height: 96px; position: relative; min-width: 0; overflow: hidden;
}
.card > * { min-width: 0; }
.card.card-wide { grid-column: 1 / -1; }
.card.card-link { cursor: pointer; }
.card.card-link:hover { outline: 2px solid var(--green); outline-offset: -2px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--ink-2); display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card-title > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title .tag { font-weight: 500; color: var(--ink-3); white-space: nowrap; }
.card-value { font-size: 26px; font-weight: 700; letter-spacing: -.015em; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.card-value .unit { font-size: 15px; font-weight: 600; color: var(--ink-2); margin-left: 4px; }
.card-sub { font-size: 13px; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 4px 10px; min-width: 0; }
.card-sub > span { overflow-wrap: anywhere; }
.delta { font-weight: 600; }
.delta.up { color: var(--good); }
.delta.down { color: var(--critical); }
.delta.flat { color: var(--ink-3); }
.meter { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; background: var(--green); border-radius: 4px; transition: width .4s ease; }
.meter > i.over { background: var(--series-1); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.card-items { display: flex; flex-direction: column; gap: 6px; margin-top: 2px; width: 100%; }
.card-item { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.card-item b { font-variant-numeric: tabular-nums; }
.card-item .tone-warn b { color: var(--serious); }
.card-item .tone-bad b { color: var(--critical); }
.card-item .tone-good b { color: var(--good); }
.card-foot { margin-top: auto; padding-top: 4px; font-size: 12px; color: var(--ink-3); display: flex; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap; }
.card-foot > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.card .skeleton { height: 28px; width: 60%; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.notice { background: var(--warn-bg); color: var(--warn-ink); padding: 9px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 12px; }
.notice a { color: inherit; }

/* year chart */
.chart { max-width: 100%; height: 190px; display: block; }
.chart .bar { rx: 0; }
.chart .ax { stroke: var(--hairline); stroke-width: 1; }
.chart text { fill: var(--ink-2); font-size: 11px; }
.chart .target { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; opacity: .8; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-top: 2px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin-right: 5px; }
.chart-tip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 12px;
  padding: 6px 8px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -110%); z-index: 3;
}

/* ---- Settings ---- */
.settings fieldset { border: 1px solid var(--hairline); border-radius: var(--radius); padding: 6px 16px 16px; margin: 0 0 16px; background: var(--surface); box-shadow: var(--shadow); }
.settings legend { font-weight: 700; padding: 0 6px; font-size: 15px; }
.settings label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 10px 0; }
.settings label em { font-style: normal; color: var(--green-ink); }
.settings input[type=text], .settings input[type=number], .settings input[type=date], .settings select, .settings textarea {
  font: inherit; font-size: 15px; font-weight: 400; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); width: 100%;
}
.settings input:focus, .settings select:focus, .settings textarea:focus { outline: 2px solid var(--green); outline-offset: -1px; }
.settings .months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; }
.settings .months label { margin: 4px 0; font-size: 12px; }
.settings .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.about { margin-top: 24px; }
.about h3 { font-size: 15px; margin-bottom: 6px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--sab) + 12px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 14px; z-index: 50; box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
}

/* ---- desktop: left rail ---- */
@media (min-width: 900px) {
  .shell { grid-template-columns: 96px 1fr; grid-template-rows: auto auto 1fr; grid-template-areas: "tabs top" "tabs banner" "tabs main"; }
  .tabs { flex-direction: column; justify-content: flex-start; height: auto; padding: 8px 6px; border-top: 0; border-right: 1px solid var(--hairline); }
  .tab { flex: 0 0 auto; padding: 12px 4px 10px; border-radius: 12px; }
  .tab span { white-space: normal; text-align: center; line-height: 1.15; }
  .tab.is-active { background: var(--surface-2); }
  .tab .dot { right: 14px; top: 10px; }
  .toast { bottom: 20px; }
  .page { padding: 22px 26px; }
}

/* ---- Money tiles: values hidden until pressed ---- */
.card-money { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: pointer; }
.card-money .secret { filter: blur(7px); transition: filter .15s ease; }
.card-money.revealed .secret { filter: none; }
.card-title .lock { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-3); font-weight: 500; white-space: nowrap; }
.card-money.revealed .card-title .lock { color: var(--green-ink); }
.card-money:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }

/* connections + import */
.conn { padding: 12px 0; border-top: 1px solid var(--hairline); }
.conn:first-child { border-top: 0; padding-top: 4px; }
.conn > b { display: inline-block; margin-right: 8px; }
.conn p { margin: 6px 0 4px; }
.conn code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.settings input[type=file] { font: inherit; font-size: 14px; }
.settings input[type=password], .settings input[type=url] { font: inherit; font-size: 15px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); width: 100%; }
#imp-fields label { font-size: 12px; }
#imp-fields select { font-size: 13px; padding: 6px 8px; }
