:root {
  --bg: #f7f8f8;
  --surface: #ffffff;
  --text: #1a2222;
  --muted: #667070;
  --border: #e2e6e6;
  --accent: #0f766e;
  --accent-contrast: #ffffff;
  --pos: #15803d;
  --neg: #b91c1c;
  --warn-bg: #fef6e0;
  --warn-text: #92620a;
  --err-bg: #fdecec;
  --err-text: #a51b1b;
  --ok-bg: #e7f6ec;
  --ok-text: #15803d;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}
:root[data-theme="dark"], html[data-theme="dark"] {
  --bg: #0f1414; --surface: #182020; --text: #e6ebeb; --muted: #93a0a0;
  --border: #2a3535; --accent: #2dd4bf; --accent-contrast: #06231f;
  --pos: #4ade80; --neg: #f87171; --warn-bg: #3a2f12; --warn-text: #fcd77f;
  --err-bg: #3a1c1c; --err-text: #fca5a5; --ok-bg: #14301f; --ok-text: #86efac;
  --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1414; --surface: #182020; --text: #e6ebeb; --muted: #93a0a0;
    --border: #2a3535; --accent: #2dd4bf; --accent-contrast: #06231f;
    --pos: #4ade80; --neg: #f87171; --warn-bg: #3a2f12; --warn-text: #fcd77f;
    --err-bg: #3a1c1c; --err-text: #fca5a5; --ok-bg: #14301f; --ok-text: #86efac;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* ---- Header (mobile-first: hamburger dropdown) ---- */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .6rem 1rem; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--accent); text-decoration: none; }

.site-menu { position: relative; }
.menu-toggle {
  width: 2.5rem; height: 2.5rem;
  display: grid; place-items: center; line-height: 0;
  border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); background: var(--surface);
  cursor: pointer; list-style: none;
}
.menu-toggle::-webkit-details-marker { display: none; }
.menu-toggle:hover { border-color: var(--accent); color: var(--accent); }
.menu-toggle .icon-close { display: none; }
.site-menu[open] .menu-toggle .icon-open { display: none; }
.site-menu[open] .menu-toggle .icon-close { display: block; }

.menu-panel {
  position: absolute; top: calc(100% + .5rem); right: 0;
  z-index: 30; min-width: 13rem; max-width: min(88vw, 20rem);
  display: flex; flex-direction: column; gap: .25rem;
  padding: .5rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
}

.menu-nav { display: flex; flex-direction: column; gap: .1rem; }
.menu-nav a {
  color: var(--text); text-decoration: none; padding: .6rem .7rem;
  border-radius: 8px; font-size: 1rem;
}
.menu-nav a:hover { background: var(--bg); }

.menu-tools {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .5rem .3rem 0; margin-top: .25rem; border-top: 1px solid var(--border);
}
.lang-switch { display: flex; gap: .2rem; font-size: .85rem; }
.lang-switch a { color: var(--muted); text-decoration: none; padding: .2rem .4rem; border-radius: 6px; }
.lang-switch a:hover { background: var(--bg); }
.lang-switch .lang-active { font-weight: 700; color: var(--accent); padding: .2rem .4rem; }
.theme-toggle { background: none; border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; font-size: 1rem; padding: .3rem .55rem; color: var(--text); }
.logout { color: var(--muted); text-decoration: none; font-size: .9rem; margin-left: auto;
  display: inline-flex; align-items: center; gap: .4rem; }
.logout-icon { display: none; }

/* Logged-in user indicator */
.user-chip { display: inline-flex; align-items: center; gap: .5rem; font-size: .95rem;
  padding: .4rem .5rem; }
.user-avatar { display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; border-radius: 50%; background: var(--accent);
  color: var(--accent-contrast); font-weight: 700; font-size: .85rem; flex: none; }
.user-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-badge { font-size: .68rem; text-transform: uppercase; letter-spacing: .03em;
  padding: .1rem .45rem; border-radius: 999px; border: 1px solid var(--border);
  color: var(--muted); flex: none; }
.role-badge.role-admin { background: var(--accent); color: var(--accent-contrast); border-color: transparent; }

/* ---- Wide screens: inline bar, no hamburger (below this, the mobile menu) ---- */
@media (min-width: 1260px) {
  .menu-toggle { display: none; }
  .site-menu { flex: 1; }
  .menu-panel {
    position: static; flex-direction: row; flex-wrap: nowrap; align-items: center;
    gap: .4rem; min-width: 0; max-width: none;
    padding: 0; border: none; box-shadow: none; background: none;
  }
  .menu-nav { flex-direction: row; flex-wrap: nowrap; flex-shrink: 0;
    gap: .1rem; margin-right: auto; order: 1; }
  .menu-nav a { padding: .4rem .5rem; font-size: .9rem; white-space: nowrap; }
  .user-chip { order: 2; padding: .2rem; flex-shrink: 0; gap: .4rem; }
  .user-name { max-width: 9rem; }
  .menu-tools { order: 3; margin-top: 0; padding: 0; border-top: none; flex-shrink: 0; gap: .4rem; }
  .logout { margin-left: 0; padding: .35rem; border: 1px solid var(--border); border-radius: 8px; }
  .logout:hover { border-color: var(--accent); color: var(--accent); }
  .logout-label { display: none; }
  .logout-icon { display: block; }
}

.container { max-width: 960px; margin: 0 auto; padding: 1rem; }
.page-head { display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1, .page-head h2 { margin: 0; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; }

.card { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1.25rem; }
.auth-card { max-width: 380px; margin: 3rem auto; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.data th, table.data td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.inactive { opacity: .5; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.row-actions { display: flex; gap: .35rem; justify-content: flex-end; }
.row-actions form { margin: 0; }

/* Forms */
label { display: block; margin-bottom: .75rem; font-size: .9rem; color: var(--muted); }
input, select { font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .55rem .6rem; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.form-stack label { max-width: 460px; }
.form-row { margin-bottom: .75rem; }
.form-actions { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; }
.checkbox input { width: auto; }
.filters { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.filters label { margin-bottom: 0; }
.inline { display: inline; margin: 0; }
table.entry input { min-width: 7rem; }
input.same-as-prev { border-color: var(--warn-text); background: var(--warn-bg); }

/* Buttons */
.btn { display: inline-block; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: .5rem .85rem;
  text-decoration: none; cursor: pointer; font: inherit; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.btn-sm { padding: .3rem .55rem; font-size: .85rem; }
.btn-danger { color: var(--neg); }
.btn-google { display: block; text-align: center; }
.or-sep { text-align: center; color: var(--muted); margin: .75rem 0; font-size: .85rem; }

/* Flash + tags */
.flash { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; font-size: .95rem; }
.flash-success { background: var(--ok-bg); color: var(--ok-text); }
.flash-error { background: var(--err-bg); color: var(--err-text); }
.flash-warning { background: var(--warn-bg); color: var(--warn-text); }
.tag { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem;
  background: var(--bg); border: 1px solid var(--border); }
tr.recon-variance td { background: color-mix(in srgb, var(--err-bg) 55%, transparent); }
tr.recon-match .tag-match { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.tag-variance { background: var(--err-bg); color: var(--err-text); border-color: transparent; }

/* Insights stat tiles */
.insights { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .85rem 1rem; display: flex; flex-direction: column; gap: .2rem; }
.stat-wide { grid-column: 1 / -1; }
.stat-num { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; }

table.data td.center, table.data th.center { text-align: center; }
fieldset.perms { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; margin-bottom: .75rem; max-width: 460px; }
fieldset.perms legend { color: var(--muted); font-size: .85rem; padding: 0 .3rem; }
fieldset.perms .checkbox { margin-bottom: .35rem; }

.site-footer { text-align: center; color: var(--muted); padding: 2rem 1rem; font-size: .85rem; }

@media (max-width: 640px) {
  h1 { font-size: 1.3rem; }
}
