:root {
  --bg: #f0f3f8;
  --bg-soft: #e8eef6;
  --surface: #ffffff;
  --text: #1a2332;
  --muted: #6b7a90;
  --line: #d7e0ec;
  --brand: #0c6e6b;
  --brand-dark: #085552;
  --brand-soft: #d9f2f0;
  --accent: #c45c26;
  --danger: #c0392b;
  --success: #1e7a46;
  --warning: #b8860b;
  --shadow: 0 10px 30px rgba(26, 35, 50, 0.08);
  --radius: 14px;
  --nav-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 10% -10%, #d9f2f0 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #f8e8dc 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--nav-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), #14918c);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; font-weight: 800;
}
.topbar-right { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.9rem; }
.market-switch {
  display: inline-flex; gap: 4px; padding: 3px;
  background: var(--bg-soft); border-radius: 999px; border: 1px solid var(--line);
}
.market-chip {
  padding: 5px 12px; border-radius: 999px; font-size: 0.82rem; font-weight: 700;
  color: var(--muted); text-decoration: none;
}
.market-chip:hover { color: var(--text); }
.market-chip.active {
  background: var(--brand); color: #fff;
}
.menu-btn {
  display: none; border: 0; background: var(--bg-soft); width: 40px; height: 40px;
  border-radius: 10px; cursor: pointer; font-size: 18px;
}

.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 16px 12px 80px;
}
.nav-group { margin-bottom: 18px; }
.nav-label {
  font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); padding: 0 10px; margin-bottom: 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--text); font-weight: 500; margin-bottom: 2px;
}
.nav-link:hover { background: var(--bg-soft); color: var(--text); }
.nav-link.active { background: var(--brand-soft); color: var(--brand-dark); }

.content {
  flex: 1; padding: 20px 20px calc(24px + var(--safe-bottom));
  max-width: 1200px; width: 100%;
}
.page-title {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}
.page-title h1 { margin: 0; font-size: 1.45rem; font-weight: 700; }
.page-sub { color: var(--muted); font-size: 0.92rem; margin-top: 4px; }

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px; margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-card .label { color: var(--muted); font-size: 0.86rem; }
.stat-card .value { font-size: 1.45rem; font-weight: 700; margin-top: 6px; }
.stat-card .hint { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.stat-card.positive .value { color: var(--success); }
.stat-card.negative .value { color: var(--danger); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.panel-hd {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-weight: 600;
}
.panel-bd { padding: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 9px 14px; font-size: 0.92rem; font-weight: 600;
  cursor: pointer; background: var(--bg-soft); color: var(--text);
  text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(0.98); color: inherit; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; border-color: var(--line); }
.btn-sm { padding: 6px 10px; font-size: 0.84rem; border-radius: 8px; }
.btn-block { width: 100%; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 0.86rem; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font: inherit; background: #fff; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(12,110,107,0.15);
}
.field-actions { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
  width: 100%; border-collapse: collapse; min-width: 640px; font-size: 0.92rem;
}
table.data th, table.data td {
  padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle;
}
table.data th {
  font-size: 0.8rem; color: var(--muted); font-weight: 700;
  background: #f7fafc; white-space: nowrap;
}
table.data tr:hover td { background: #fafcfe; }
.text-right { text-align: right !important; }
.text-center { text-align: center !important; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, Consolas, monospace; }

.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 999px; font-size: 0.75rem; font-weight: 700;
  background: var(--bg-soft); color: var(--muted);
}
.badge-open { background: #e8f5ff; color: #1a6ea8; }
.badge-closed { background: #fff4e5; color: #a35b00; }
.badge-settled { background: #e8f8ef; color: var(--success); }
.badge-won { background: #e8f8ef; color: var(--success); }
.badge-lost { background: #fdecea; color: var(--danger); }
.badge-void { background: #eef1f5; color: #5b6777; }
.badge-pending { background: #fff4e5; color: #a35b00; }

.ball {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  font-size: 0.78rem; font-weight: 800; color: #fff; margin-right: 4px;
}
.ball-red { background: #d64545; }
.ball-blue { background: #2f6fed; }
.ball-green { background: #1f9d5a; }
.ball-special { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }

.alert {
  padding: 12px 14px; border-radius: 12px; margin-bottom: 14px;
  border: 1px solid transparent; font-size: 0.92rem;
}
.alert-success { background: #e8f8ef; border-color: #b7e4c7; color: var(--success); }
.alert-error { background: #fdecea; border-color: #f5c6c2; color: var(--danger); }
.alert-info { background: #e8f5ff; border-color: #b8ddf5; color: #1a6ea8; }

.filters {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; align-items: end;
}
.filters .field { min-width: 140px; }

.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 18px;
  padding: 28px 24px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 6px; font-size: 1.4rem; }
.login-card .sub { color: var(--muted); margin-bottom: 20px; }

.empty {
  text-align: center; padding: 36px 16px; color: var(--muted);
}

.mobile-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  background: rgba(255,255,255,0.96);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + var(--safe-bottom));
  grid-template-columns: repeat(5, 1fr);
}
.mobile-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; font-size: 0.7rem; color: var(--muted); font-weight: 600;
}
.mobile-nav a.active { color: var(--brand); }
.mobile-nav .ico { font-size: 1.1rem; line-height: 1; }

.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 40;
}

@media (max-width: 1024px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 45;
    transform: translateX(-105%); transition: transform 0.2s ease;
    width: min(280px, 84vw); padding-top: calc(var(--nav-h) + 12px);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .content { padding: 14px 12px calc(78px + var(--safe-bottom)); }
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .form-grid, .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: 1fr; }
  .page-title h1 { font-size: 1.2rem; }
  .mobile-nav { display: grid; }
  .stat-card .value { font-size: 1.2rem; }
}

@media (max-width: 420px) {
  .cards { grid-template-columns: 1fr; }
}
