:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #17211f;
  --muted: #687470;
  --line: #dde5e2;
  --accent: #0f8b75;
  --accent-dark: #086653;
  --warn: #c7801d;
  --danger: #c84b42;
  --success: #198754;
  --shadow: 0 14px 38px rgba(18, 33, 29, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 Arial, "Microsoft YaHei", sans-serif;
}
a { color: inherit; text-decoration: none; }
input, select, textarea, button {
  font: inherit;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 139, 117, .12);
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 18px;
  background: #13201d;
  color: #e9f3ef;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 22px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.brand span, .sidebar-user small { display: block; color: #9db4ae; font-size: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}
.brand-mark.large {
  width: 54px;
  height: 54px;
  margin: 0 auto 12px;
  font-size: 18px;
}
.sidebar nav {
  display: grid;
  gap: 6px;
  margin-top: 24px;
}
.sidebar nav a {
  padding: 11px 12px;
  border-radius: 8px;
  color: #c7d8d3;
}
.sidebar nav a.active, .sidebar nav a:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
}
.sidebar-user {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,.1);
}
.sidebar-user a {
  display: block;
  margin-top: 10px;
  color: #99f0d7;
}
.main {
  padding: 28px;
  min-width: 0;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 3px; font-size: 28px; line-height: 1.18; }
h2 { margin-bottom: 14px; font-size: 17px; }
h3 { margin-bottom: 8px; font-size: 14px; }
.topbar p { margin-bottom: 0; color: var(--muted); }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 15px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.button:hover { background: var(--accent-dark); }
.button.subtle {
  background: #e8f2ef;
  color: var(--accent-dark);
}
.button.subtle:hover { background: #d7ebe5; }
.button.danger {
  background: var(--danger);
  color: #fff;
}
.button.danger:hover { background: #a93b34; }
.button.full { width: 100%; }
.actions { display: flex; gap: 10px; align-items: center; }
.delete-form { margin: 0; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat, .panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.stat {
  padding: 18px;
}
.stat span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}
.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}
.stat.warn strong { color: var(--warn); }
.stat.success strong { color: var(--success); }
.panel {
  padding: 18px;
  margin-bottom: 18px;
}
.panel.compact { max-width: 720px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel-head a, .table-link { color: var(--accent-dark); font-weight: 700; }
.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}
.customer-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, .95fr);
  gap: 18px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table th {
  color: var(--muted);
  font-size: 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
}
.data-table td {
  border-bottom: 1px solid #edf1ef;
  padding: 13px 8px;
  vertical-align: middle;
}
.data-table td span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}
.data-table .need-cell {
  max-width: 230px;
  color: #243833;
  font-weight: 650;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.data-table tr.done { opacity: .55; }
.badge {
  display: inline-flex;
  min-width: 68px;
  justify-content: center;
  padding: 4px 9px;
  border-radius: 999px;
  background: #eef3f1;
  color: #52605c;
  font-size: 12px;
  font-weight: 700;
}
.badge.contacted, .badge.quoted { background: #e8f2ff; color: #236099; }
.badge.won, .badge.active { background: #e4f6ec; color: #147447; }
.badge.lost, .badge.blocked { background: #fdebea; color: #ad3d35; }
.badge.candidate { background: #fff5e6; color: #9b6418; }
.badge.paused { background: #eef3f1; color: #52605c; }

.filters, .inline-form {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}
.filters input { max-width: 420px; }
.filters select { max-width: 180px; }
.task-list { display: grid; gap: 10px; }
.task-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.task-row span { display: block; color: var(--muted); font-size: 12px; }
.task-row time { color: var(--muted); white-space: nowrap; }
.task-row.overdue time { color: var(--danger); font-weight: 700; }
.pipeline { display: grid; gap: 14px; }
.pipeline-row {
  display: grid;
  grid-template-columns: 84px 1fr 90px;
  gap: 10px;
  align-items: center;
}
.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eeee;
}
.bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}
.details {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 9px 14px;
}
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.note {
  min-height: 78px;
  padding: 12px;
  border-radius: 8px;
  background: #f6f9f8;
}
.stack-form, .customer-form { display: grid; gap: 12px; }
.customer-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
label { display: grid; gap: 6px; color: var(--muted); font-weight: 700; }
label input, label select, label textarea { color: var(--ink); font-weight: 400; }
.wide { grid-column: 1 / -1; }
.two {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 10px;
}
.mini {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.timeline {
  display: grid;
  gap: 12px;
}
.timeline div {
  padding-left: 12px;
  border-left: 3px solid #d6e8e2;
}
.timeline time {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.opportunity {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
}
.opportunity span { color: var(--muted); }
.kanban {
  display: grid;
  grid-template-columns: repeat(6, minmax(190px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 10px;
}
.kanban-col {
  min-height: 420px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.kanban-col h2 {
  font-size: 14px;
  color: var(--muted);
}
.deal-card {
  display: grid;
  gap: 5px;
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid #dce8e4;
  border-radius: 8px;
  background: #fbfdfc;
}
.deal-card span { color: var(--muted); font-size: 12px; }
.deal-card em { color: var(--accent-dark); font-style: normal; font-weight: 800; }
.check {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--accent);
  font-weight: 800;
  cursor: pointer;
}
.flash {
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #eef7f4;
  color: var(--accent-dark);
  border: 1px solid #cbe6dd;
}
.flash.error {
  background: #fff0ef;
  color: var(--danger);
  border-color: #f3c7c3;
}
.empty { color: var(--muted); margin-bottom: 0; }
.external-link { color: var(--accent-dark); text-decoration: underline; text-underline-offset: 2px; }
.external-link:hover { color: var(--accent); }

.csv-upload-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}
.csv-upload-control { min-width: 0; }
.csv-dropzone {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 12px 14px;
  border: 1px dashed #a9c9c0;
  border-radius: 8px;
  background: #f8fcfb;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.csv-dropzone:hover, .csv-dropzone.is-dragging {
  border-color: var(--accent);
  background: #edf8f4;
}
.csv-dropzone-title { color: var(--accent-dark); font-weight: 700; }
.csv-dropzone-hint { color: var(--muted); }
.csv-dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.csv-file-name {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.csv-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding-top: 4px;
}
.csv-clear-button {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}
.csv-clear-button:hover:not(:disabled) {
  color: var(--danger);
  background: #fff0ee;
}
.csv-clear-button:disabled {
  visibility: hidden;
  pointer-events: none;
}
.csv-upload-error { color: var(--danger); font-size: 13px; }

.table-thumb {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
}
.thumb-placeholder {
  display: inline-grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f7faf9;
}
.image-upload-block {
  display: grid;
  gap: 8px;
}
.help-text {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.supplier-image-preview img,
.supplier-image-card img {
  max-width: 280px;
  max-height: 200px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
}
.supplier-image-card {
  margin-bottom: 16px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #ecf4f1, #f8faf9);
}
.login-card, .setup-card {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}
.login-card {
  display: grid;
  gap: 13px;
}
.login-card h1, .login-card p { text-align: center; }
.login-card p { color: var(--muted); }
.setup-card {
  margin: 48px auto;
  width: min(720px, calc(100% - 32px));
}
code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #eef3f1;
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
  }
  .sidebar nav { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .sidebar-user { display: none; }
  .stats-grid, .dashboard-grid, .customer-layout, .customer-form {
    grid-template-columns: 1fr;
  }
  .main { padding: 18px; }
}

@media (max-width: 640px) {
  .topbar, .filters, .inline-form {
    align-items: stretch;
    flex-direction: column;
  }
  .actions { flex-wrap: wrap; }
  .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .data-table { display: block; overflow-x: auto; white-space: nowrap; }
  .csv-upload-form { grid-template-columns: 1fr; }
  h1 { font-size: 23px; }
}
