:root {
  --navy: #101827;
  --navy-2: #172033;
  --blue: #2563EB;
  --blue-2: #eaf3ff;
  --green: #16A34A;
  --yellow: #F59E0B;
  --red: #DC2626;
  --gray: #8a94a6;
  --line: #e7ebf2;
  --text: #152033;
  --muted: #687386;
  --bg: #F5F7FA;
  --panel: #ffffff;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.07);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

.login-mode {
  min-height: 100vh;
  background: radial-gradient(circle at top left, #dceaff 0, transparent 34%), var(--bg);
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(430px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(17, 31, 55, 0.14);
  padding: 30px;
}

.login-brand {
  color: var(--text);
  margin-bottom: 22px;
}

.login-brand small {
  color: var(--muted);
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.login-panel p {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.7;
}

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

.login-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.login-form input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  outline: 0;
}

.login-error {
  min-height: 22px;
  color: var(--red);
}

.demo-accounts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.demo-accounts button {
  border: 1px solid #b8d7ff;
  color: var(--blue);
  background: #fff;
  border-radius: 12px;
  padding: 9px 10px;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px 1fr;
}

.sidebar {
  color: #eaf1fb;
  background: linear-gradient(180deg, var(--navy), #071527);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand,
.profile-card,
.topbar,
.hero-strip,
.section-head,
.metric,
.customer-summary,
.modal-actions,
.primary-actions,
.top-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--blue);
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0;
}

.brand strong,
.profile-card strong {
  display: block;
}

.brand small,
.profile-card small {
  color: #99abc1;
}

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

.nav button {
  width: 100%;
  border: 0;
  border-radius: 8px;
  color: #d8e4f4;
  background: transparent;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.nav button.active,
.nav button:hover {
  background: var(--blue);
  color: #fff;
}

.nav .badge {
  margin-left: auto;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
}

.profile-card {
  margin-top: auto;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #dceaff;
  color: var(--blue);
  display: grid;
  place-items: center;
  font-weight: 800;
}

.workspace {
  min-width: 0;
}

.grid,
.panel,
.query-box,
.metric {
  min-width: 0;
}

.topbar {
  height: 64px;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.page-title {
  font-size: 20px;
  font-weight: 800;
  margin-left: 12px;
}

.top-actions {
  gap: 14px;
}

.role-switcher {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8fafc;
}

.role-tab {
  border: 0;
  color: var(--muted);
  background: transparent;
  padding: 8px 12px;
  border-radius: 7px;
}

.role-tab.active {
  color: #fff;
  background: var(--blue);
}

.search-lite {
  width: 260px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: #fff;
}

.search-lite input {
  width: 100%;
  border: 0;
  outline: 0;
}

.icon-button {
  border: 0;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #f3f6fb;
  color: var(--text);
  display: inline-grid;
  place-items: center;
}

.notification {
  position: relative;
}

.notification span {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
}

.hero-strip {
  justify-content: space-between;
  gap: 18px;
  padding: 24px 28px 12px;
}

.hero-strip h1 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: 0;
}

.hero-strip p {
  margin: 0;
  color: var(--muted);
}

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

.dashboard {
  padding: 0 28px 30px;
  display: grid;
  gap: 18px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.metrics-4 {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.grid.metrics-5 {
  grid-template-columns: repeat(5, minmax(150px, 1fr));
}

.grid.metrics-6 {
  grid-template-columns: repeat(6, minmax(150px, 1fr));
}

.grid.two {
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
}

.grid.three {
  grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.2fr) minmax(280px, 0.9fr);
}

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

.panel,
.query-box {
  padding: 18px;
}

.metric {
  min-height: 114px;
  padding: 18px;
  justify-content: space-between;
}

.metric strong {
  display: block;
  font-size: 31px;
  margin-top: 8px;
  letter-spacing: 0;
}

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

.metric-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
}

.metric-icon.blue { background: var(--blue); }
.metric-icon.green { background: var(--green); }
.metric-icon.yellow { background: var(--yellow); }
.metric-icon.gray { background: #9aa4b5; }
.metric-icon.red { background: var(--red); }
.metric-icon.purple { background: #7c5cff; }

.query-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.query-box h2,
.query-result {
  grid-column: 1 / -1;
}

.query-box input,
.filterbar input,
.filterbar select,
.state-editor input,
.state-editor select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  outline: 0;
}

.query-result {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.result-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.warning-text {
  color: #c77700;
}

h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

.panel h2 {
  font-size: 17px;
  margin-bottom: 14px;
}

.section-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.table-wrap {
  overflow: auto;
}

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

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

th {
  color: var(--muted);
  font-weight: 600;
  background: #fafbfd;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}

.tag.blue { color: #096bd8; background: #e7f1ff; }
.tag.green { color: #12805c; background: #def8ec; }
.tag.yellow { color: #9a6200; background: #fff1cf; }
.tag.gray { color: #657185; background: #eef1f5; }
.tag.red { color: #c02626; background: #ffe7e7; }

.primary,
.secondary,
.danger,
.ghost,
.text-button {
  border-radius: 8px;
  padding: 10px 16px;
  border: 1px solid transparent;
}

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

.secondary {
  color: var(--blue);
  background: #fff;
  border-color: #b8d7ff;
}

.danger {
  color: #c02626;
  background: #fff;
  border-color: #ffc8c8;
}

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

.text-button {
  border: 0;
  padding: 6px 8px;
  color: var(--blue);
}

.danger-text {
  color: var(--red);
}

.row-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 180px;
}

.row-actions .text-button {
  white-space: nowrap;
  background: #f8fbff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}

.row-actions .danger-text {
  background: #fff7f7;
  border-color: #fee2e2;
}

.wide {
  width: 100%;
}

.reminder-list,
.todo-list,
.rank-list,
.activity-list,
.source-list,
.audit-list {
  display: grid;
  gap: 12px;
}

.audit-block {
  display: grid;
  gap: 10px;
}

.audit-block + .audit-block {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.audit-block h4 {
  margin: 0;
  font-size: 15px;
}

.audit-block p {
  margin: 0;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  line-height: 1.7;
}

.audit-block p:last-child {
  border-bottom: 0;
}

.reminder-item,
.todo-item,
.rank-item,
.activity-item,
.source-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.rank-item > div:first-child,
.source-row > div:first-child,
.activity-item > div:first-child {
  min-width: 0;
  flex: 1;
}

.rank-item p,
.source-row p,
.activity-item p {
  margin-top: 4px;
}

.reminder-item:last-child,
.todo-item:last-child,
.rank-item:last-child,
.activity-item:last-child,
.source-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--blue);
  flex: 0 0 auto;
}

.todo-left,
.activity-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chart-donut {
  width: 176px;
  height: 176px;
  margin: 10px auto 18px;
  border-radius: 50%;
  background: conic-gradient(var(--blue) 0 50%, var(--green) 50% 65%, #aab3c2 65% 88%, var(--red) 88% 100%);
  display: grid;
  place-items: center;
}

.chart-donut div {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
  text-align: center;
  font-weight: 800;
}

.bar-chart {
  height: 210px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  align-items: end;
  padding: 14px 0 0;
}

.bar-group {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: end;
  gap: 6px;
  position: relative;
}

.bar-group span {
  width: 20px;
  border-radius: 5px 5px 0 0;
  background: var(--blue);
}

.bar-group span:last-child {
  background: var(--green);
}

.bar-group small {
  position: absolute;
  bottom: -22px;
  color: var(--muted);
}

.progress {
  width: 110px;
  height: 8px;
  border-radius: 999px;
  background: #edf1f6;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.filterbar {
  display: grid;
  grid-template-columns: 150px 150px 170px 1fr auto auto;
  gap: 10px;
  margin-bottom: 12px;
}

.filterbar.advanced {
  grid-template-columns: repeat(4, minmax(140px, 1fr)) minmax(220px, 1.4fr) auto auto;
  align-items: center;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 14px;
}

.pagination > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pagination button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.drawer,
.modal-backdrop {
  position: fixed;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 20;
}

.drawer.open,
.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  background: rgba(8, 19, 35, 0.28);
  display: flex;
  justify-content: flex-end;
}

.drawer-panel {
  width: min(720px, 100%);
  height: 100%;
  background: #fff;
  overflow: auto;
  box-shadow: -20px 0 40px rgba(8, 19, 35, 0.18);
}

.drawer-header {
  height: 62px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

.detail-grid {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.detail-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.customer-summary {
  align-items: flex-start;
  gap: 16px;
}

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

.customer-summary p {
  margin: 8px 0 0;
  color: var(--muted);
}

.owner-box {
  margin-left: auto;
  border: 1px dashed #bed8ff;
  background: var(--blue-2);
  padding: 12px;
  border-radius: 8px;
  min-width: 120px;
}

.owner-box.hidden {
  display: none;
}

.owner-box span,
.owner-box small {
  display: block;
  color: var(--muted);
}

.state-editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.state-editor label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  margin-bottom: 10px;
}

.timeline {
  padding-left: 0;
  margin: 0;
  list-style: none;
  display: grid;
  gap: 12px;
}

.timeline li {
  display: grid;
  grid-template-columns: 86px auto 1fr;
  gap: 10px;
  align-items: start;
  color: var(--muted);
}

.timeline time {
  color: var(--muted);
}

.action-zone {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-backdrop {
  background: rgba(8, 19, 35, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal {
  width: min(430px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border-radius: 10px;
  background: #fff;
  padding: 28px;
  position: relative;
  text-align: center;
  box-shadow: 0 24px 70px rgba(8, 19, 35, 0.3);
}

.modal.detail-modal {
  width: min(1120px, 100%);
  text-align: left;
}

.detail-modal .modal-icon {
  margin-left: 0;
  margin-right: 0;
}

.detail-modal .modal-body {
  color: var(--text);
}

.detail-view {
  display: grid;
  gap: 14px;
}

.detail-hero,
.detail-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 16px;
}

.detail-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  background: linear-gradient(180deg, #f8fbff 0%, #fff 100%);
}

.detail-hero h3 {
  margin: 0 0 6px;
  font-size: 20px;
}

.detail-hero p,
.detail-note {
  margin: 0;
  color: var(--muted);
}

.detail-metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
}

.detail-metric {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}

.detail-metric span,
.detail-field span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.detail-metric strong,
.detail-field strong {
  color: var(--text);
  font-size: 16px;
}

.detail-metric i {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--blue);
}

.detail-metric i.green {
  background: var(--green);
}

.detail-fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
}

.detail-field {
  min-width: 0;
  padding: 10px 0;
}

.detail-note {
  border-top: 1px solid var(--line);
  margin-top: 10px;
  padding-top: 12px;
  line-height: 1.7;
}

.detail-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.mini-table {
  overflow: auto;
}

.mini-table table {
  min-width: 620px;
}

.detail-timeline {
  display: grid;
  gap: 12px;
}

.timeline-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

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

.timeline-row time,
.timeline-row small {
  color: var(--muted);
  font-size: 12px;
}

.timeline-row p {
  margin: 6px 0;
  color: var(--text);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.modal-icon {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  background: #fff3cd;
  color: #c77700;
  font-size: 28px;
  font-weight: 900;
}

.modal p,
.modal-body {
  line-height: 1.7;
  color: var(--muted);
}

.customer-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  text-align: left;
  margin-top: 14px;
}

.customer-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

.customer-form input,
.customer-form select,
.customer-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  outline: 0;
}

.customer-form textarea {
  min-height: 82px;
  margin-bottom: 0;
}

.customer-form .span-2 {
  grid-column: 1 / -1;
}

.modal-actions {
  position: sticky;
  bottom: -28px;
  background: #fff;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
  padding-top: 12px;
}

@media (max-width: 1180px) {
  .grid.metrics-6,
  .grid.metrics-5,
  .grid.metrics-4 {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }

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

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

  .detail-split {
    grid-template-columns: 1fr;
  }

  .timeline-row {
    grid-template-columns: 1fr;
  }

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

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

  .sidebar {
    position: fixed;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: 232px;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .topbar,
  .hero-strip {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar {
    align-items: flex-start;
    height: auto;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .top-actions,
  .hero-strip {
    flex-direction: column;
    align-items: stretch;
  }

  .search-lite,
  .role-switcher {
    width: 100%;
  }

  .role-tab {
    flex: 1;
  }

  .dashboard {
    padding: 0 16px 24px;
  }

  .grid.metrics-6,
  .grid.metrics-5,
  .grid.metrics-4,
  .grid.two,
  .grid.three,
  .filterbar,
  .filterbar.advanced,
  .query-box,
  .state-editor {
    grid-template-columns: 1fr;
  }

  .pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .result-line,
  .customer-summary,
  .timeline li {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: flex-start;
  }

  .owner-box {
    margin-left: 0;
  }

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