/* core/ui.css — reusable design system (tokens, reset, shell, components).
   App-specific feature styling lives in the host app's own stylesheet, loaded AFTER this one
   so app rules win ties. Theme via the :root custom properties below. */
:root {
  /* JacobsInc signature: deep navy + gold */
  --bg: #081020;
  --bg2: #0c1830;
  --card: #122040;
  --card2: #16294e;
  --border: #23385f;
  --text: #e9eef8;
  --muted: #8fa3c4;
  --primary: #3b76e8;
  --primary-hover: #5b90f5;
  --gold: #e8b64c;
  --teal: #3fd6b3;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.4);
  --grad: linear-gradient(135deg, #4a86f0, #2456b8);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: radial-gradient(1200px 800px at 80% -10%, #14264d 0%, var(--bg) 55%),
              radial-gradient(900px 600px at -10% 110%, #0d1b38 0%, var(--bg) 60%);
  color: var(--text);
  font-size: 14px;
}
h1,h2,h3 { margin: 0; font-weight: 700; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  width: 380px; max-width: 100%; text-align: center;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 20px; padding: 40px 34px; box-shadow: var(--shadow);
}
.auth-logo-img { width: 92px; height: 92px; margin-bottom: 4px; }
.auth-card .brand-eyebrow { font-size: 11px; letter-spacing: 4px; margin-top: 6px; }
.auth-card h1 { font-size: 34px; margin: 2px 0 6px; font-weight: 800; }
.wm-fin { color: #f2f5fb; }
.wm-hub {
  background: linear-gradient(120deg, #4a86f0, #2b9fe8);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.auth-tagline { font-size: 10px; letter-spacing: 3px; color: #cdd6ea; font-weight: 600; margin-bottom: 18px; }
.auth-tagline i { color: var(--teal); font-style: normal; }
.auth-sub { color: var(--muted); margin: 0 0 22px; }
.auth-note { color: var(--amber); font-size: 13px; }
.auth-card input {
  width: 100%; margin-bottom: 12px; padding: 12px 14px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 15px; outline: none;
}
.auth-card input:focus { border-color: var(--primary); }
.auth-card button {
  width: 100%; padding: 12px; border: 0; border-radius: 10px;
  background: var(--grad); color: #fff; font-size: 15px; font-weight: 600;
  box-shadow: 0 4px 18px rgba(59,118,232,.35);
}
.auth-card button:hover { filter: brightness(1.12); }
.auth-error { color: var(--red); min-height: 18px; font-size: 13px; }
.auth-or { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--muted); font-size: 11px; letter-spacing: 1px; text-transform: uppercase; }
.auth-or::before, .auth-or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 11px 12px; border-radius: 10px; text-decoration: none;
  background: #fff; color: #3c4043; font-size: 14px; font-weight: 600;
  border: 1px solid #dadce0;
}
.btn-google:hover { background: #f7f8fa; box-shadow: 0 1px 6px rgba(0,0,0,.15); }

/* ---------- shell ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 230px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--bg2); border-right: 1px solid var(--border); padding: 18px 14px;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 19px; font-weight: 800; padding: 4px 10px 18px; letter-spacing: .2px; }
.brand b { color: var(--primary-hover); }
.brand-logo { width: 34px; height: 34px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-eyebrow {
  font-size: 9.5px; font-weight: 700; letter-spacing: 3px;
  color: var(--teal); text-transform: uppercase;
}
#nav { display: flex; flex-direction: column; gap: 2px; min-height: 0; overflow-y: auto; scrollbar-width: thin; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  color: var(--muted); text-decoration: none; border-radius: 10px; font-weight: 500;
}
#nav a:hover { color: var(--text); background: rgba(255,255,255,.04); }
#nav a.active { color: #fff; background: var(--primary); }
#nav a { position: relative; }
.nav-badge { display: none; }
.nav-badge.on {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 17px; height: 17px; padding: 0 4px; margin-left: auto;
  background: var(--red); color: #fff; font-size: 10px; font-weight: 700; border-radius: 9px;
}
@media (max-width: 760px) {
  .nav-badge.on { position: absolute; top: 2px; right: 2px; margin: 0; }
}
.sidebar-entities { margin-top: 22px; padding: 0 10px; flex: 1; overflow-y: auto; }
.sidebar-entities h4 { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; margin: 0 0 10px; }
.side-ent { display: flex; align-items: center; gap: 8px; padding: 5px 0; color: var(--muted); font-size: 13px; }
.side-ent .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.side-ent .amt { margin-left: auto; font-variant-numeric: tabular-nums; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 10px 10px 4px; font-size: 13px; line-height: 1.25; }
.user-chip .avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.logout-btn {
  margin-top: 10px; padding: 9px; border-radius: 10px; border: 1px solid var(--border);
  background: transparent; color: var(--muted); font-weight: 500;
}
.logout-btn:hover { color: var(--text); border-color: var(--muted); }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 16px 26px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.topbar h2 { font-size: 20px; }
.topbar-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.topbar-controls select, .topbar-controls input {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 8px 12px; outline: none; font-size: 13px;
}
/* account menu (top-right, always visible) */
.acct { position: relative; }
.acct-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--grad); color: #fff; font-weight: 700; font-size: 15px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.acct-btn:hover { filter: brightness(1.1); }
.acct-pop {
  position: absolute; top: 46px; right: 0; z-index: 40; min-width: 210px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 12px; display: none; flex-direction: column; gap: 8px;
}
.acct-pop.open { display: flex; }
.acct-who { font-size: 13px; color: var(--muted); padding: 2px 2px 8px; border-bottom: 1px solid var(--border); }
.acct-who b { color: var(--text); display: block; font-size: 14px; }
.acct-pop .btn { width: 100%; justify-content: center; text-align: center; }

.view { flex: 1; overflow-y: auto; padding: 24px 26px 60px; }

/* ---------- welcome / first-run ---------- */
.welcome-card {
  max-width: 480px; margin: 40px auto; text-align: center;
  background: linear-gradient(160deg, var(--card) 0%, var(--bg2) 130%);
  border: 1px solid var(--border); border-radius: 18px; padding: 34px 30px; box-shadow: var(--shadow);
}
.welcome-icon { font-size: 44px; margin-bottom: 6px; }
.welcome-card h2 { font-size: 22px; margin-bottom: 10px; }
.welcome-card p { color: var(--muted); line-height: 1.6; margin: 0 0 18px; }
.welcome-card .btn { font-size: 15px; padding: 12px 22px; }
.welcome-hint { font-size: 12.5px; margin-top: 18px !important; }

/* ---------- buttons ---------- */
.btn {
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-weight: 600; font-size: 13px;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--grad); border-color: transparent; color: #fff;
  box-shadow: 0 3px 12px rgba(59,118,232,.28); }
.btn-primary:hover { filter: brightness(1.12); border-color: transparent; }
.btn-danger { color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---------- cards / grids / panels ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card {
  background: linear-gradient(160deg, var(--card) 0%, var(--bg2) 130%);
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  transition: border-color .2s, transform .2s;
}
.card:hover { border-color: #33507f; }
.card .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; }
.card .value { font-size: 24px; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.pos { color: var(--green); } .neg { color: var(--red); }

.panel-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 14px; margin-bottom: 20px; }
@media (max-width: 1000px) { .panel-grid { grid-template-columns: 1fr; } }
.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.panel h3 { font-size: 14px; margin-bottom: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .8px; }
.chart-box { position: relative; height: 260px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid rgba(38,47,87,.5); font-size: 13.5px; vertical-align: middle; }
tr:hover td { background: rgba(255,255,255,.02); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 20px; font-size: 12px; background: var(--bg2); border: 1px solid var(--border); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; }
.row-actions button { background: none; border: 0; color: var(--muted); font-size: 14px; padding: 3px 5px; border-radius: 6px; }
.row-actions button:hover { color: var(--text); background: var(--bg2); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* filter bar */
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input, .filters select {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 8px 12px; font-size: 13px; outline: none;
}
.filters input[type=text] { min-width: 220px; }

/* ---------- modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5,8,20,.7); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 440px; max-width: 100%; max-height: 90vh; overflow-y: auto;
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 24px; box-shadow: var(--shadow);
}
.modal h3 { margin-bottom: 16px; }
.modal label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.modal input:not([type=checkbox]), .modal select {
  display: block; width: 100%; margin-top: 5px; padding: 10px 12px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 14px; outline: none;
}
.modal input:focus, .modal select:focus { border-color: var(--primary); }
.modal .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal .check { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-lg { width: 640px; }
.kind-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.kind-tabs button {
  flex: 1; padding: 8px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg2); color: var(--muted); font-weight: 600;
}
.kind-tabs button.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- dropzone (generic file upload) ---------- */
.drop {
  border: 2px dashed var(--border); border-radius: 12px; padding: 26px 16px;
  text-align: center; color: var(--muted); cursor: pointer; margin-bottom: 14px;
}
.drop:hover, .drop.over { border-color: var(--primary); color: var(--text); background: rgba(99,102,241,.06); }
.drop-icon { font-size: 30px; margin-bottom: 6px; }
.drop-sub { font-size: 12px; margin-top: 4px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--card2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 20px; border-radius: 12px; box-shadow: var(--shadow);
  opacity: 0; transition: all .25s; z-index: 100; font-weight: 500;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--red); color: #fca5a5; }

/* ---------- generic layout: settings grid, section headers ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 1000px) { .settings-grid { grid-template-columns: 1fr; } }
.panel .panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel .panel-head h3 { margin: 0; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 14px; }
.section-head h3 { font-size: 15px; }

/* ---------- mobile bottom tab bar + More sheet (part of the shell) ---------- */
.mobile-nav { display: none; }
.msheet, .msheet-backdrop { display: none; }
.msheet-grid a .ico, .mobile-nav .ico { display: inline-block; }

/* mobile — shell + core components */
@media (max-width: 760px) {
  .app { flex-direction: column; height: 100dvh; }
  /* Slim brand-only top bar; navigation moves to the bottom tab bar */
  .sidebar {
    width: 100%; flex-direction: row; align-items: center;
    padding: 9px 14px; flex-shrink: 0; overflow: visible;
  }
  .brand { padding: 0; white-space: nowrap; font-size: 17px; }
  #nav, .sidebar-entities, .user-chip, .logout-btn { display: none; }

  /* Bottom tab bar */
  .mobile-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    display: flex; justify-content: space-around; align-items: stretch;
    background: color-mix(in srgb, var(--card) 90%, #000);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    padding: 6px 2px calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .mobile-nav a, .mobile-nav .m-more-btn {
    flex: 1 1 0; min-width: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px;
    background: none; border: 0; text-decoration: none;
    color: var(--muted); font-weight: 600; font-size: 10px; letter-spacing: .2px;
    padding: 4px 2px; position: relative; transition: color .15s;
  }
  .mobile-nav .ico { font-size: 21px; line-height: 1; transition: transform .15s; }
  .mobile-nav .m-lbl { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-nav a.active { color: var(--primary); }
  .mobile-nav a.active .ico { transform: translateY(-2px); }
  .mobile-nav .nav-badge.on {
    position: absolute; top: 0; right: 18%; margin: 0;
    min-width: 16px; height: 16px; font-size: 9.5px;
  }

  /* More sheet */
  .msheet-backdrop {
    display: block; position: fixed; inset: 0; z-index: 70;
    background: rgba(0,0,0,.55); opacity: 0; pointer-events: none; transition: opacity .22s;
  }
  .msheet-backdrop.open { opacity: 1; pointer-events: auto; }
  .msheet {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
    background: var(--card); border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0; box-shadow: 0 -12px 40px rgba(0,0,0,.5);
    transform: translateY(100%); transition: transform .26s cubic-bezier(.32,.72,0,1);
    padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0px));
    max-height: 82vh; overflow-y: auto;
  }
  .msheet.open { transform: translateY(0); }
  .msheet::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 3px; background: var(--border); margin: 4px auto 12px; }
  .msheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-weight: 700; font-size: 15px; }
  .msheet-head button { background: var(--bg2); border: 1px solid var(--border); color: var(--muted); width: 32px; height: 32px; border-radius: 50%; font-size: 15px; }
  .msheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .msheet-grid a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px;
    padding: 15px 6px; border-radius: 15px; text-align: center;
    background: var(--bg2); border: 1px solid var(--border);
    color: var(--text); text-decoration: none; font-size: 12px; font-weight: 600; position: relative;
  }
  .msheet-grid a .ico { font-size: 23px; line-height: 1; }
  .msheet-grid a.active { border-color: var(--primary); color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, var(--bg2)); }
  .msheet-grid a.msheet-signout { color: #fca5a5; border-color: rgba(239,68,68,.4); }
  .msheet-grid a .nav-badge.on { position: absolute; top: 8px; right: 12px; margin: 0; }
  .topbar { padding: 12px 14px; gap: 10px; }
  .topbar h2 { font-size: 17px; width: 100%; }
  .topbar-controls { width: 100%; }
  .topbar-controls select, .topbar-controls input { flex: 1; min-width: 0; }
  .topbar-controls .btn { flex: 1; white-space: nowrap; }
  .view { padding: 14px 12px 88px; }          /* extra bottom padding clears the fixed tab bar */
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 13px 14px; }
  .card .value { font-size: 19px; }
  .panel { padding: 14px; overflow-x: auto; }   /* wide tables scroll inside their panel */
  .panel table { min-width: 560px; }
  .panel .chart-box canvas { min-width: 0; }
  .section-head { flex-wrap: wrap; gap: 10px; }
  .filters input[type=text] { min-width: 0; flex: 1; }
  .modal { padding: 18px 16px; }
  .modal .grid2 { grid-template-columns: 1fr; gap: 0; }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 430px) {
  .cards { grid-template-columns: 1fr; }
}
