:root {
  --ink: #17212b;
  --muted: #64717a;
  --line: #dfe7e5;
  --bg: #f4f6f7;
  --panel: #ffffff;
  --green: #1f4d46;
  --green-soft: #e8f1ef;
  --amber: #b7791f;
  --red: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-view {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: #eef3f2;
}

.login-view.hidden {
  display: none;
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 28px;
}

.login-card label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.login-card .input,
.login-card .btn {
  width: 100%;
}

.brand.compact {
  border-bottom: 0;
  padding-bottom: 6px;
  color: var(--ink);
}

.brand.compact .brand-subtitle {
  color: var(--muted);
}

.login-tip {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.wecom-login-hint {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid #cfe2dd;
  border-radius: 8px;
  background: #f2f8f6;
}

.wecom-login-title {
  color: var(--green);
  font-size: 14px;
  font-weight: 650;
}

.wecom-login-hint .muted {
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  background: #163b36;
  color: #fff;
  padding: 24px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #f5c26b;
  color: #163b36;
  font-weight: 800;
}

.brand-title {
  font-size: 17px;
  font-weight: 750;
}

.brand-subtitle {
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
}

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

.nav-item {
  height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  text-align: left;
  cursor: pointer;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
}

.main {
  margin-left: 248px;
  padding: 28px;
}

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

.mobile-pagebar {
  display: none;
}

.mobile-pagebar-title {
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

.topbar p {
  margin-top: 7px;
  color: var(--muted);
}

.user-chip {
  display: grid;
  gap: 4px;
  min-width: 160px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

.logout-btn {
  width: 100%;
  height: 28px;
  border: 1px solid #d6e0df;
  border-radius: 6px;
  background: #f7faf9;
  color: var(--green);
  cursor: pointer;
  font-size: 12px;
}

.view {
  display: none;
}

.hidden {
  display: none !important;
}

.view.active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric {
  min-height: 104px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

.metric-value {
  margin-top: 10px;
  color: var(--green);
  font-size: 30px;
  font-weight: 800;
}

.split {
  display: grid;
  grid-template-columns: 1.25fr 0.75fr;
  gap: 16px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.dashboard-actions {
  margin-bottom: 10px;
}

.input {
  height: 38px;
  min-width: 180px;
  border: 1px solid #ccd7db;
  border-radius: 8px;
  padding: 0 11px;
  background: #fff;
  color: var(--ink);
}

.btn,
.text-btn {
  height: 38px;
  border: 1px solid #cbd8d5;
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  color: var(--green);
  cursor: pointer;
}

.btn.primary {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.danger-btn {
  border-color: #e6c4c0;
  background: #fff5f4;
  color: var(--red);
}

.btn.disabled,
.btn:disabled {
  border-color: #d7dfe3;
  background: #eef2f4;
  color: #8a969e;
  cursor: not-allowed;
}

.btn.small {
  height: 30px;
  margin: 0 4px 4px 0;
  padding: 0 9px;
  font-size: 12px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
}

.pagination-summary {
  margin-right: auto;
  color: var(--muted);
}

.pagination-size,
.pagination-jump {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.pagination .input {
  width: 76px;
  min-width: 76px;
}

.text-btn {
  border: 0;
  background: var(--green-soft);
}

.badge {
  border-radius: 6px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 12px;
  padding: 6px 9px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid #ebeff1;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

td.wrap {
  min-width: 260px;
  white-space: normal;
  line-height: 1.45;
}

th {
  color: #4e5d65;
  font-weight: 650;
  background: #fafbfb;
}

.stack {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.risk {
  border: 1px solid #f0d9b5;
  border-radius: 8px;
  padding: 12px;
  background: #fff8ee;
}

.risk strong {
  display: block;
  margin-bottom: 5px;
}

.risk-group-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.risk-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

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

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

.amber {
  color: var(--amber);
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 18px;
}

.rule-grid label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.rule-grid .input {
  width: 100%;
}

.rule-note {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0 18px 18px;
}

.rule-note span {
  border-radius: 6px;
  background: #f1f4f5;
  color: #3b4a52;
  padding: 8px 10px;
  font-size: 13px;
}

.summary-preview {
  min-width: 220px;
  white-space: normal;
  line-height: 1.45;
}

.summary-preview strong {
  display: block;
  margin-bottom: 4px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(23, 33, 43, 0.18);
  padding: 24px;
}

.modal-card {
  width: min(760px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.compact-modal-card {
  width: min(520px, calc(100vw - 48px));
}

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

.summary-timeline {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.summary-item {
  border: 1px solid #e4ecea;
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfc;
}

.summary-item-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.summary-item p {
  margin-top: 6px;
  white-space: normal;
  line-height: 1.5;
}

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

.visit-location-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
}

.visit-location-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.visit-location-title {
  color: var(--green);
  font-size: 14px;
  font-weight: 650;
}

.visit-location-bar .btn {
  width: 100%;
  min-width: 0;
}

.full-span {
  grid-column: 1 / -1;
}

.compact-textarea {
  min-height: 110px;
}

.filter-hint {
  margin: -4px 0 12px;
  font-size: 13px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 18px;
}

.detail-item {
  border: 1px solid #e4ecea;
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.detail-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.detail-value {
  white-space: normal;
  line-height: 1.5;
}

.accompaniment-section {
  border-top: 1px solid var(--line);
}

.accompaniment-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 0;
}

.accompaniment-head h3 {
  margin: 0 0 4px;
}

.accompaniment-detail-grid {
  padding-top: 12px;
}

#visitAccompanimentForm {
  padding: 12px 18px 18px;
}

.users-layout {
  grid-template-columns: 1fr 1fr;
  margin-bottom: 16px;
}

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

.form-actions {
  display: flex;
  gap: 10px;
  padding: 0 18px 18px;
}

.import-box {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.textarea {
  min-height: 168px;
  width: 100%;
  border: 1px solid #ccd7db;
  border-radius: 8px;
  padding: 11px;
  resize: vertical;
  color: var(--ink);
  font: inherit;
  line-height: 1.5;
}

.table-input {
  min-width: 130px;
  width: 150px;
  height: 32px;
}

.mobile-opportunity-cards,
.mobile-record-cards {
  display: none;
  gap: 12px;
  padding: 14px;
}

.opportunity-card,
.record-card {
  border: 1px solid #dfe7e5;
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.opportunity-card-head,
.record-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.opportunity-card-title-wrap,
.record-card-title-wrap {
  min-width: 0;
}

.opportunity-card-title,
.record-card-title {
  margin: 0;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.35;
}

.opportunity-card-meta,
.record-card-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

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

.opportunity-card-item,
.record-card-item {
  min-width: 0;
}

.opportunity-card-item.full,
.record-card-item.full {
  grid-column: 1 / -1;
}

.opportunity-card-label,
.record-card-label {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.opportunity-card-value,
.record-card-value {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  white-space: normal;
  word-break: break-word;
}

.opportunity-card-value .summary-preview {
  min-width: 0;
}

.opportunity-card-actions,
.record-card-actions {
  margin-top: 12px;
}

.wide-input {
  min-width: 220px;
  width: 240px;
}

.file-input {
  width: 100%;
}

.proof-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  padding: 0 18px 18px;
}

.proof-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #d7e2e0;
  background: #f7faf9;
}

.proof-inline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.proof-thumb-button {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.proof-inline-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #d7e2e0;
  display: block;
}

.proof-preview-card {
  width: min(860px, calc(100vw - 32px));
}

.proof-preview-body {
  padding: 18px;
}

.proof-preview-image {
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border-radius: 8px;
  background: #f7faf9;
}

.green-text {
  color: var(--green);
  font-weight: 650;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  transform: translateY(20px);
  opacity: 0;
  border-radius: 8px;
  background: #17212b;
  color: #fff;
  padding: 12px 14px;
  transition: 0.2s ease;
  pointer-events: none;
}

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

@media (max-width: 1100px) {
  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .detail-grid,
  .visit-form-grid,
  .user-form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  body {
    background: #eef3f2;
  }

  .sidebar {
    position: sticky;
    inset: 0 0 auto 0;
    width: 100%;
    padding: 14px 12px 10px;
    z-index: 10;
  }

  .brand {
    padding-bottom: 12px;
  }

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

  .nav-item {
    height: 52px;
    padding: 0 12px;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
  }

  .main {
    margin-left: 0;
    padding: 16px 12px 28px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
  }

  .user-chip {
    width: 100%;
    min-width: 0;
  }

  body[data-current-view]:not([data-current-view="home"]) .user-chip {
    display: none;
  }

  body[data-current-view]:not([data-current-view="home"]) .sidebar,
  body[data-current-view]:not([data-current-view="home"]) .topbar {
    display: none;
  }

  body[data-current-view]:not([data-current-view="home"]) .mobile-pagebar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
  }

  body[data-current-view]:not([data-current-view="home"]) .mobile-pagebar .btn {
    width: auto;
    min-width: 96px;
  }

  body[data-current-view="home"] #dashboardView {
    display: none;
  }

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

  .metric {
    min-height: 90px;
    padding: 14px;
  }

  .metric-value {
    font-size: 24px;
  }

  .actions,
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .pagination {
    justify-content: flex-start;
    padding: 14px;
  }

  .pagination-summary {
    width: 100%;
  }

  .pagination .btn {
    width: auto;
  }

  .input,
  .btn,
  .text-btn {
    width: 100%;
    min-width: 0;
  }


  .rule-grid,
  .users-layout,
  .visit-form-grid,
  .user-form-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .modal {
    padding: 12px;
  }

  .modal-card {
    width: 100%;
    max-height: calc(100vh - 24px);
  }

  .mobile-opportunity-cards,
  .mobile-record-cards {
    display: grid;
  }

  .opportunity-table-wrap {
    display: none;
  }

  .customer-table-wrap,
  .visit-table-wrap {
    display: none;
  }

  .opportunity-card-grid,
  .record-card-grid {
    grid-template-columns: 1fr;
  }
}

#mobileHomeButton,
#closeVisitCreateModal {
  border-color: #e5c56a;
  background: #f5c96c;
  color: #214842;
  font-weight: 700;
}

#mobileHomeButton:hover,
#closeVisitCreateModal:hover {
  background: #efbe56;
}
