:root {
  color-scheme: dark;
  --bg: #070b12;
  --panel: #0e1522;
  --panel-soft: #111b2b;
  --line: #273651;
  --text: #eef4ff;
  --muted: #9aa8bd;
  --blue: #4b8cff;
  --blue-hover: #6ca1ff;
  --cyan: #35d6c2;
  --red: #ff637a;
  --amber: #ffbd52;
  --shadow: 0 16px 46px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: radial-gradient(circle at 85% 0, #13213e 0, transparent 35%), var(--bg);
  color: var(--text);
  font: 14px/1.55 Inter, "Microsoft YaHei", system-ui, sans-serif;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

aside {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  padding: 24px 16px;
  background: rgba(8, 13, 22, .96);
}
aside .brand { font-size: 22px; font-weight: 800; letter-spacing: 2px; margin: 0 10px 28px; }
.brand span { color: var(--blue); }
.brand small { display: block; font-size: 9px; color: var(--muted); letter-spacing: 3px; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 108px;
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--text);
  background: transparent;
  font: inherit;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}
button:hover { transform: translateY(-1px); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(75, 140, 255, .35);
  outline-offset: 2px;
}
button:disabled { opacity: .55; cursor: wait; transform: none; }
.primary { background: var(--blue); border-color: var(--blue); }
.primary:hover { background: var(--blue-hover); border-color: var(--blue-hover); }
.secondary { background: #17243a; border-color: #344665; }
.secondary:hover { background: #20314d; border-color: #4a628c; }
.danger-button { color: #ffdce2; background: #351923; border-color: #6f2f3c; }

aside button {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  justify-content: flex-start;
  text-align: left;
  padding: 10px 13px;
  border-radius: 9px;
  color: var(--muted);
  margin: 1px 0;
}
aside button:hover, aside button.active { background: #142038; color: #fff; transform: none; }
aside .danger { color: var(--red); margin-top: 20px; }
.nav-group { margin: 2px 0; }
.nav-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 10px 13px;
  border-radius: 9px;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::after { content: "+"; color: #6f83a3; font-size: 16px; }
.nav-group[open] summary { color: #fff; background: #0f192a; }
.nav-group[open] summary::after { content: "−"; }
.nav-group > div { padding: 3px 0 5px 12px; border-left: 1px solid #263550; margin-left: 13px; }
.nav-group > div button { min-height: 38px; font-size: 13px; }

main { padding: 30px clamp(20px, 3vw, 52px) 60px; max-width: 1700px; width: 100%; min-width: 0; }
header { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 24px; }
h1 { margin: 0; font-size: clamp(25px, 3vw, 32px); }
h2, h3 { margin-top: 0; line-height: 1.3; }
p { overflow-wrap: anywhere; }
.eyebrow { color: var(--blue); font-size: 10px; letter-spacing: 3px; margin: 0; }
.status, .tag { display: inline-flex; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--cyan); }

.page-intro {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin: 0 0 20px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 13px;
  background: linear-gradient(120deg, rgba(75, 140, 255, .1), rgba(14, 21, 34, .72));
}
.page-intro h2 { margin: 0 0 5px; font-size: 20px; }
.page-intro p { margin: 0; color: var(--muted); max-width: 840px; }
.intro-note { flex: 0 0 auto; padding: 7px 11px; color: #cfe0ff; background: #17243a; border: 1px solid #344665; border-radius: 999px; }

.grid { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 14px; }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.top-gap { margin-top: 16px; }
.card {
  min-width: 0;
  background: linear-gradient(145deg, #101928, #0b111c);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.metric span { color: var(--muted); }
.metric b { display: block; font-size: 30px; margin-top: 8px; }
.status-card p { margin: 12px 0 0; color: var(--muted); }
.muted { color: var(--muted); }
.warning { color: var(--amber); }
.ok { color: var(--cyan); }
.bad { color: var(--red); }
a { color: #8db8ff; }

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  padding: 5px 9px;
  border: 1px solid #40506c;
  border-radius: 999px;
  color: #d4deee;
  background: #192236;
  font-size: 12px;
  line-height: 1.3;
}
.badge.success { color: #8beadf; background: #102a2b; border-color: #285b59; }
.badge.warning { color: #ffd58c; background: #302514; border-color: #69532a; }
.badge.danger { color: #ffabb8; background: #351923; border-color: #6f2f3c; }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
table { width: 100%; border-collapse: collapse; background: var(--panel); min-width: 820px; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; white-space: nowrap; background: #0b121e; }
tbody tr:last-child td { border-bottom: 0; }
tr.unread { background: #111f36; }
td button { min-width: 120px; }
.message-preview { max-width: 310px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.loading { padding: 48px; text-align: center; color: var(--muted); }

input, textarea, select {
  width: 100%;
  min-height: 42px;
  background: #080e18;
  color: var(--text);
  border: 1px solid #34425d;
  padding: 10px 12px;
  border-radius: 8px;
  font: inherit;
}
textarea { resize: vertical; min-height: 100px; }
label { display: grid; align-content: start; gap: 6px; color: #cbd6e7; min-width: 0; }
fieldset { min-width: 0; margin: 0; border: 1px solid var(--line); border-radius: 9px; }
legend { color: var(--muted); padding: 0 6px; }

.create-panel { margin-bottom: 18px; border: 1px solid var(--line); border-radius: 12px; background: rgba(14, 21, 34, .82); }
.create-panel summary { padding: 14px 18px; font-weight: 700; cursor: pointer; }
.create-panel[open] summary { border-bottom: 1px solid var(--line); }
.form { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 14px; margin: 0; padding: 18px; }
.form .span-all, .form textarea { grid-column: 1 / -1; }
.form button { justify-self: start; }
.check { display: flex; grid-template-columns: auto 1fr; align-items: center; gap: 8px; margin: 7px 0; }
.check input { width: auto; min-height: 0; }

.catalog { display: grid; grid-template-columns: repeat(3, minmax(240px, 1fr)); gap: 14px; }
.catalog h3 { margin: 10px 0 0; }
.price { font-size: 22px; color: var(--cyan); font-weight: 700; }
.catalog ul { padding-left: 18px; }

.record-grid, .ticket-board { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.record-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.record-head h3 { margin: 3px 0; }
.record-head p { margin: 0; color: var(--muted); }
.record-head > div { min-width: 0; }
.record-card dl, .order-card dl { display: grid; gap: 10px; margin: 14px 0 0; }
.record-card dl div, .order-card dl div { padding-top: 10px; border-top: 1px solid var(--line); }
dt { color: var(--muted); font-size: 12px; }
dd { margin: 3px 0 0; overflow-wrap: anywhere; }
.mini-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.mini-metrics div { padding: 11px; background: #090f19; border: 1px solid #202d43; border-radius: 9px; }
.mini-metrics span { display: block; color: var(--muted); font-size: 11px; }
.mini-metrics b { display: block; margin-top: 3px; font-size: 17px; overflow-wrap: anywhere; }
.button-row { display: flex; flex-wrap: wrap; align-items: stretch; gap: 9px; margin-top: 16px; }
.button-row button { flex: 1 1 130px; margin: 0; }
.proxy-control { display: grid; grid-template-columns: minmax(0, 1fr) 220px minmax(260px, auto); align-items: end; gap: 18px; }
.proxy-control h3 { margin-bottom: 5px; }
.proxy-control p { margin: 0; color: var(--muted); }
.proxy-control .button-row { margin: 0; }

.ticket-card { display: flex; flex-direction: column; }
.ticket-no { color: #8db8ff; font-size: 12px; font-weight: 700; letter-spacing: .4px; }
.status-stack { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.source-line { margin: 0 0 14px; padding: 10px 12px; background: #0a111d; border-radius: 8px; color: var(--muted); }
.ticket-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.ticket-fields .span-all { grid-column: 1 / -1; }
.ticket-actions { margin-top: auto; padding-top: 16px; }

.notice { padding: 12px 14px; border: 1px solid #5d4826; background: #211a10; border-radius: 9px; margin-bottom: 18px; }
.notice.bad { border-color: #6f2f3c; background: #351923; color: #ffdce2; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; color: var(--muted); }
.conversation { margin-top: 20px; scroll-margin-top: 20px; }
.conversation-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.conversation-head h2 { margin-bottom: 4px; }
.conversation-head p { margin: 0; color: var(--muted); }
.messages { max-height: 520px; overflow: auto; padding: 12px; background: #080d15; border-radius: 10px; margin-top: 14px; }
.message { max-width: 72%; padding: 10px 12px; margin: 8px 0; border-radius: 12px; background: #172238; }
.message.outbound { margin-left: auto; background: #17344a; }
.message span, .message small { font-size: 11px; color: var(--muted); }
.message p { white-space: pre-wrap; margin: 4px 0; }
.compact-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; align-items: end; gap: 10px; margin-top: 14px; }
.compact-form button { min-width: 142px; }
.reply-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; margin-top: 14px; }
.reply-form textarea { min-height: 90px; }
.reply-form button { min-width: 142px; }

.narrow { max-width: 680px; }
.login-shell { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: min(440px, 100%); padding: 32px; background: linear-gradient(145deg, #111b2b, #090f19); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 30px 80px #0008; }
.login-card h1 { margin-top: 6px; }
.login-form { display: grid; gap: 14px; margin-top: 24px; }
.login-form label { display: grid; gap: 6px; color: var(--muted); }
.login-form .primary { width: 100%; margin-top: 4px; }
.login-card main { padding: 0; }

@media (max-width: 1200px) {
  .grid.metrics { grid-template-columns: repeat(3, 1fr); }
  .catalog { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compact-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compact-form button { width: 100%; }
  .mini-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  aside {
    position: sticky;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    height: auto;
    overflow-x: auto;
    padding: 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  aside .brand { display: none; }
  aside button { flex: 0 0 auto; width: auto; min-width: 104px; justify-content: center; white-space: nowrap; margin: 0; }
  aside .danger { margin-top: 0; }
  .nav-group { flex: 0 0 auto; display: flex; align-items: center; }
  .nav-group summary { min-width: 104px; white-space: nowrap; }
  .nav-group summary::after { margin-left: 8px; }
  .nav-group > div { display: flex; align-items: center; padding: 0; margin: 0 0 0 4px; border: 0; }
  .nav-group > div button { min-height: 42px; }
  main { padding-top: 22px; }
  .grid.three { grid-template-columns: 1fr; }
  .record-grid, .ticket-board { grid-template-columns: 1fr; }
  .proxy-control { grid-template-columns: 1fr 1fr; }
  .proxy-control > div:first-child { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  main { padding: 18px 14px 44px; }
  header { align-items: flex-start; }
  header .status { max-width: 44%; text-align: right; }
  .page-intro { display: block; padding: 15px; }
  .intro-note { margin-top: 12px; }
  .grid.metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .catalog, .form, .ticket-fields, .compact-form, .reply-form { grid-template-columns: 1fr; }
  .proxy-control { grid-template-columns: 1fr; }
  .proxy-control > div:first-child { grid-column: auto; }
  .form .span-all, .form textarea, .ticket-fields .span-all { grid-column: auto; }
  .form button, .compact-form button, .reply-form button { width: 100%; justify-self: stretch; }
  .record-head { display: grid; }
  .status-stack { align-items: flex-start; }
  .button-row button { flex: 1 1 100%; width: 100%; }
  .toolbar button { width: 100%; }
  .conversation-head { display: grid; }
  .conversation-head button { width: 100%; }
  .message { max-width: 92%; }
  .mini-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  th, td { padding: 12px 10px; }
}
