:root {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: #172033;
  background: #eef2f6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

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

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

.login-card,
.panel,
.table-panel,
.detail {
  background: #fff;
  border: 1px solid #d7e0e9;
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(23, 50, 77, 0.08);
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 24px;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: #17324d;
  font-weight: 800;
  background: #f4c95d;
  border-radius: 6px;
}

.brand span,
.muted,
td span {
  color: #6c7888;
}

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

label {
  display: grid;
  gap: 6px;
  color: #536172;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  color: #172033;
  background: #fff;
  border: 1px solid #c7d3df;
  border-radius: 6px;
}

textarea {
  min-height: 82px;
  resize: vertical;
}

.primary,
.secondary,
.danger,
.danger-soft,
.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  font-weight: 700;
}

.primary {
  color: #fff;
  background: #166e8f;
}

.secondary {
  color: #19324d;
  background: #dfe9f2;
}

.danger {
  color: #fff;
  background: #b42318;
}

.danger-soft {
  color: #b42318;
  background: #fff;
  border: 1px solid #f0b8b3;
}

.danger-soft:hover {
  background: #fff5f5;
}

.ghost {
  color: #dce6f2;
  background: transparent;
}

.error,
.toast {
  padding: 10px 12px;
  border-radius: 6px;
}

.error {
  color: #8a1f17;
  background: #fee2e2;
}

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 5;
  color: #17324d;
  background: #fff;
  border: 1px solid #c7d3df;
  box-shadow: 0 12px 30px rgba(23, 50, 77, 0.16);
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 8px;
  color: #e7edf5;
  background: #17324d;
}

.sidebar .brand {
  margin-bottom: 18px;
}

.sidebar .brand strong {
  font-size: 13px;
  line-height: 1.25;
}

.sidebar .brand span {
  font-size: 11px;
}

.sidebar .brand span,
.sidebar small {
  color: #b9c5d4;
}

.nav {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 6px;
  padding: 10px 8px;
  color: #dce6f2;
  background: transparent;
  border-radius: 6px;
}

.nav.active,
.nav:hover,
.ghost:hover {
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

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

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

h1,
h2,
p {
  margin: 0;
}

.actions,
.row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

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

.metric {
  padding: 16px;
  background: #fff;
  border: 1px solid #d7e0e9;
  border-radius: 8px;
}

.metric span {
  display: block;
  color: #6c7888;
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
}

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

.filters {
  display: grid;
  grid-template-columns: 2fr repeat(5, minmax(120px, 1fr));
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid #d7e0e9;
}

.table-wrap {
  overflow-x: scroll;
  overflow-y: auto;
  max-height: calc(100vh - 360px);
  min-height: 0;
  padding-bottom: 12px;
  scrollbar-gutter: stable;
}

.customer-table-wrap {
  height: auto;
}

.table-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-bottom: 1px solid #d7e0e9;
}

.table-tools label {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
}

.table-tools select {
  width: 90px;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 14px;
}

.resizable-table {
  min-width: 1900px;
}

.table-wrap::-webkit-scrollbar {
  height: 14px;
  width: 12px;
}

.table-wrap::-webkit-scrollbar-track {
  background: #e5ebf1;
  border-radius: 999px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: #8aa0b5;
  border: 3px solid #e5ebf1;
  border-radius: 999px;
}

.table-wrap::-webkit-scrollbar-thumb:hover {
  background: #60758b;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 11px 12px;
  text-align: left;
  color: #334155;
  background: #f4f7fa;
  border-bottom: 1px solid #d7e0e9;
}

.sort-header {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  color: inherit;
  font-weight: 700;
  background: transparent;
}

.sort-header span {
  min-width: 12px;
  color: #166e8f;
}

.resizable-table th {
  position: sticky;
}

.resizable-table th[draggable="true"] {
  cursor: grab;
}

.resizable-table th.dragging-column {
  opacity: 0.55;
  cursor: grabbing;
}

.resizable-table th.drag-over-column {
  background: #dff3fb;
  box-shadow: inset 3px 0 0 #166e8f;
}

.col-resizer {
  position: absolute;
  top: 0;
  right: -5px;
  width: 12px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  touch-action: none;
}

.col-resizer::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 5px;
  width: 2px;
  height: calc(100% - 16px);
  background: #c7d3df;
}

.col-resizer:hover,
body.is-resizing-column .col-resizer {
  background: rgba(22, 110, 143, 0.22);
}

body.is-resizing-column {
  cursor: col-resize;
  user-select: none;
}

td {
  padding: 12px;
  vertical-align: top;
  border-bottom: 1px solid #e5ebf1;
  overflow-wrap: anywhere;
}

td strong,
td span {
  display: block;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: #eef8fc;
}

.badge {
  display: inline-flex;
  min-width: 38px;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  color: #3d4755;
  background: #e8eef5;
  font-weight: 700;
}

.badge-A { color: #075985; background: #c9eefb; }
.badge-B { color: #166534; background: #d9f8df; }
.badge-C { color: #854d0e; background: #ffedbd; }
.badge-D { color: #7f1d1d; background: #fee2e2; }

.detail,
.panel {
  padding: 18px;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.detail-actions-top {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

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

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.info-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  background: #f8fafc;
  border: 1px solid #e5ebf1;
  border-radius: 6px;
}

.info-item span {
  color: #6c7888;
  font-size: 12px;
}

.info-item strong {
  min-height: 18px;
  font-weight: 500;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.span-2 {
  grid-column: span 2;
}

.wide {
  width: 100%;
  margin-top: 14px;
}

.notes-section {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #d7e0e9;
}

.contacts-section,
.contacts-editor {
  display: grid;
  gap: 10px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #d7e0e9;
}

.contact-list {
  display: grid;
  gap: 10px;
}

.contact-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
  background: #fff;
  border: 1px solid #d7e0e9;
  border-radius: 8px;
}

.contact-card.primary-contact {
  border-color: #8bb8c8;
  background: #f0f9fc;
}

.contact-card-title {
  grid-column: span 2;
  color: #166e8f;
  font-weight: 700;
}

.contact-editor-row {
  display: grid;
  grid-template-columns: 70px repeat(6, minmax(92px, 1fr)) 58px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.primary-radio {
  display: flex;
  align-items: center;
  gap: 4px;
}

.primary-radio input {
  width: auto;
  min-height: auto;
}

.notes-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.notes-title h3 {
  margin: 0;
  font-size: 16px;
}

.note-list {
  display: grid;
  gap: 10px;
}

.note-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid #d7e0e9;
  border-radius: 8px;
}

.note-card p {
  white-space: pre-wrap;
}

.note-meta,
.note-file {
  color: #6c7888;
  font-size: 12px;
  font-weight: 600;
}

.note-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}

.note-images img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid #c7d3df;
  border-radius: 6px;
}

.note-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.activity-workspace {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 16px;
}

.activity-filter-panel {
  align-self: start;
  display: grid;
  gap: 14px;
}

.sort-list {
  display: grid;
  gap: 8px;
}

.sort-line {
  justify-content: flex-start;
}

.activity-list {
  display: grid;
  gap: 12px;
}

.activity-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: #f8fafc;
  border: 1px solid #d7e0e9;
  border-radius: 8px;
}

.activity-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.activity-card-head strong,
.activity-card-head span {
  display: block;
}

.activity-card-head span {
  color: #6c7888;
  font-size: 13px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
  gap: 16px;
}

.user-form {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr 130px auto;
  gap: 10px;
  margin: 16px 0;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.user-card {
  display: grid;
  gap: 6px;
  padding: 14px;
  background: #f8fafc;
  border: 1px solid #d7e0e9;
  border-radius: 8px;
}

@media (max-width: 1180px) {
  .app,
  .workspace,
  .admin-grid,
  .activity-workspace {
    grid-template-columns: 1fr;
  }
  .filters,
  .metrics,
  .user-form {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 14px;
  }
  .topbar,
  .actions {
    display: grid;
  }
  .filters,
  .metrics,
  .form-grid,
  .info-grid,
  .contact-card,
  .user-form {
    grid-template-columns: 1fr;
  }
  .contact-card-title {
    grid-column: span 1;
  }
  .contact-editor-row {
    grid-template-columns: 1fr;
  }
  .span-2 {
    grid-column: span 1;
  }
}
