:root {
  --ink: #102a2a;
  --muted: #647575;
  --line: #dbe5e3;
  --soft: #f3f7f6;
  --panel: #ffffff;
  --teal: #0f766e;
  --teal-dark: #0b4f4a;
  --teal-soft: #def7f3;
  --blue: #2563eb;
  --amber: #b45309;
  --red: #b42318;
  --green: #16815f;
  --shadow: 0 18px 48px rgb(15 46 45 / 10%);
}

* { box-sizing: border-box; }
html { font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif; color: var(--ink); background: var(--soft); }
body { margin: 0; min-width: 320px; min-height: 100vh; font-size: 16px; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 32px 20px; background: radial-gradient(circle at 20% 15%, #dff7f2 0, transparent 32%), linear-gradient(135deg, #edf6f4 0%, #f8fbfa 58%, #e8f0ee 100%); }
.auth-card { width: min(100%, 440px); padding: 42px; border: 1px solid rgb(255 255 255 / 75%); border-radius: 24px; background: rgb(255 255 255 / 92%); box-shadow: var(--shadow); backdrop-filter: blur(14px); }
.brand-mark { display: grid; width: 54px; height: 54px; place-items: center; border-radius: 16px; color: white; background: linear-gradient(145deg, #11877d, #0b4f4a); font-size: 28px; font-weight: 800; box-shadow: 0 10px 24px rgb(15 118 110 / 24%); }
.brand-mark.small { width: 40px; height: 40px; border-radius: 12px; font-size: 20px; box-shadow: none; }
.auth-card .brand-mark { margin-bottom: 24px; }
.eyebrow { margin: 0 0 6px; color: var(--teal); font-size: .75rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.auth-card h1 { margin: 0; font-size: 2rem; letter-spacing: -.035em; }
.muted { color: var(--muted); }
.auth-card > .muted { margin: 8px 0 28px; }
.auth-foot { margin: 24px 0 0; color: #7b8a88; font-size: .8rem; text-align: center; }

.stack { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: #385150; font-size: .875rem; font-weight: 650; }
input, select, textarea { width: 100%; min-height: 44px; border: 1px solid #cbd9d7; border-radius: 10px; padding: 10px 12px; color: var(--ink); background: white; outline: none; transition: border .15s, box-shadow .15s; }
textarea { min-height: 90px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: #2d9c91; box-shadow: 0 0 0 3px rgb(45 156 145 / 15%); }
.button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 10px; padding: 9px 15px; color: #254240; background: white; font-weight: 700; text-decoration: none; transition: transform .1s, box-shadow .15s, background .15s; }
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.button.primary { color: white; background: var(--teal); box-shadow: 0 7px 18px rgb(15 118 110 / 18%); }
.button.primary:hover { background: #0c655e; }
.button.secondary { border-color: #cad9d6; background: white; }
.button.ghost { color: #48605e; background: transparent; }
.button.small { min-height: 34px; padding: 6px 11px; font-size: .85rem; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
.icon-button { width: 40px; height: 40px; border: 0; border-radius: 10px; color: #536967; background: transparent; font-size: 24px; }
.icon-button:hover { background: var(--soft); }
.notice { border-radius: 12px; padding: 12px 14px; font-size: .875rem; line-height: 1.55; }
.notice.info { color: #125f59; background: #e5f7f4; }
.notice.warning { color: #7c4a08; background: #fff4d6; }
.form-error { min-height: 20px; margin: 10px 0 0; color: var(--red); font-size: .85rem; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 244px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 22px 16px; color: #e8f8f5; background: linear-gradient(180deg, #103c3a 0%, #0b2f2e 100%); z-index: 20; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 26px; }
.sidebar-brand strong, .sidebar-brand small { display: block; }
.sidebar-brand strong { font-size: 1rem; }
.sidebar-brand small { margin-top: 2px; color: #91b9b5; font-size: .75rem; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 46px; border: 0; border-radius: 11px; padding: 10px 13px; color: #bdd6d3; background: transparent; font-weight: 650; text-align: left; }
.sidebar nav button span { width: 22px; color: #7fb8b1; font-size: 20px; text-align: center; }
.sidebar nav button:hover { color: white; background: rgb(255 255 255 / 7%); }
.sidebar nav button.active { color: white; background: rgb(28 171 157 / 20%); box-shadow: inset 3px 0 #2dd4bf; }
.sidebar-user { margin-top: auto; border: 1px solid rgb(255 255 255 / 9%); border-radius: 12px; padding: 12px; background: rgb(255 255 255 / 5%); }
.sidebar-user strong, .sidebar-user small { display: block; }
.sidebar-user small { margin-top: 3px; color: #91b9b5; }
.main-shell { min-width: 0; }
.topbar { min-height: 90px; display: flex; align-items: center; gap: 14px; border-bottom: 1px solid var(--line); padding: 17px 30px; background: rgb(255 255 255 / 88%); backdrop-filter: blur(14px); }
.topbar h1 { margin: 0; font-size: 1.45rem; letter-spacing: -.025em; }
.topbar .eyebrow { margin-bottom: 3px; }
.top-actions { margin-left: auto; display: flex; gap: 4px; }
.content { max-width: 1500px; min-height: calc(100vh - 90px); margin: 0 auto; padding: 30px; outline: none; }
.page-actions { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.page-actions h2 { margin: 0; font-size: 1.25rem; }
.page-actions p { margin: 5px 0 0; color: var(--muted); font-size: .9rem; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; }
.metric { position: relative; overflow: hidden; min-height: 124px; display: flex; flex-direction: column; justify-content: space-between; border: 1px solid var(--line); border-radius: 16px; padding: 20px; background: white; box-shadow: 0 7px 24px rgb(22 55 52 / 5%); }
.metric::after { content: ""; position: absolute; right: -23px; bottom: -39px; width: 105px; height: 105px; border-radius: 50%; background: var(--metric, #eef6f4); }
.metric span { color: var(--muted); font-size: .9rem; }
.metric strong { position: relative; z-index: 1; font-size: 1.8rem; letter-spacing: -.04em; }
.metric.warning { --metric: #fff0cf; }
.metric.blue { --metric: #e4edff; }
.metric.success { --metric: #dcf7ec; }
.dashboard-grid { display: grid; grid-template-columns: 1.2fr .9fr; gap: 18px; margin-top: 18px; }
.panel { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: 0 7px 24px rgb(22 55 52 / 4%); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 21px 0; }
.panel-head h3 { margin: 0; font-size: 1rem; }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: .82rem; }
.funnel { display: grid; gap: 20px; padding: 28px 22px 24px; }
.funnel span { display: flex; justify-content: space-between; font-size: .9rem; }
.funnel .bar { height: 9px; overflow: hidden; margin-top: 9px; border-radius: 999px; background: #edf2f1; }
.funnel i { display: block; height: 100%; min-width: 3px; border-radius: inherit; background: linear-gradient(90deg, var(--teal), #2dd4bf); }
.risk-list { padding: 13px 20px 20px; }
.risk-list button { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 18px; border: 0; border-bottom: 1px solid #edf2f1; padding: 15px 0; color: inherit; background: white; text-align: left; }
.risk-list button:last-child { border-bottom: 0; }
.risk-list b, .risk-list small { display: block; }
.risk-list small { margin-top: 3px; color: var(--muted); }
.risk-list time { flex: none; color: var(--amber); font-size: .83rem; }

.customer-panel { overflow: hidden; }
.filters { display: flex; align-items: center; gap: 14px; border-bottom: 1px solid var(--line); padding: 15px 18px; }
.filters input { width: min(300px, 100%); margin-left: auto; }
.filters > span { flex: none; color: var(--muted); font-size: .8rem; }
.stage-tabs { display: flex; gap: 5px; overflow-x: auto; }
.stage-tabs button { min-height: 38px; flex: none; border: 0; border-radius: 9px; padding: 7px 12px; color: #607572; background: transparent; font-weight: 650; }
.stage-tabs button.active { color: var(--teal-dark); background: var(--teal-soft); }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid #edf2f1; padding: 15px 18px; font-size: .875rem; text-align: left; vertical-align: middle; }
th { color: #617471; background: #fbfcfc; font-size: .78rem; font-weight: 750; letter-spacing: .025em; }
tbody tr[data-customer] { cursor: pointer; transition: background .12s; }
tbody tr[data-customer]:hover { background: #f8fbfa; }
td b, td small { display: block; }
td small { margin-top: 4px; color: var(--muted); font-size: .75rem; }
.pill { display: inline-flex; border-radius: 999px; padding: 4px 9px; font-size: .76rem; font-weight: 750; }
.stage-lead { color: #475569; background: #eef2f7; }
.stage-contacted { color: #075985; background: #e0f2fe; }
.stage-sample_following { color: #92400e; background: #fef3c7; }
.stage-won { color: #116149; background: #dcfce7; }
.warning-text { color: var(--amber); font-weight: 700; }
.empty { display: grid; place-items: center; gap: 7px; min-height: 130px; padding: 24px; color: #879693; text-align: center; }
.empty span { font-size: 24px; }
.empty p { margin: 0; }

.settings-grid { display: grid; grid-template-columns: 1.25fr .75fr; gap: 18px; }
.member-list { padding: 12px 18px 20px; }
.member { width: 100%; display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 12px; border: 0; border-bottom: 1px solid #edf2f1; padding: 13px 2px; color: inherit; background: white; text-align: left; }
.member:not(:disabled):hover { background: #f8fbfa; }
.member:disabled { cursor: default; }
.member b, .member small { display: block; }
.member small { margin-top: 3px; color: var(--muted); }
.avatar { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 12px; color: var(--teal-dark); background: var(--teal-soft); font-weight: 800; }
.member-meta { display: inline-flex; align-items: center; gap: 7px; color: #536967; font-size: .8rem; }
.member-meta i { width: 8px; height: 8px; border-radius: 50%; }
.member-meta i.online { background: #22a06b; }
.member-meta i.offline { background: #a0aaa8; }
.chip-list { display: flex; flex-wrap: wrap; gap: 9px; padding: 23px 20px; }
.chip-list span { border-radius: 999px; padding: 7px 11px; color: #31524e; background: #edf5f3; font-size: .85rem; font-weight: 650; }
.rule-box { margin: 0 20px 20px; border-radius: 12px; padding: 16px; color: #194f49; background: #e8f7f4; font-size: .875rem; line-height: 1.65; }
.rule-box p { margin: 5px 0 0; }

.modal { width: min(760px, calc(100vw - 28px)); max-height: 90vh; overflow: auto; border: 0; border-radius: 20px; padding: 0; color: var(--ink); background: white; box-shadow: 0 30px 80px rgb(3 33 31 / 28%); }
.modal::backdrop { background: rgb(10 35 33 / 54%); backdrop-filter: blur(3px); }
#modal-body { padding: 25px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.modal-head h2 { margin: 0; font-size: 1.35rem; letter-spacing: -.025em; }
.modal-head p { margin: 6px 0 0; color: var(--muted); font-size: .87rem; line-height: 1.55; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.wide { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 4px; }
.check { display: flex; grid-column: 1 / -1; align-items: center; gap: 9px; }
.check input { width: 18px; min-height: 18px; }
.detail-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 18px 0; }
.detail-grid > div { border-radius: 11px; padding: 12px; background: var(--soft); }
.detail-grid small, .detail-grid b { display: block; }
.detail-grid small { color: var(--muted); font-size: .74rem; }
.detail-grid b { margin-top: 5px; font-size: .88rem; overflow-wrap: anywhere; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.management-box { border: 1px solid #cde1de; border-radius: 14px; padding: 15px; background: #f5fbfa; }
.management-box h3 { margin: 0 0 12px; font-size: .92rem; }
.inline-form { display: grid; grid-template-columns: minmax(170px, 1fr) minmax(160px, 1fr) auto; align-items: end; gap: 10px; margin-top: 10px; }
.inline-form:first-of-type { grid-template-columns: 1fr auto; }
.tabs { display: flex; gap: 4px; margin: 23px 0 14px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-bottom: 2px solid transparent; padding: 10px 12px; color: var(--muted); background: transparent; font-weight: 700; }
.tabs button.active { border-bottom-color: var(--teal); color: var(--teal-dark); }
.timeline-item { display: grid; grid-template-columns: 12px 1fr; gap: 11px; padding: 10px 0; }
.timeline-item > i { position: relative; width: 9px; height: 9px; margin-top: 6px; border: 2px solid white; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 2px #afd8d3; }
.timeline-item > div { border-bottom: 1px solid #edf2f1; padding-bottom: 13px; }
.timeline-item > div > div { display: flex; justify-content: space-between; gap: 15px; }
.timeline-item time { color: var(--muted); font-size: .77rem; }
.timeline-item p { margin: 7px 0 4px; color: #445b59; line-height: 1.55; }
.timeline-item small { color: #83928f; }
.record-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.record-grid h3 { margin: 0 0 10px; font-size: .95rem; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 80; max-width: min(420px, calc(100vw - 32px)); border-radius: 12px; padding: 13px 17px; color: white; background: var(--teal-dark); box-shadow: var(--shadow); opacity: 0; transform: translateY(18px); pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #8f231d; }
.toast.warning { background: #92550a; }
.mobile-only { display: none; }

@media (max-width: 1000px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid, .settings-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; left: -270px; width: 244px; transition: left .2s; box-shadow: 15px 0 40px rgb(6 30 28 / 24%); }
  .sidebar.open { left: 0; }
  .mobile-only { display: inline-grid; place-items: center; }
  .topbar { min-height: 78px; padding: 13px 15px; }
  .topbar h1 { font-size: 1.15rem; }
  .top-actions .button { min-height: 38px; padding: 7px 9px; font-size: .8rem; }
  .content { min-height: calc(100vh - 78px); padding: 20px 14px; }
  .page-actions { align-items: stretch; flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric { min-height: 105px; padding: 15px; }
  .metric strong { font-size: 1.45rem; }
  .filters { align-items: stretch; flex-direction: column; }
  .filters input { width: 100%; margin-left: 0; }
  th, td { white-space: nowrap; }
  .form-grid, .record-grid { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .inline-form { grid-template-columns: 1fr; }
  .inline-form:first-of-type { grid-template-columns: 1fr; }
  .modal { width: calc(100vw - 16px); border-radius: 16px; }
  #modal-body { padding: 20px 16px; }
}

@media (max-width: 460px) {
  .auth-card { padding: 30px 22px; }
  .metric-grid, .detail-grid { grid-template-columns: 1fr; }
  .top-actions #change-password { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
