:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --line: #e6e8ec;
  --text: #1d2433;
  --muted: #667085;
  --blue: #2563eb;
  --blue-soft: #eff4ff;
  --green: #0f9f6e;
  --amber: #b7791f;
  --red: #d92d20;
  --shadow: 0 18px 50px rgba(29, 36, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  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: 256px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 20px 16px;
  border-right: 1px solid var(--line);
  background: #fff;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 40px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

.brand span,
.codex-box p,
.panel-header p,
.eyebrow,
.muted,
.field-meta {
  color: var(--muted);
}

.brand span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.nav button.active {
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 700;
}

.codex-box {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
}

.label,
.eyebrow {
  font-size: 12px;
  font-weight: 700;
}

.codex-box p {
  margin: 8px 0 12px;
  font-size: 13px;
  line-height: 1.5;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar,
.panel-header,
.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  margin-top: 6px;
  font-size: 28px;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.primary-button,
.ghost-button,
.danger-button,
.file-button,
.icon-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 14px;
}

.primary-button {
  background: var(--blue);
  color: #fff;
}

.ghost-button,
.file-button,
.icon-button {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.danger-button {
  background: #fff;
  border-color: #f2c6c2;
  color: var(--red);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  padding: 0;
  font-size: 22px;
}

.file-button input {
  display: none;
}

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

.metric {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

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

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

.main-panel,
.detail-panel {
  min-height: 520px;
}

.panel-header {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header.compact {
  padding: 16px;
}

.panel-header p {
  margin-top: 6px;
  font-size: 13px;
}

.filter-grid {
  display: grid;
  grid-template-columns: 1.3fr repeat(3, minmax(130px, 1fr)) auto;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.filter-grid input,
.filter-grid select,
.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
}

.table-wrap {
  overflow: auto;
}

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

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

th {
  position: sticky;
  top: 0;
  background: #fafbfc;
  color: var(--muted);
  font-weight: 700;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: var(--blue-soft);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f2f4f7;
  color: #344054;
  font-size: 12px;
  white-space: nowrap;
}

.badge.blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.badge.green {
  background: #ecfdf3;
  color: var(--green);
}

.badge.amber {
  background: #fffaeb;
  color: var(--amber);
}

.badge.red {
  background: #fef3f2;
  color: var(--red);
}

.detail-view {
  padding: 16px;
}

.empty {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.detail-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
}

.detail-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.kv {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
}

.kv span:first-child {
  color: var(--muted);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.chart-list,
.reminder-list {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.bar-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 56px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.bar-track {
  height: 8px;
  border-radius: 999px;
  background: #edf0f5;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.reminder-item {
  display: grid;
  gap: 5px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

dialog {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: 0 28px 80px rgba(29, 36, 51, 0.22);
}

dialog::backdrop {
  background: rgba(16, 24, 40, 0.34);
}

.dialog-card {
  padding: 20px;
}

.dialog-card.narrow {
  width: min(460px, calc(100vw - 28px));
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.form-grid.single {
  grid-template-columns: 1fr;
}

.form-field.full {
  grid-column: 1 / -1;
}

.form-field label {
  display: block;
  margin-bottom: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

.form-field textarea {
  min-height: 86px;
  resize: vertical;
}

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

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

.export-grid button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(247, 248, 250, 0.96);
}

.auth-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.auth-brand {
  padding: 0 0 6px;
}

.auth-card label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

.auth-card input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
}

.auth-card p {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.team-list {
  display: grid;
  gap: 10px;
  max-height: 260px;
  overflow: auto;
  padding: 4px 0;
}

.team-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #f8fafc;
}

.team-row div {
  display: grid;
  gap: 3px;
}

.team-row span {
  color: var(--muted);
  font-size: 12px;
}

.team-row button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 1180px) {
  .content-layout,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    min-height: auto;
  }
}

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

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

  .workspace {
    padding: 16px;
  }

  .topbar,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary-grid,
  .filter-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

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