:root {
  --bg: #0f1419;
  --panel: #1a212b;
  --panel-2: #222c38;
  --line: #2c3744;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #3b82f6;
  --ok: #22c55e;
  --wait: #f59e0b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 20px 14px;
  position: sticky; top: 0; align-self: flex-start;
  height: 100vh; overflow-y: auto; flex-shrink: 0;
}
.content { min-width: 0; }
.brand { font-size: 20px; font-weight: 700; margin-bottom: 24px; line-height: 1.2; }
.brand span { display: block; font-size: 12px; font-weight: 400; color: var(--muted); margin-top: 2px; }
.brand.center { text-align: center; }
nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; color: var(--muted); font-size: 14px;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item .ico { width: 20px; text-align: center; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; }
.logout {
  width: 100%; margin-top: 8px; padding: 8px; background: transparent;
  border: 1px solid var(--line); color: var(--muted); border-radius: 8px; cursor: pointer;
}
.logout:hover { color: var(--text); border-color: var(--muted); }

.content { flex: 1; padding: 32px 40px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.page-head h1 { margin: 0; font-size: 24px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card {
  display: flex; gap: 14px; align-items: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; padding: 18px;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card-ico { font-size: 28px; }
.card-body h3 { margin: 0 0 6px; font-size: 15px; }

.badge { font-size: 12px; padding: 3px 9px; border-radius: 99px; }
.badge-ok { background: rgba(34,197,94,.15); color: var(--ok); }
.badge-wait { background: rgba(245,158,11,.15); color: var(--wait); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; max-width: 760px; }
.notice {
  background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.3);
  border-radius: 8px; padding: 14px 16px; margin: 16px 0; font-size: 14px;
}
code { background: var(--panel-2); padding: 2px 6px; border-radius: 4px; font-size: 13px; }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 32px; display: flex; flex-direction: column; gap: 14px;
}
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 14px;
}
.btn-primary {
  padding: 11px; background: var(--accent); border: none; color: #fff;
  border-radius: 8px; font-size: 15px; cursor: pointer; margin-top: 4px;
}
.btn-primary:hover { background: #2563eb; }
.center { text-align: center; }
.form-error { color: #f87171; font-size: 13px; margin: 0; }

/* social module */
.badge-err { background: rgba(239,68,68,.15); color: #f87171; }
.badge-dim { background: var(--panel-2); color: var(--muted); }
.section-title { font-size: 15px; color: var(--muted); margin: 28px 0 12px; font-weight: 600; }
.back { color: var(--muted); font-size: 13px; }
.back:hover { color: var(--text); }

.stat-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 22px; min-width: 110px; display: flex; flex-direction: column; gap: 4px;
}
.stat-warn { border-color: rgba(239,68,68,.4); }
.stat-num { font-size: 24px; font-weight: 700; }
.stat-lbl { font-size: 12px; color: var(--muted); }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; background: var(--panel-2);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  font-size: 15px; flex-shrink: 0;
}
.chips { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.metrics-line { font-size: 12px; color: var(--muted); }

.post-list { display: flex; flex-direction: column; gap: 10px; max-width: 820px; }
.post-item { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.post-meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.post-meta a, .post-metrics a { color: var(--accent); }
.post-text { font-size: 14px; line-height: 1.5; }
.post-metrics { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* projects / data table */
.dist { display: flex; gap: 28px; flex-wrap: wrap; margin: 16px 0 8px; }
.dist-title { font-size: 12px; color: var(--muted); margin-right: 8px; }
.chip { display: inline-block; background: var(--panel-2); border-radius: 99px; padding: 3px 10px; font-size: 12px; margin: 0 6px 6px 0; }
.chip b { color: var(--accent); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }
.filters input, .filters select {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 13px;
}
.filters input { min-width: 240px; }
.filters .btn-primary { margin: 0; padding: 8px 18px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--bg); }
.data-table tbody tr:hover { background: var(--panel); }
.data-table .mono { font-family: ui-monospace, monospace; font-size: 12px; white-space: nowrap; }
.data-table .desc { max-width: 360px; color: var(--muted); }
.data-table .nowrap { white-space: nowrap; }

.pager { display: flex; gap: 16px; align-items: center; margin: 18px 0; }
.pager a { color: var(--accent); }

/* finance */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.data-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* tender intelligence */
.tab-link { margin-left: auto; color: var(--accent); font-size: 13px; }
.score { display: inline-block; min-width: 30px; text-align: center; padding: 2px 8px; border-radius: 6px; font-weight: 700; font-size: 12px; }
.score-high { background: rgba(34,197,94,.18); color: var(--ok); }
.score-medium { background: rgba(245,158,11,.18); color: var(--wait); }
.score-low { background: var(--panel-2); color: var(--muted); }

/* command center: priority actions + health cards */
.cmd-actions { margin-bottom: 24px; }
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 26px; }
.health-card { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: 12px; padding: 14px 16px; display: block; transition: transform .15s, border-color .15s; }
.health-card:hover { transform: translateY(-2px); }
.health-top { font-weight: 600; font-size: 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 7px; }
.health-line { font-size: 12px; color: var(--muted); line-height: 1.7; }
.health-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); }
.health-ok { border-left-color: var(--ok); }
.health-ok .health-dot { background: var(--ok); }
.health-warn { border-left-color: var(--wait); }
.health-warn .health-dot { background: var(--wait); }
.health-risk { border-left-color: #f87171; }
.health-risk .health-dot { background: #f87171; }

/* AI digest + ask */
.digest { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; margin-bottom: 24px; }
.digest-head { display: flex; align-items: baseline; gap: 12px; }
.digest-head .section-title { margin: 0 0 10px; }
.digest-summary { font-size: 15px; line-height: 1.6; margin: 4px 0 16px; }
.digest-items { display: flex; flex-direction: column; gap: 10px; }
.digest-item { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; background: var(--bg); border-radius: 8px; border-left: 3px solid var(--line); }
.digest-item.prio-high { border-left-color: #f87171; }
.digest-item.prio-medium { border-left-color: var(--wait); }
.digest-item .badge { flex-shrink: 0; }

.ask-form { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.ask-form textarea { padding: 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit; resize: vertical; }
.ask-form .btn-primary { align-self: flex-start; margin: 0; padding: 9px 22px; }
.ask-answer { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 16px; }
.answer-body { font-size: 15px; line-height: 1.65; margin-top: 8px; }

/* action items */
.actions { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.action-row { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.action-row.prio-high { border-left-color: #f87171; }
.action-row.prio-medium { border-left-color: var(--wait); }
.action-body { flex: 1; }
.action-btns { display: flex; gap: 6px; }
.mini-btn { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--muted); cursor: pointer; font-size: 14px; }
.mini-btn:hover { color: var(--text); border-color: var(--muted); }
.mini-btn.ok:hover { color: var(--ok); border-color: var(--ok); }

/* meeting extracted tasks */
.meeting-tasks { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.mtask { font-size: 13px; color: var(--text); background: var(--bg); border-radius: 6px; padding: 5px 10px; }
.meeting-summary { font-size: 13px; color: var(--muted); margin-top: 8px; line-height: 1.6; background: var(--bg); border-radius: 6px; padding: 8px 12px; }

/* manual sync button */
.sync-form { margin-left: auto; }
.sync-btn { background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 6px 14px; font-size: 13px; cursor: pointer; }
.sync-btn:hover { color: var(--text); border-color: var(--accent); }
.sync-btn:active { transform: translateY(1px); }

/* object forms (lead / opportunity) */
.obj-form .field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.obj-form .field-label { font-size: 13px; color: var(--muted); }
.obj-form input, .obj-form select, .obj-form textarea {
  padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit; width: 100%;
}
.obj-form .btn-primary { margin-top: 4px; }

.row-btn { background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.row-btn:hover { color: var(--accent); border-color: var(--accent); }

/* flash messages */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; border: 1px solid var(--line); }
.flash.success { background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.35); color: var(--ok); }
.flash.error { background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.35); color: #f87171; }
.mini-btn.danger:hover { color: #f87171; border-color: #f87171; }

/* ============ responsive / mobile ============ */
@media (max-width: 820px) {
  /* Never allow the whole page to scroll sideways */
  html, body { overflow-x: hidden; max-width: 100%; }

  /* Sidebar -> top bar; nav items WRAP onto multiple rows (no horizontal scroll) */
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; max-width: 100%; height: auto; position: static; overflow: visible;
    flex-direction: column; padding: 12px 14px;
    border-right: none; border-bottom: 1px solid var(--line);
  }
  .brand { margin-bottom: 10px; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .sidebar .nav-item {
    flex: 0 0 auto; padding: 7px 11px; font-size: 13px; border: 1px solid var(--line);
  }
  .sidebar .nav-item .ico { width: auto; }
  .sidebar-foot {
    margin-top: 10px; padding-top: 10px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  }
  .sidebar-foot form { margin-left: auto; }
  .logout { width: auto; margin-top: 0; }

  .content { padding: 16px; }
  .page-head { flex-wrap: wrap; gap: 8px; }
  .page-head h1 { font-size: 20px; }
  .sync-form, .tab-link { margin-left: 0; }

  /* Forms / filters fit narrow screens */
  .filters { gap: 8px; }
  .filters input, .filters select { min-width: 0; flex: 1 1 140px; width: auto; }
  .login-card { width: auto; max-width: 92vw; }

  /* Wide tables scroll horizontally instead of overflowing */
  .data-table { display: block; overflow-x: auto; white-space: nowrap; max-width: 100%; }

  /* Tables marked .cards become stacked cards (one card per row, label:value) */
  .data-table.cards { overflow-x: visible; white-space: normal; }
  .data-table.cards thead { display: none; }
  .data-table.cards, .data-table.cards tbody { display: block; }
  .data-table.cards tr {
    display: block; border: 1px solid var(--line); border-radius: 10px;
    padding: 6px 2px; margin-bottom: 10px; background: var(--panel);
  }
  .data-table.cards td {
    display: flex; justify-content: space-between; gap: 14px; align-items: baseline;
    border: none; padding: 6px 12px; text-align: right; white-space: normal;
  }
  .data-table.cards td::before {
    content: attr(data-label); color: var(--muted); font-size: 12px;
    flex: 0 0 auto; text-align: left;
  }
  .data-table.cards td.num { text-align: right; }
  .data-table.cards td:empty { display: none; }

  /* Stack the two-column blocks */
  .two-col { grid-template-columns: 1fr; }

  /* Tighter cards/stats */
  .stat { min-width: 0; flex: 1 1 calc(50% - 14px); padding: 12px 14px; }
  .stat-num { font-size: 20px; }
  .digest, .panel { padding: 16px; }
}
