:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --ink: #1c2430;
  --muted: #677284;
  --line: #dfe5ee;
  --blue: #2563eb;
  --cyan: #0891b2;
  --green: #16a34a;
  --yellow: #ca8a04;
  --red: #dc2626;
  --shadow: 0 18px 45px rgba(38, 54, 77, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: #0f172a;
  color: #e5edf8;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #38bdf8;
  color: #06101f;
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 3px;
  color: #9fb0c7;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #c6d3e5;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: #1d2b45;
  color: #ffffff;
}

.side-card {
  margin-top: auto;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.side-card span,
.side-card small {
  display: block;
  color: #a9b8cd;
}

.side-card strong {
  display: block;
  margin: 12px 0 4px;
  font-size: 38px;
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 14px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
}

h2 {
  font-size: 20px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.auth-card span {
  max-width: 180px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-card.signed-in span {
  color: #0f766e;
}

.auth-card .ghost-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.primary-button,
.ghost-button,
.icon-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.primary-button {
  padding: 0 18px;
  background: var(--blue);
  color: #ffffff;
  font-weight: 700;
}

.ghost-button {
  padding: 0 16px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  width: 40px;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 18px;
}

.metric-card span,
.metric-card small {
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 12px 0 6px;
  font-size: 34px;
}

.metric-card.risk strong {
  color: var(--red);
}

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.9fr);
  gap: 18px;
}

.panel {
  padding: 20px;
}

.panel.wide {
  grid-row: span 2;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.panel-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.ranking-list,
.risk-list,
.ai-cards,
.sync-grid,
.module-list {
  display: grid;
  gap: 12px;
}

.rank-row {
  display: grid;
  grid-template-columns: 44px 1fr 86px;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.module-row {
  display: grid;
  grid-template-columns: 88px 1fr 54px;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.module-row:last-child {
  border-bottom: 0;
}

.module-name {
  color: #334155;
  font-weight: 800;
}

.module-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2e8f0;
}

.module-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0891b2, #16a34a);
}

.module-rate {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.rank-no {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  background: #e0f2fe;
  color: #075985;
  font-weight: 800;
}

.rank-main strong,
.rank-main span {
  display: block;
}

.rank-main span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.score-pill,
.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #ecfdf5;
  color: #047857;
  font-weight: 800;
}

.bar-chart {
  display: grid;
  align-items: end;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  min-height: 250px;
}

.bar-item {
  display: grid;
  align-content: end;
  gap: 8px;
  min-width: 0;
  height: 250px;
  text-align: center;
}

.bar {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 18px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, #0ea5e9, #2563eb);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  padding-top: 8px;
}

.bar-label {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.risk-item,
.ai-card,
.sync-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
}

.risk-item strong,
.risk-item span,
.ai-card strong,
.ai-card span {
  display: block;
}

.risk-item span,
.ai-card span {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.5;
}

.readiness-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.readiness-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
}

.readiness-card div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.readiness-card strong {
  color: #111827;
}

.readiness-card span {
  flex: none;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 800;
  line-height: 24px;
}

.readiness-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.storage-status {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.storage-status div {
  display: grid;
  gap: 6px;
  min-height: 74px;
  padding: 14px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fbfcff;
}

.storage-status div:nth-child(4n) {
  border-right: 0;
}

.storage-status div:nth-last-child(-n + 4) {
  border-bottom: 0;
}

.storage-status span {
  color: var(--muted);
  font-size: 13px;
}

.storage-status strong {
  font-size: 16px;
  overflow-wrap: anywhere;
}

.form {
  display: grid;
  gap: 18px;
}

.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.section-title h3 {
  margin: 0;
  font-size: 18px;
}

.section-title p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.section-title span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 800;
}

.form-grid,
.split-fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.form-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.split-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.checklist-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.check-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
}

.check-item input {
  width: 18px;
  min-height: 18px;
  margin-top: 2px;
}

.check-main strong,
.check-main span {
  display: block;
}

.check-main span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.priority-badge {
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  font-size: 12px;
  font-weight: 800;
}

label {
  display: grid;
  gap: 8px;
  color: #111827;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfd7e3;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 110px;
  padding: 12px;
  resize: vertical;
  line-height: 1.5;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

th,
td {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8fafc;
  color: #475569;
  font-size: 13px;
}

td {
  line-height: 1.45;
}

.compact-table table {
  min-width: 1080px;
}

.cell-input,
.cell-select,
.cell-textarea {
  min-height: 36px;
  border-radius: 6px;
  font-size: 14px;
}

.cell-input,
.cell-select {
  padding: 0 8px;
}

.cell-textarea {
  min-height: 54px;
  padding: 8px;
}

.opportunity-name {
  min-width: 140px;
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

.status-closed {
  background: #f1f5f9;
  color: #475569;
}

.editable-table {
  border-radius: 6px;
  background: #ffffff;
}

.editable-table table {
  min-width: 1220px;
}

.editable-table th,
.editable-table td {
  border-right: 1px solid var(--line);
}

.editable-table th:last-child,
.editable-table td:last-child {
  border-right: 0;
}

.editable-table th {
  height: 40px;
  padding: 0 10px;
  background: #f8fafc;
  white-space: nowrap;
}

.editable-table td {
  height: 42px;
  padding: 0 10px;
}

.sheet-cell {
  position: relative;
  max-width: 260px;
  cursor: cell;
  white-space: nowrap;
}

.sheet-cell:focus,
.sheet-cell:hover {
  outline: 2px solid #2563eb;
  outline-offset: -2px;
  background: #eff6ff;
}

.sheet-cell span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet-editor {
  width: calc(100% + 20px);
  min-width: 120px;
  min-height: 42px;
  margin: 0 -10px;
  padding: 0 10px;
  border: 2px solid #2563eb;
  border-radius: 0;
  outline: 0;
  background: #ffffff;
  box-shadow: 0 8px 22px rgba(37, 99, 235, 0.18);
}

.sheet-editor-textarea {
  position: absolute;
  z-index: 4;
  top: -1px;
  left: -1px;
  width: max(260px, 100%);
  min-height: 96px;
  margin: 0;
  padding: 8px 10px;
  resize: both;
}

.ai-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.8fr);
  gap: 18px;
}

.weekly-summary {
  display: grid;
  gap: 16px;
  line-height: 1.7;
}

.weekly-summary h3 {
  margin: 0;
}

.weekly-summary ul {
  margin: 0;
  padding-left: 20px;
}

.sync-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.sync-note {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  background: #f0f9ff;
  color: #0f172a;
}

.sync-note span {
  color: #475569;
  line-height: 1.55;
}

.sync-card strong {
  display: block;
  margin-bottom: 8px;
}

.sync-card span {
  color: var(--muted);
}

dialog {
  width: min(560px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.dialog-form {
  display: grid;
  gap: 14px;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .side-card {
    display: none;
  }

  .metric-grid,
  .dashboard-layout,
  .ai-layout,
  .sync-grid,
  .readiness-grid,
  .storage-status {
    grid-template-columns: 1fr 1fr;
  }

  .panel.wide {
    grid-row: auto;
    grid-column: 1 / -1;
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .main {
    padding: 18px;
  }

  .topbar,
  .panel-head {
    display: grid;
  }

  h1 {
    font-size: 24px;
  }

  .nav,
  .metric-grid,
  .dashboard-layout,
  .ai-layout,
  .sync-grid,
  .readiness-grid,
  .storage-status,
  .form-grid,
  .form-grid.compact,
  .split-fields,
  .checklist-grid {
    grid-template-columns: 1fr;
  }

  .storage-status div,
  .storage-status div:nth-child(4n),
  .storage-status div:nth-last-child(-n + 4) {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .storage-status div:last-child {
    border-bottom: 0;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
