:root {
  --bg: #f2f5f1;
  --bg2: #e5ece3;
  --card: #ffffff;
  --ink: #0e1f16;
  --muted: #5a6b60;
  --line: #d0dbd3;
  --brand: #146b42;
  --brand-dark: #0b3d27;
  --brand-soft: #dff0e6;
  --accent: #d4a84b;
  --accent-2: #e8c56a;
  --warn: #b85a1f;
  --danger: #b33a2e;
  --ok: #1d7a45;
  --sidebar: #0a2418;
  --sidebar-2: #123528;
  --shadow: 0 12px 32px rgba(10, 36, 24, 0.1);
  --radius: 12px;
  --font: "Manrope", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --display: "Fraunces", "Source Serif 4", "Noto Serif SC", serif;
  --sidebar-w: 260px;
  --touch: 44px;
}
* { box-sizing: border-box }
html, body { margin: 0; min-height: 100% }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit }
button { cursor: pointer }
a { color: inherit }
img { max-width: 100%; display: block }

.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--muted);
  letter-spacing: 0.04em;
}

/* ===== Language switcher ===== */
.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
}
.lang-switch button {
  border: 0;
  background: transparent;
  color: inherit;
  min-width: 40px;
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  opacity: 0.75;
}
.lang-switch button.active {
  background: #fff;
  color: var(--brand-dark);
  opacity: 1;
}
.lang-switch.dark {
  background: #eef3ef;
  border-color: var(--line);
  color: var(--ink);
}
.lang-switch.dark button.active {
  background: var(--brand);
  color: #fff;
}

/* ===== Landing (full-bleed brand hero) ===== */
.landing {
  min-height: 100vh;
  color: #f4faf6;
  background: #0a2418;
}
.landing-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px clamp(14px, 4vw, 40px);
}
.landing-logo {
  font-family: var(--display);
  font-size: clamp(20px, 2.8vw, 28px);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.15;
}
.landing-logo small {
  display: block;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  opacity: 0.72;
  margin-top: 3px;
  letter-spacing: 0.04em;
}
.landing-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.landing-hero {
  position: relative;
  min-height: 100vh;
  display: grid;
  align-content: end;
  padding: 110px clamp(16px, 5vw, 56px) clamp(40px, 8vh, 72px);
  overflow: hidden;
  isolation: isolate;
}
.landing-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    linear-gradient(115deg, rgba(8, 28, 18, 0.55) 0%, rgba(8, 28, 18, 0.25) 42%, rgba(8, 28, 18, 0.72) 100%),
    radial-gradient(ellipse 70% 55% at 78% 35%, rgba(212, 168, 75, 0.35), transparent 60%),
    radial-gradient(ellipse 50% 40% at 15% 70%, rgba(40, 140, 90, 0.35), transparent 55%),
    linear-gradient(160deg, #0a2418 0%, #146b42 48%, #0f3d28 100%);
}
.landing-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0.22;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255, 200, 90, 0.5) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 60%, rgba(255, 255, 255, 0.35) 0 1.5px, transparent 3px),
    radial-gradient(circle at 40% 80%, rgba(180, 255, 200, 0.35) 0 2px, transparent 3px);
  background-size: 120px 120px, 90px 90px, 140px 140px;
  animation: drift 28s linear infinite;
}
.hero-brand {
  font-family: var(--display);
  font-size: clamp(42px, 9vw, 88px);
  font-weight: 700;
  line-height: 0.98;
  letter-spacing: -0.02em;
  margin: 0 0 14px;
  max-width: 12ch;
  animation: rise 0.7s ease both;
}
.hero-lead {
  margin: 0;
  font-size: clamp(15px, 2.1vw, 18px);
  line-height: 1.55;
  max-width: 38ch;
  opacity: 0.9;
  animation: rise 0.7s ease 0.08s both;
}
.landing-cta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 22px;
  animation: rise 0.7s ease 0.14s both;
}
.landing-cta .btn {
  min-height: var(--touch);
  padding: 12px 20px;
  font-weight: 600;
}
.hero-tip {
  margin-top: 18px;
  font-size: 12px;
  opacity: 0.7;
  animation: rise 0.7s ease 0.2s both;
}

.landing-body {
  color: var(--ink);
  background:
    linear-gradient(180deg, #eef4ec 0%, var(--bg) 120px);
}
.landing section {
  padding: 56px clamp(16px, 5vw, 56px);
}
.landing .sec-head {
  max-width: 560px;
  margin-bottom: 28px;
}
.landing .sec-head h2 {
  margin: 0 0 8px;
  font-family: var(--display);
  font-size: clamp(26px, 3.5vw, 36px);
  font-weight: 700;
}
.landing .sec-head p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 28px 32px;
}
.feature-item h3 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
}
.feature-item p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}
.landing-demo {
  border-top: 1px solid var(--line);
  background: #e8efe6;
}
.demo-accounts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}
.demo-chip {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 14px 14px;
  min-height: var(--touch);
  transition: border-color 0.15s, transform 0.15s;
}
.demo-chip:hover {
  border-color: var(--brand);
  transform: translateY(-1px);
}
.demo-chip strong {
  display: block;
  font-size: 13px;
  font-family: ui-monospace, Consolas, monospace;
}
.demo-chip span {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}
.landing-foot {
  padding: 22px clamp(16px, 5vw, 56px) 36px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line);
  background: #e4ebe2;
}

/* ===== Login (split panel on desktop) ===== */
.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  background: #0a2418;
}
.login-visual {
  position: relative;
  padding: clamp(24px, 4vw, 48px);
  color: #f4faf6;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  isolation: isolate;
}
.login-visual::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 60% 50% at 70% 20%, rgba(212, 168, 75, 0.28), transparent 55%),
    linear-gradient(155deg, #0a2418, #146b42 55%, #0f3d28);
}
.login-visual .brand {
  font-family: var(--display);
  font-size: clamp(32px, 4vw, 48px);
  font-weight: 700;
  line-height: 1.05;
  margin: 0;
}
.login-visual .tagline {
  margin: 10px 0 0;
  max-width: 28ch;
  opacity: 0.85;
  line-height: 1.5;
  font-size: 15px;
}
.login-visual .meta {
  font-size: 12px;
  opacity: 0.65;
}
.login-panel {
  background: #f7faf6;
  color: var(--ink);
  display: grid;
  place-items: center;
  padding: 28px 20px;
}
.login-card {
  width: min(400px, 100%);
  animation: rise 0.45s ease both;
}
.login-card h1 {
  font-family: var(--display);
  font-size: 28px;
  margin: 0 0 6px;
  font-weight: 700;
}
.login-card .hint {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 18px;
  line-height: 1.5;
}
.card > p.hint {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 12px;
  line-height: 1.45;
}
.login-card .field input {
  min-height: var(--touch);
  font-size: 16px; /* iOS zoom-safe */
}
.pass-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.pass-row button {
  border: 0;
  background: transparent;
  color: var(--brand);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 0;
  min-height: 32px;
}
.login-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.login-actions .btn {
  min-height: var(--touch);
  padding: 10px 16px;
  flex: 1 1 auto;
}
.login-demo-label {
  margin: 20px 0 8px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.login-top-mobile {
  display: none;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

/* ===== App shell + mobile drawer (single scroll surface) ===== */
html:has(.app-shell),
body:has(.app-shell) {
  height: 100%;
  overflow: hidden;
}
.app-shell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  overflow: hidden;
}
.sidebar {
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: #e8f2eb;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 30;
}
.side-brand {
  padding: 18px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.side-brand strong {
  display: block;
  font-family: var(--display);
  font-size: 18px;
  line-height: 1.25;
}
.side-brand span {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  opacity: 0.65;
}
.side-lang {
  padding: 10px 12px 0;
}
.side-nav {
  padding: 10px 10px 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.nav-group-label {
  margin: 12px 10px 6px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.45;
}
.side-nav button {
  border: 0;
  background: transparent;
  color: rgba(232, 242, 235, 0.78);
  text-align: left;
  padding: 11px 12px;
  min-height: 40px;
  border-radius: 10px;
  font-size: 13px;
}
.side-nav button:hover { background: rgba(255,255,255,0.06); color: #fff }
.side-nav button.active {
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}
.side-foot {
  padding: 12px 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.side-foot .btn {
  min-height: 40px;
  justify-content: center;
}
.workspace {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, #f7faf6 0%, var(--bg) 180px);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(8px);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}
.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}
.topbar .sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.menu-toggle {
  display: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  min-width: var(--touch);
  min-height: var(--touch);
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8, 20, 14, 0.45);
  z-index: 25;
}
.main {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 16px 20px;
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
/* Sheet pages: only the grid scrolls horizontally/vertically inside one pane */
.main.sheet-mode {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: none;
  padding-bottom: 12px;
}
.main.sheet-mode > .msg {
  flex-shrink: 0;
}
.main.sheet-mode > .grid {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.main.sheet-mode > .grid > .page-head {
  flex-shrink: 0;
  margin-bottom: 0;
}
.main.sheet-mode > .grid > .card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 10px 12px;
}
.main.sheet-mode .mkt-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.main.sheet-mode .mkt-wrap > .tabs,
.main.sheet-mode .mkt-wrap > .mkt-toolbar,
.main.sheet-mode .mkt-wrap > .mkt-note {
  flex-shrink: 0;
}
.main.sheet-mode .mkt-scroll {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
}
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.page-head h2 {
  margin: 0;
  font-size: 20px;
  font-family: var(--display);
}
.page-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.grid { display: grid; gap: 12px }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)) }
.grid.two { grid-template-columns: 1fr 1fr }
.grid.three { grid-template-columns: repeat(3, 1fr) }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card h2, .card h3 { margin: 0 0 10px; font-size: 15px }
.stat .n { font-size: 24px; font-weight: 700; color: var(--brand) }
.stat .l { font-size: 12px; color: var(--muted) }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: end }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 120px; flex: 1 }
.field label { font-size: 11px; color: var(--muted); font-weight: 600 }
.field input, .field select, .field textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  min-height: 40px;
}
.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: #e7eee8;
  color: var(--ink);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-primary { background: var(--brand); color: #fff }
.btn-primary:hover { background: var(--brand-dark) }
.btn-warn { background: var(--warn); color: #fff }
.btn-ghost {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  color: inherit;
}
.workspace .btn-ghost, .login-panel .btn-ghost {
  border-color: var(--line);
  color: var(--ink);
}
.btn-light {
  background: #fff;
  color: var(--brand-dark);
  border: 0;
}
.btn-outline-light {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.45);
}
.msg { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; font-size: 13px }
.msg.err { background: #fdecea; color: var(--danger) }
.msg.ok { background: #e8f7ee; color: var(--ok) }
.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  -webkit-overflow-scrolling: touch;
}
.table-wrap::after {
  content: "";
}
table { width: 100%; border-collapse: collapse; font-size: 12px }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top }
th { background: #f4f8f5; color: var(--muted); font-weight: 600; white-space: nowrap }
.mono { font-family: ui-monospace, Consolas, monospace }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 11px;
}
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px }
.tabs button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 36px;
  font-size: 12px;
}
.tabs button.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}
.empty { color: var(--muted); padding: 20px; text-align: center }
.quick-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.quick-links button {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 14px;
  min-height: 72px;
}
.quick-links button strong { display: block; font-size: 14px; margin-bottom: 4px }
.quick-links button span { font-size: 12px; color: var(--muted) }
.quick-links button:hover { border-color: var(--brand); background: var(--brand-soft) }

@keyframes rise {
  from { opacity: 0; transform: translateY(12px) }
  to { opacity: 1; transform: none }
}
@keyframes drift {
  from { transform: translate3d(0, 0, 0) }
  to { transform: translate3d(-40px, 20px, 0) }
}

/* ===== Mobile tab bar + real phone layout ===== */
.mobile-tabbar {
  display: none;
}
.desk-only { display: inline-flex; }

@media (max-width: 900px) {
  .desk-only { display: none !important; }
  .menu-toggle { display: none; } /* use bottom "More" instead */

  .mobile-tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
    background: #0a2418;
    color: #e8f2eb;
    border-top: 1px solid rgba(255,255,255,0.12);
    padding: 4px 2px calc(4px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -8px 24px rgba(0,0,0,0.18);
  }
  .mobile-tabbar button {
    border: 0;
    background: transparent;
    color: rgba(232, 242, 235, 0.72);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 52px;
    font-size: 10px;
    font-weight: 600;
    padding: 4px 2px;
  }
  .mobile-tabbar button .tab-ico {
    font-size: 16px;
    line-height: 1;
  }
  .mobile-tabbar button.active {
    color: #fff;
  }
  .mobile-tabbar button.active .tab-ico {
    color: var(--accent-2, #e8c56a);
  }

  .app-shell {
    padding-bottom: calc(58px + env(safe-area-inset-bottom, 0px));
  }
  .workspace {
    min-height: calc(100dvh - 58px - env(safe-area-inset-bottom, 0px));
  }

  /* Dedicated login page: full-screen single column */
  body.entry-login .login-wrap {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }
  body.entry-login .login-visual { display: none; }
  body.entry-login .login-top-mobile { display: flex; }
  body.entry-login .login-panel {
    min-height: 100dvh;
    align-content: start;
    padding: 16px 16px calc(24px + env(safe-area-inset-bottom, 0px));
    background: #f7faf6;
  }
  body.entry-login .login-card {
    width: 100%;
    max-width: 420px;
  }
  body.entry-login .login-card .field input {
    font-size: 16px;
    min-height: 48px;
  }
  body.entry-login .login-actions .btn {
    min-height: 48px;
    flex: 1 1 100%;
  }
  body.entry-login .demo-chip {
    min-height: 52px;
  }

  .tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding-bottom: 4px;
  }
  .tabs button {
    flex: 0 0 auto;
    min-height: 40px;
    white-space: nowrap;
  }

  .main.sheet-mode .mkt-scroll {
    max-height: calc(100dvh - 220px - env(safe-area-inset-bottom, 0px));
    overflow: auto;
    border-radius: 10px;
  }
  .mkt-scroll::before {
    content: none;
  }
}

@media (max-width: 900px) {
  .login-wrap { grid-template-columns: 1fr }
  .login-visual { display: none }
  .login-top-mobile { display: flex }
  .login-panel { min-height: 100vh; align-content: start; padding-top: 20px }

  html:has(.app-shell),
  body:has(.app-shell) {
    height: auto;
    overflow: auto;
  }
  .app-shell {
    display: block;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(300px, 86vw);
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: 8px 0 28px rgba(0,0,0,0.2);
    z-index: 40;
  }
  .app-shell.nav-open .sidebar { transform: none }
  .app-shell.nav-open .nav-backdrop { display: block }
  .workspace {
    height: auto;
    min-height: calc(100dvh - 58px);
    overflow: visible;
  }
  .main {
    overflow: visible;
    max-width: none;
    padding-bottom: 12px;
  }
  .main.sheet-mode {
    overflow: visible;
    height: auto;
  }
  .main.sheet-mode > .grid,
  .main.sheet-mode > .grid > .card,
  .main.sheet-mode .mkt-wrap {
    display: block;
    height: auto;
    min-height: 0;
    overflow: visible;
  }
  .grid.two, .grid.three { grid-template-columns: 1fr }
  .topbar h1 { font-size: 15px }
  .main { padding: 12px 12px 16px }
  .landing-hero { align-content: end; padding-bottom: 48px }
  .hero-brand { max-width: 11ch }
}

@media (max-width: 520px) {
  .landing-actions .btn-outline-light { display: none }
  .demo-accounts { grid-template-columns: 1fr }
  .stat .n { font-size: 20px }
  .quick-links { grid-template-columns: 1fr 1fr }
}

/* Wide sheet tables stay scrollable on phones */
@media (max-width: 900px) {
  .mkt-scroll, .table-wrap {
    max-width: 100%;
  }
}
