:root {
  --nav: #14202f;
  --nav-deep: #0e1723;
  --nav-muted: #a7b3c2;
  --page: #f8fafb;
  --surface: #ffffff;
  --ink: #172536;
  --muted: #687588;
  --faint: #97a3b2;
  --line: #e3e8ed;
  --line-strong: #d4dce4;
  --brass: #b48a46;
  --brass-soft: #fbf7ef;
  --teal: #23856b;
  --teal-soft: #edf8f4;
  --red: #c94b4b;
  --red-soft: #fff2f1;
  --blue: #3874c8;
  --shadow: 0 16px 42px rgba(25, 41, 59, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--page);
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--page);
}

[hidden] { display: none !important; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(150deg, #eef3f5 0%, #f9fbfc 55%, #fbf5e9 100%); }
.login-panel { width: min(390px, 100%); display: grid; gap: 18px; padding: 30px; border: 1px solid var(--line); border-radius: 7px; box-shadow: var(--shadow); background: #fff; }
.login-brand { padding: 0; }
.login-panel .brand-mark { color: var(--brass); border-color: var(--brass); }
.login-panel .brand-copy span { color: var(--ink); }
.login-panel .brand-copy strong { color: var(--muted); }
.eyebrow { margin: 0 0 5px; color: var(--brass); font-size: 10px; font-weight: 750; letter-spacing: .08em; }
.login-panel h1 { margin: 0; font-size: 23px; }
.login-panel label, .admin-form label { display: grid; gap: 6px; color: #526174; font-size: 12px; font-weight: 680; }
.login-panel input, .admin-form input, .admin-form select { width: 100%; min-height: 38px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--ink); background: #fff; }
.login-submit { width: 100%; min-height: 38px; }
.form-error { margin: -4px 0 0; color: var(--red); font-size: 12px; line-height: 1.45; }
.sidebar-empty { padding: 10px; color: var(--nav-muted); font-size: 11px; line-height: 1.55; }
.admin-dialog { max-height: min(760px, calc(100vh - 32px)); overflow: auto; }
.admin-content { display: grid; gap: 15px; padding: 21px; }
.admin-content > header { display: flex; align-items: flex-start; justify-content: space-between; }
.admin-content > header p { margin: 0 0 4px; color: var(--brass); font-size: 10px; font-weight: 750; letter-spacing: .08em; }
.admin-content > header h2 { margin: 0; font-size: 19px; }
.admin-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.admin-list { display: grid; gap: 7px; margin-bottom: 18px; }
.admin-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 5px; }
.admin-row strong, .admin-row small { display: block; }
.admin-row strong { font-size: 12px; }
.admin-row small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.admin-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-top: 16px; border-top: 1px solid var(--line); }
.admin-form h3, .admin-form .form-error, .admin-form .primary-button, .admin-form #custom-host-fields { grid-column: 1 / -1; }
.admin-form h3 { margin: 0; font-size: 14px; }
#custom-host-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check-row { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 8px; }
.check-row input { width: 15px; min-height: 15px; margin: 0; }
@media (max-width: 520px) { .login-panel { padding: 23px; } .admin-form, #custom-host-fields { grid-template-columns: 1fr; } }

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(56, 116, 200, 0.24);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  background: var(--surface);
}

.sidebar {
  position: relative;
  z-index: 2;
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  padding: 20px 14px 14px;
  color: #fff;
  background: linear-gradient(180deg, var(--nav), var(--nav-deep));
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 9px 24px; }
.brand-mark {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border: 1px solid rgba(224, 188, 122, 0.7);
  color: #f4d99e;
  font-family: Georgia, serif;
  font-size: 19px;
  line-height: 1;
}
.brand-copy { display: grid; gap: 1px; line-height: 1.1; }
.brand-copy span { color: #f7f9fb; font-size: 14px; font-weight: 650; }
.brand-copy strong { color: var(--nav-muted); font-size: 11px; font-weight: 500; }

.primary-nav, .sidebar-footer { display: grid; gap: 3px; }
.nav-item, .account-item {
  width: 100%;
  display: grid;
  align-items: center;
  border: 0;
  border-radius: 5px;
  color: var(--nav-muted);
  background: transparent;
  text-align: left;
  transition: background 140ms ease, color 140ms ease;
}
.nav-item { min-height: 39px; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 10px; padding: 0 10px; font-size: 13px; }
.nav-item svg, .account-item svg { width: 17px; height: 17px; stroke-width: 1.75; }
.nav-item b {
  min-width: 20px;
  padding: 1px 5px;
  border-radius: 10px;
  color: #dce4eb;
  background: rgba(255, 255, 255, 0.1);
  font-size: 11px;
  font-weight: 650;
  text-align: center;
}
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(255, 255, 255, 0.09); }
.nav-item.active { box-shadow: inset 2px 0 0 var(--brass); }
.nav-item.active b { color: #1b222b; background: #e3bd72; }

.sidebar-section { margin-top: 27px; }
.sidebar-section p {
  margin: 0 10px 8px;
  color: #748396;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.account-list { display: grid; gap: 3px; }
.account-item { grid-template-columns: 9px minmax(0, 1fr) auto; gap: 9px; min-height: 45px; padding: 5px 10px; }
.account-item:hover, .account-item.active { background: rgba(255, 255, 255, 0.07); color: #fff; }
.account-item strong, .account-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-item strong { font-size: 12px; font-weight: 620; }
.account-item small { margin-top: 2px; color: #8290a0; font-size: 10px; }
.account-item em { color: #bbcad7; font-size: 11px; font-style: normal; }
.account-dot { width: 7px; height: 7px; border-radius: 50%; background: #66b49a; }
.account-dot.orders { background: #80a8de; }
.account-dot.wholesale { background: #d9a966; }
.placeholder-dot { background: transparent; border: 1px dashed #5f6e7e; }
.account-item.reserved { color: #94a2b1; }
.account-item.reserved svg { color: #708094; width: 15px; }
.reserved-section { margin-top: 22px; }
.sidebar-footer { margin-top: auto; padding-top: 15px; border-top: 1px solid rgba(210, 223, 233, 0.12); }

.workbench { min-width: 0; display: flex; min-height: 100vh; flex-direction: column; }
.topbar {
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.search-box {
  width: min(410px, 46vw);
  min-width: 200px;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: #7a8797;
  background: #fbfcfd;
}
.search-box svg { width: 17px; height: 17px; }
.search-box input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 13px; }
.search-box input::placeholder { color: #98a5b3; }
.sync-state { display: flex; align-items: center; gap: 6px; margin-left: auto; color: var(--muted); font-size: 11px; white-space: nowrap; }
.sync-state time { color: #9aa6b4; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: #36a97e; box-shadow: 0 0 0 3px #eaf8f2; }
.icon-button {
  width: 33px;
  height: 33px;
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  color: #526173;
  background: transparent;
  transition: color 140ms ease, background 140ms ease, border-color 140ms ease;
}
.icon-button svg { width: 17px; height: 17px; stroke-width: 1.85; }
.icon-button:hover { border-color: var(--line); color: var(--ink); background: #f7f9fa; }
.compact-only { display: none; }
.user-menu { display: flex; align-items: center; gap: 7px; margin-left: 3px; padding: 3px 0 3px 4px; border: 0; color: var(--ink); background: transparent; }
.user-menu svg { width: 14px; height: 14px; color: #8794a2; }
.avatar { width: 26px; height: 26px; display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-size: 11px; font-weight: 750; }
.avatar-lin { background: #536f88; }
.user-name { font-size: 12px; font-weight: 670; }

.mail-grid { min-height: 0; flex: 1; display: grid; grid-template-columns: minmax(330px, 390px) minmax(0, 1fr); }
.mail-list-pane { min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface); }
.list-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 20px 18px 13px; }
.list-header h1 { margin: 0; color: #172536; font-size: 18px; font-weight: 720; letter-spacing: 0; }
.list-header p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.header-actions { display: flex; gap: 2px; }
.quick-filters { display: flex; gap: 7px; padding: 0 18px 13px; border-bottom: 1px solid var(--line); }
.filter-chip { min-height: 26px; padding: 0 9px; border: 1px solid var(--line); border-radius: 999px; color: #687588; background: #fff; font-size: 11px; font-weight: 600; }
.filter-chip:hover, .filter-chip.active { border-color: #d8bf92; color: #835f24; background: var(--brass-soft); }
.message-list { overflow-x: hidden; overflow-y: auto; }
.message-row { position: relative; width: 100%; display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; gap: 10px; padding: 15px 16px 14px; border: 0; border-bottom: 1px solid var(--line); color: var(--ink); background: #fff; text-align: left; }
.message-row:hover { background: #fbfcfd; }
.message-row.active { background: #fbf8f1; }
.message-row.active::before { position: absolute; top: 0; bottom: 0; left: 0; width: 3px; background: var(--brass); content: ""; }
.message-row .unread-dot { width: 7px; height: 7px; margin-top: 7px; border-radius: 50%; background: transparent; }
.message-row.unread .unread-dot { background: var(--brass); }
.message-main { min-width: 0; }
.message-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sender { overflow: hidden; color: #324152; font-size: 12px; font-weight: 690; text-overflow: ellipsis; white-space: nowrap; }
.source-label { padding: 2px 5px; border-radius: 3px; color: #637182; background: #f0f3f6; font-size: 9px; font-weight: 730; letter-spacing: 0.02em; }
.message-row.unread .sender, .message-row.unread .subject { color: #152334; font-weight: 740; }
.subject { overflow: hidden; margin-top: 5px; color: #405062; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.snippet { overflow: hidden; margin-top: 4px; color: #8290a0; font-size: 11px; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.message-side { display: grid; align-content: start; justify-items: end; gap: 10px; color: #8794a2; font-size: 10px; }
.message-side svg { width: 13px; height: 13px; color: #6b7a8d; }
.message-empty { padding: 50px 24px; color: var(--muted); font-size: 13px; text-align: center; }

.detail-pane { min-width: 0; overflow: auto; background: #fff; }
.detail-header { padding: 20px 28px 0; border-bottom: 1px solid var(--line); }
.detail-heading-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.thread-title { max-width: 680px; margin: 0; color: #142233; font-size: clamp(18px, 2vw, 24px); font-weight: 720; line-height: 1.3; }
.detail-actions { display: flex; gap: 2px; }
.detail-summary { display: flex; flex-wrap: wrap; gap: 7px; margin: 15px 0 16px; }
.status-control, .meta-chip { min-height: 28px; display: inline-flex; align-items: center; gap: 6px; padding: 0 8px; border: 1px solid var(--line); border-radius: 4px; color: #5e6c7d; background: #fff; font-size: 11px; }
.status-control { font-weight: 690; }
.status-control:hover { border-color: #c5ced7; background: #fafbfc; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brass); }
.status-dot.pending { background: #557ec2; }
.status-dot.resolved { background: var(--teal); }
.meta-chip svg { width: 13px; height: 13px; }
.ticket-id { margin-left: auto; color: #9ba6b3; font-size: 11px; align-self: center; }
.message-detail { padding: 21px 28px 26px; }
.sender-line { display: flex; align-items: center; gap: 11px; }
.sender-line .avatar { width: 35px; height: 35px; background: #9b7d57; font-size: 13px; }
.sender-line > span:nth-child(2) { min-width: 0; }
.sender-line strong { display: block; font-size: 13px; }
.sender-line span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.sender-line > span:nth-child(2) span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-line time { margin-left: auto; color: #9aa6b2; font-size: 11px; }
.mail-body { max-width: 760px; margin: 23px 0 20px 46px; color: #425162; font-size: 13px; line-height: 1.78; white-space: pre-line; }
.tag-row { display: flex; flex-wrap: wrap; gap: 7px; margin-left: 46px; }
.tag { display: inline-flex; min-height: 24px; align-items: center; padding: 0 7px; border: 1px solid #dce4e9; border-radius: 3px; color: #58687b; background: #fafbfc; font-size: 10px; font-weight: 650; }
.tag.order { border-color: #cfe2f0; color: #396993; background: #f2f8fc; }
.tag.wholesale { border-color: #eadab8; color: #866727; background: #fffaf0; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin: 24px 0 0 46px; }
.attachment { min-width: 170px; display: flex; align-items: center; gap: 8px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 5px; color: #526174; background: #fff; font-size: 11px; }
.attachment svg { width: 17px; height: 17px; color: #6b7f98; }
.thread-divider { margin: 0 28px; border: 0; border-top: 1px solid var(--line); }
.internal-note { margin: 21px 28px 12px; padding: 14px 15px; border: 1px solid #ead9b9; border-left: 3px solid var(--brass); border-radius: 5px; background: #fffaf0; }
.internal-note header { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: #745620; font-size: 11px; font-weight: 720; }
.internal-note header span { display: flex; align-items: center; gap: 6px; }
.internal-note header svg { width: 14px; height: 14px; }
.internal-note p { margin: 8px 0 0; color: #5e584d; font-size: 12px; line-height: 1.6; }
.reply-area { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin: 18px 28px 28px; }
.reply-area textarea { min-height: 64px; resize: vertical; padding: 11px; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--ink); line-height: 1.45; }
.reply-area textarea::placeholder { color: #98a5b3; }
.reply-actions { display: grid; grid-auto-rows: min-content; gap: 6px; }
.small-action { min-height: 29px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 9px; border: 1px solid var(--line-strong); border-radius: 5px; color: #526174; background: #fff; font-size: 11px; }
.small-action svg { width: 14px; height: 14px; }
.small-action:hover { background: #f8fafb; }
.small-action.send { border-color: var(--brass); color: #fff; background: var(--brass); }
.small-action.send:hover { background: #9e7434; }

.compose-button { position: fixed; z-index: 3; right: 24px; bottom: 24px; min-height: 40px; display: inline-flex; align-items: center; gap: 8px; padding: 0 15px; border: 0; border-radius: 5px; box-shadow: 0 8px 18px rgba(114, 83, 33, 0.22); color: #fff; background: var(--brass); font-size: 12px; font-weight: 720; }
.compose-button:hover { background: #9e7434; }
.compose-button svg { width: 16px; height: 16px; }
.compose-dialog { width: min(570px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 7px; box-shadow: var(--shadow); }
.compose-dialog::backdrop { background: rgba(9, 19, 32, 0.38); }
.compose-dialog form { display: grid; gap: 15px; padding: 21px; }
.compose-dialog header { display: flex; align-items: flex-start; justify-content: space-between; }
.compose-dialog header p { margin: 0 0 4px; color: var(--brass); font-size: 10px; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase; }
.compose-dialog h2 { margin: 0; font-size: 19px; }
.compose-dialog label { display: grid; gap: 6px; color: #526174; font-size: 11px; font-weight: 680; }
.compose-dialog input, .compose-dialog select, .compose-dialog textarea { width: 100%; padding: 9px 10px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--ink); background: #fff; font-size: 13px; }
.compose-dialog textarea { resize: vertical; line-height: 1.5; }
.compose-dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.primary-button, .secondary-button { min-height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 12px; border-radius: 4px; font-size: 12px; font-weight: 700; }
.primary-button { border: 1px solid var(--brass); color: #fff; background: var(--brass); }
.primary-button:hover { background: #9e7434; }
.primary-button svg { width: 14px; height: 14px; }
.secondary-button { border: 1px solid var(--line-strong); color: #536173; background: #fff; }
.secondary-button:hover { background: #f8fafb; }
.toast { position: fixed; z-index: 4; right: 24px; bottom: 75px; max-width: min(360px, calc(100vw - 32px)); padding: 11px 13px; border-radius: 5px; box-shadow: 0 10px 22px rgba(16, 30, 45, 0.18); color: #fff; background: #23384d; font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity 160ms ease, transform 160ms ease; }
.toast.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 222px minmax(0, 1fr); }
  .sidebar { padding-right: 10px; padding-left: 10px; }
  .mail-grid { grid-template-columns: minmax(300px, 350px) minmax(0, 1fr); }
  .detail-header, .message-detail { padding-right: 22px; padding-left: 22px; }
  .mail-body, .tag-row, .attachments { margin-left: 0; }
}

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { min-height: auto; flex-direction: row; padding: 11px 12px; scrollbar-width: none; }
  .sidebar::-webkit-scrollbar { display: none; }
  .brand { padding: 0 7px 10px; }
  .sidebar, .primary-nav, .account-list, .sidebar-footer { display: flex; align-items: center; }
  .sidebar { gap: 8px; overflow-x: auto; }
  .brand { flex: 0 0 auto; }
  .brand-copy, .sidebar-section p, .sidebar-footer { display: none; }
  .primary-nav, .account-list { flex: 0 0 auto; gap: 4px; }
  .nav-item { width: auto; min-height: 34px; grid-template-columns: 18px auto; gap: 6px; padding: 0 8px; white-space: nowrap; }
  .nav-item b { display: none; }
  .sidebar-section { flex: 0 0 auto; display: block; margin: 0; }
  .reserved-section { display: none; }
  .account-item { width: auto; min-height: 34px; grid-template-columns: 7px auto; gap: 6px; padding: 0 7px; white-space: nowrap; }
  .account-item small, .account-item em { display: none; }
  .workbench { min-height: calc(100vh - 57px); }
  .topbar { padding: 0 14px; }
  .mail-grid { grid-template-columns: 1fr; }
  .mail-list-pane { border-right: 0; border-bottom: 1px solid var(--line); }
  .message-list { max-height: 47vh; }
  .detail-pane { min-height: 540px; }
  .compose-button { right: 16px; bottom: 16px; }
}

@media (max-width: 520px) {
  .topbar { gap: 7px; min-height: 54px; }
  .search-box { min-width: 0; width: auto; flex: 1; }
  .sync-state, .user-name, .user-menu svg { display: none; }
  .mail-body { margin-top: 18px; font-size: 12px; }
  .detail-header, .message-detail { padding-right: 16px; padding-left: 16px; }
  .thread-divider { margin: 0 16px; }
  .internal-note, .reply-area { margin-right: 16px; margin-left: 16px; }
  .reply-area { grid-template-columns: 1fr; }
  .reply-actions { display: flex; flex-wrap: wrap; }
  .ticket-id { width: 100%; margin-left: 0; }
  .detail-summary { gap: 5px; }
  .attachments { margin-top: 20px; }
  .compose-button span { display: none; }
  .compose-button { width: 42px; justify-content: center; padding: 0; }
}

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