:root {
  --bg: #f5f8f8;
  --panel: #ffffff;
  --panel-soft: #f8fbfa;
  --text: #1f2927;
  --muted: #8a9693;
  --line: #edf1f0;
  --mint: #22bf91;
  --mint-deep: #13a77c;
  --mint-soft: #eaf9f4;
  --blue: #568ff5;
  --amber: #f2bd4a;
  --purple: #8b78e8;
  --red: #ee6c77;
  --shadow: 0 12px 35px rgba(31, 70, 61, .06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { cursor: pointer; transition: .18s ease; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(34,191,145,.18); outline-offset: 2px; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.login-panel {
  width: min(390px, 100%);
  background: var(--panel);
  border: 1px solid rgba(31,70,61,.05);
  border-radius: 18px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(145deg, #37d7aa, #18af82);
  color: white; display: grid; place-items: center; font-weight: 900;
  margin-bottom: 16px; box-shadow: 0 8px 20px rgba(34,191,145,.18);
}
.brand-mark.small { width: 34px; height: 34px; margin: 0; border-radius: 10px; box-shadow: none; }
.login-panel h1 { margin: 0 0 8px; font-size: 23px; }
.login-panel p { margin: 0 0 24px; color: var(--muted); line-height: 1.7; font-size: 13px; }
.login-panel input {
  width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 9px;
  padding: 0 13px; margin-bottom: 12px; background: #fbfcfc; color: var(--text);
}
.login-panel button, .primary {
  width: 100%; height: 44px; border: 0; border-radius: 9px;
  background: var(--mint); color: white; font-weight: 700;
}
.login-panel button:hover, .primary:hover { background: var(--mint-deep); }
.login-error { min-height: 18px; margin-top: 10px; color: var(--red); font-size: 13px; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  grid-template-rows: 62px minmax(0, 1fr);
  grid-template-areas: "side header" "side main";
  background: #f7f9f9;
}
.sidebar {
  grid-area: side;
  background: #fff;
  color: var(--text);
  padding: 14px 12px 22px;
  border-right: 1px solid var(--line);
  overflow: auto;
}
.sidebar-title {
  display: flex; align-items: center; gap: 10px;
  height: 48px; padding: 0 7px 14px;
  border-bottom: 1px solid var(--line);
}
.sidebar-title b { display: block; font-size: 14px; letter-spacing: .01em; }
.sidebar-title span { display: block; margin-top: 2px; font-size: 10px; color: var(--muted); }
#moduleNav { display: grid; gap: 5px; padding-top: 18px; }
.nav-btn {
  position: relative; width: 100%; min-height: 41px; border: 0; border-radius: 9px;
  text-align: left; padding: 0 12px 0 42px; color: #77827f; background: transparent;
  font-size: 13px; font-weight: 500; white-space: nowrap;
}
.nav-btn::before {
  position: absolute; left: 15px; top: 50%; transform: translateY(-50%);
  width: 17px; text-align: center; color: #9ba5a3; font-size: 15px;
}
.nav-btn[data-id="dashboard"]::before { content: "⌂"; }
.nav-btn[data-id="customers"]::before { content: "◉"; }
.nav-btn[data-id="people"]::before { content: "♙"; }
.nav-btn[data-id="channels"]::before { content: "◇"; }
.nav-btn[data-id="tickets"]::before { content: "▤"; }
.nav-btn[data-id="orderCosts"]::before { content: "▣"; }
.nav-btn[data-id="audits"]::before { content: "✓"; }
.nav-btn[data-id="subscriptions"]::before { content: "◎"; }
.nav-btn[data-id="settings"]::before { content: "⚙"; }
.nav-btn[data-id="commission"]::before { content: "¥"; }
.nav-btn:hover { background: #f7faf9; color: var(--text); }
.nav-btn.active { background: var(--mint-soft); color: var(--mint-deep); font-weight: 700; }
.nav-btn.active::before { color: var(--mint); }

.topbar {
  grid-area: header;
  display: flex; justify-content: space-between; align-items: center; gap: 18px;
  margin: 0; padding: 0 28px; background: #fff; border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 17px; line-height: 1.2; font-weight: 700; }
.topbar p { margin: 3px 0 0; color: var(--muted); max-width: 740px; line-height: 1.3; font-size: 11px; }
.top-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px;
  border-radius: 7px; background: var(--mint-soft); color: var(--mint-deep);
  font-size: 11px; font-weight: 700;
}
.ghost {
  height: 29px; padding: 0 11px; border: 1px solid var(--line); border-radius: 7px;
  background: white; color: #687370; font-size: 11px; font-weight: 600;
}
.ghost:hover { background: var(--panel-soft); color: var(--text); }

.main { grid-area: main; min-width: 0; padding: 22px 26px 30px; overflow: auto; }
.content { display: grid; gap: 15px; min-width: 0; max-width: 1500px; margin: 0 auto; }
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 13px;
}
.stat, .panel, .table-panel {
  min-width: 0; background: var(--panel); border: 1px solid rgba(31,70,61,.045);
  border-radius: 11px; box-shadow: 0 7px 24px rgba(31,70,61,.035);
}
.stat {
  position: relative; min-height: 116px; padding: 17px 18px 15px;
  display: flex; flex-direction: column; justify-content: space-between; overflow: hidden;
}
.stat::before {
  content: ""; position: absolute; right: 16px; top: 18px; width: 44px; height: 22px;
  border-bottom: 2px solid var(--mint); border-radius: 50%; transform: rotate(-8deg); opacity: .72;
}
.stat:nth-child(2)::before { border-color: var(--blue); transform: rotate(8deg); }
.stat:nth-child(3)::before { border-color: var(--amber); }
.stat:nth-child(4)::before { border-color: var(--red); transform: rotate(10deg); }
.stat:nth-child(5)::before { border-color: var(--purple); }
.stat:nth-child(6)::before { border-color: var(--blue); }
.stat span, .muted { color: var(--muted); font-size: 12px; line-height: 1.65; }
.stat small { color: #b0bab7; font-size: 10px; margin-top: 9px; }
.stat b { display: block; margin-top: 20px; font-size: 26px; line-height: 1; font-weight: 760; color: var(--text); letter-spacing: -.025em; }
.panel { padding: 19px; }
.panel h3 { margin: 0 0 8px; font-size: 14px; }
.grid-2 { display: grid; grid-template-columns: 1.25fr .75fr; gap: 13px; }
.grid-2 .panel { min-height: 120px; }

.table-panel { padding: 16px; overflow: hidden; }
.table-panel > .row-actions:first-child {
  min-height: 38px; padding: 0 2px 12px; margin-bottom: 0 !important;
}
.table-wrap { width: 100%; max-width: 100%; overflow: auto; background: white; }
table { width: 100%; border-collapse: collapse; min-width: 760px; background: white; }
th, td {
  padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left;
  font-size: 12px; vertical-align: middle; white-space: nowrap;
}
th { color: #8b9592; font-size: 11px; font-weight: 650; background: #fbfcfc; }
tbody tr:hover { background: #fbfdfc; }
tbody tr:last-child td { border-bottom: 0; }
.tag {
  display: inline-flex; align-items: center; min-height: 23px; padding: 0 9px;
  border-radius: 6px; font-size: 10px; font-weight: 700; background: #f1effd; color: #735fcf;
}
.tag.ok { background: #eaf9f4; color: var(--mint-deep); }
.tag.warn { background: #fff5ea; color: #d48837; }
.tag.bad { background: #fff0f2; color: #df5966; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.small-btn {
  min-height: 29px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px;
  background: white; color: #697370; font-size: 11px; font-weight: 650;
}
.small-btn:hover { background: #f8fbfa; }
.small-btn.primary { width: auto; border-color: transparent; background: var(--mint-soft); color: var(--mint-deep); }
.small-btn.primary:hover { background: #dcf5ec; }
.small-btn.danger { border-color: #f4cfd3; color: #dc5966; }
.small-btn.danger:hover { background: #fff4f5; }
.small-btn.danger.solid { border-color: #e7626e; background: #e7626e; color: white; }
.small-btn.danger.solid:hover { background: #d9505d; }
.small-btn[disabled] { opacity: .48; cursor: not-allowed; }
.customer-toolbar { justify-content: space-between; margin-bottom: 12px; }
.customer-toolbar > div { display: flex; align-items: center; gap: 10px; }
.customer-total { color: var(--muted); font-size: 11px; }
.pagination { display: flex; justify-content: flex-end; align-items: center; gap: 10px; padding-top: 14px; color: var(--muted); font-size: 11px; }
.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(20,35,31,.28); backdrop-filter: blur(3px); }
.editor-card { width: min(700px, 100%); max-height: calc(100vh - 40px); overflow: auto; padding: 22px; background: white; border-radius: 14px; box-shadow: 0 24px 70px rgba(19,48,40,.18); }
.editor-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.editor-head h3 { margin: 0 0 5px; font-size: 17px; }
.editor-head p { margin: 0; color: var(--muted); font-size: 11px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label { display: grid; gap: 6px; color: #66716e; font-size: 11px; font-weight: 650; }
.form-grid input, .form-grid select { width: 100%; height: 39px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfc; color: var(--text); }
.form-wide { grid-column: 1 / -1; }
.form-error { min-height: 18px; margin-top: 10px; color: var(--red); font-size: 11px; }
.editor-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 8px; }
.editor-actions .primary { width: auto; min-width: 72px; }
.compact-editor { width: min(580px, 100%); }
.delete-card { width: min(470px, 100%); }
.delete-warning { padding: 14px; border-radius: 9px; background: #fff5f6; color: #b74752; font-size: 13px; line-height: 1.7; }
.ny-check-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.ny-check-grid > div { padding: 14px; border: 1px solid var(--line); border-radius: 9px; background: #f9fbfa; }
.ny-check-grid span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 7px; }
.ny-check-grid b { font-size: 13px; line-height: 1.65; overflow-wrap: anywhere; }
.ny-entry-list { margin-top: 10px; display: grid; gap: 8px; }
.ny-entry-list label { display: flex; flex-direction: row; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: #f8faf9; }
.ny-entry-list input { width: auto; }
.ny-entry-list span { display: flex; flex-direction: column; gap: 2px; }
.ny-entry-list small { color: var(--muted); }
.package-preview-card { width: min(1180px, calc(100vw - 40px)); max-height: calc(100vh - 40px); overflow: auto; }
.package-nodes { display: grid; gap: 10px; margin: 10px 0 18px; }
.package-node { display: grid; grid-template-columns: 180px 220px 1fr; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #f8fbfa; }
.package-node code { overflow-wrap: anywhere; color: var(--mint-deep); }
.output-preview { width: 100%; min-height: 280px; margin-top: 8px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.package-files { display: grid; gap: 7px; padding-left: 22px; }
.ticket-replies { display: grid; gap: 10px; margin: 10px 0 16px; }
.ticket-reply { border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; padding: 12px; }
.ticket-reply small { margin-left: 10px; color: var(--muted); }
.ticket-reply p { margin: 8px 0 0; line-height: 1.6; }
@media (max-width: 850px) { .package-node { grid-template-columns: 1fr; } }
.ny-route-row { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(220px, .7fr); gap: 16px; align-items: end; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.ny-route-row > label { margin: 0; }
.ny-route-row select { width: 100%; }
@media (max-width: 760px) { .ny-route-row { grid-template-columns: 1fr; } }
.audit-create-card { width: min(820px,100%); }
.field-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; }
.contact-list { display: grid; gap: 8px; }
.contact-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.form-grid textarea { width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; font: inherit; color: var(--ink); background: #fbfcfc; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; grid-template-areas: "header" "side" "main"; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px 12px; }
  .sidebar-title { display: none; }
  #moduleNav { padding-top: 0; grid-template-columns: repeat(5, minmax(110px, 1fr)); overflow-x: auto; }
  .nav-btn { padding-left: 36px; }
  .topbar { min-height: 62px; padding: 10px 18px; }
  .main { padding: 18px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .login-shell { padding: 16px; }
  .login-panel { padding: 24px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions { justify-content: flex-start; }
  .main { padding: 14px; }
  .stats { grid-template-columns: 1fr; }
  .stat { min-height: 96px; }
}
