:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef4f6;
  --text: #18212f;
  --muted: #667085;
  --line: #dce3ea;
  --brand: #176b87;
  --brand-dark: #0d4458;
  --accent: #d97706;
  --success: #16875b;
  --warning: #b45309;
  --danger: #c2413d;
  --shadow: 0 20px 45px rgba(24, 33, 47, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, "Microsoft YaHei", "PingFang SC", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  background: #132331;
}

.login-shell {
  width: min(430px, calc(100% - 32px));
}

.login-card {
  display: grid;
  gap: 24px;
  border-radius: 8px;
  background: var(--surface);
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-brand strong {
  color: var(--text);
}

.login-brand span {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-weight: 700;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  background: #132331;
  color: #f7fbfc;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #f6c453;
  color: #17202d;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.sidebar-card span {
  color: #b6c2cc;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.role-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.role-button {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: #dbe5ec;
  font-weight: 800;
}

.role-button.active {
  background: #f6c453;
  color: #17202d;
}

.client-mode .admin-only {
  display: none;
}

.client-mode .manager-only,
.client-mode .super-admin-only,
.staff-mode .super-admin-only {
  display: none;
}

.nav-item {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #dbe5ec;
  text-align: left;
  padding: 0 14px;
}

.nav-item.active,
.nav-item:hover {
  background: #244256;
  color: #ffffff;
}

.sidebar-card {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.05);
}

.sidebar-card strong {
  display: block;
  margin: 6px 0;
}

.sidebar-card p {
  margin: 0;
  color: #cfdae1;
  font-size: 13px;
  line-height: 1.6;
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar,
.section-head,
.panel-heading,
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-actions {
  display: flex;
  align-items: end;
  gap: 12px;
}

.language-picker {
  min-width: 130px;
}

.language-picker select {
  min-height: 40px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(26px, 4vw, 38px);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 19px;
}

.primary-action,
.secondary-action,
.edit-action,
.danger-action,
.restore-action {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 700;
}

.primary-action {
  background: var(--brand);
  color: #ffffff;
}

.secondary-action {
  background: #dcebf0;
  color: var(--brand-dark);
}

.edit-action {
  background: #fff3d7;
  color: var(--warning);
}

.danger-action {
  background: #fde2df;
  color: var(--danger);
}

.restore-action {
  background: #ddf4e9;
  color: var(--success);
}

.danger-action:disabled,
.restore-action:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.full {
  width: 100%;
}

.view {
  display: none;
  margin-top: 26px;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.metric,
.panel,
.entity-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span,
.metric small {
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 34px;
}

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  gap: 18px;
  margin-top: 18px;
}

.panel {
  padding: 18px;
}

.bar-list,
.recent-list {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.bar-row {
  display: grid;
  gap: 8px;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 14px;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e9eef3;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
}

.recent-item {
  display: grid;
  gap: 6px;
  width: 100%;
  border: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
}

.recent-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.muted {
  color: var(--muted);
}

.toolbar {
  display: grid;
  grid-template-columns: 2fr repeat(3, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px auto;
  align-items: end;
  gap: 12px;
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 7px;
}

label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 10px 11px;
}

.compact-select {
  margin-top: 3px;
  min-height: 34px;
  padding: 6px 9px;
  font-weight: 700;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

.table-panel {
  overflow-x: auto;
  padding: 0;
  margin-top: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: var(--surface-soft);
}

.status,
.priority {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status.pending {
  background: #fff3d7;
  color: var(--warning);
}

.status.progress {
  background: #dcebf0;
  color: var(--brand-dark);
}

.status.done {
  background: #ddf4e9;
  color: var(--success);
}

.priority.high {
  background: #fde2df;
  color: var(--danger);
}

.priority.medium {
  background: #fff3d7;
  color: var(--warning);
}

.priority.low {
  background: #e8f3ed;
  color: var(--success);
}

.priority.unset {
  background: #ebedf0;
  color: #58616b;
}

.detail-page-head {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 16px;
}

.ticket-detail-page {
  display: grid;
  gap: 18px;
}

.detail-page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
  gap: 18px;
  align-items: stretch;
}

.detail-block {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.ticket-detail-page .detail-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 0;
  padding: 18px;
}

.detail-block:last-child {
  border-bottom: 0;
  margin-bottom: 0;
  padding-bottom: 0;
}

.ticket-detail-page .detail-block:last-child {
  border: 1px solid var(--line);
  padding: 18px;
}

.conversation-block {
  min-height: 620px;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.info-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.info-grid strong {
  display: block;
  margin-top: 3px;
  font-size: 14px;
}

.chat-list {
  display: grid;
  gap: 10px;
  max-height: 640px;
  overflow: auto;
  padding-right: 4px;
}

.message {
  max-width: 82%;
  border-radius: 8px;
  padding: 10px 12px;
  background: #edf1f5;
}

.message.staff {
  justify-self: end;
  background: #dcebf0;
}

.message strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.message p {
  margin: 0;
  line-height: 1.5;
}

.message time {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.attachment-list {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.attachment {
  border: 1px solid rgba(102, 112, 133, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
  color: inherit;
  text-decoration: none;
}

.image-attachment {
  display: grid;
  gap: 6px;
  padding: 8px;
}

.image-attachment img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: cover;
  border-radius: 6px;
}

.image-attachment span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.file-attachment {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
}

.file-icon {
  display: grid;
  width: 38px;
  height: 34px;
  place-items: center;
  border-radius: 6px;
  background: #ddf4e9;
  color: var(--success);
  font-size: 11px;
  font-weight: 800;
}

.file-attachment strong,
.file-attachment small {
  display: block;
}

.file-attachment strong {
  overflow-wrap: anywhere;
  font-size: 13px;
}

.file-attachment small {
  color: var(--muted);
  margin-top: 2px;
}

.reply-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  margin-top: 14px;
}

.reply-box input {
  min-width: 0;
}

.attach-button {
  display: grid;
  min-height: 40px;
  min-width: 72px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--brand-dark);
  font-weight: 800;
  cursor: pointer;
}

.attach-button input {
  display: none;
}

.attachment-hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.card-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.entity-card {
  padding: 18px;
}

.deleted-card {
  border-style: dashed;
  background: #f8fafc;
  box-shadow: none;
  opacity: 0.9;
}

.archive-heading {
  grid-column: 1 / -1;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.entity-card h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.entity-card dl {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
}

.entity-card div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.entity-card .entity-actions {
  justify-content: flex-end;
  margin-top: 14px;
}

.entity-card dt {
  color: var(--muted);
}

.entity-card dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(17, 24, 39, 0.48);
}

.modal.open {
  display: grid;
}

.modal-content {
  display: grid;
  gap: 14px;
  width: min(540px, 100%);
  border-radius: 8px;
  background: var(--surface);
  padding: 20px;
  box-shadow: var(--shadow);
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 22px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.checkbox-list {
  display: grid;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
}

.checkbox-row input {
  width: auto;
}

.checkbox-row span {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

@media (max-width: 1100px) {
  .metric-grid,
  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-layout,
  .detail-page-grid {
    grid-template-columns: 1fr;
  }

  .chat-list {
    max-height: 560px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 16px;
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .nav-item {
    min-height: 38px;
    padding: 0 8px;
    text-align: center;
    font-size: 13px;
  }

  .sidebar-card {
    display: none;
  }

  .main {
    padding: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .metric-grid,
  .toolbar,
  .inline-form,
  .card-grid,
  .card-grid.compact,
  .form-row,
  .reply-box {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 94%;
  }
}
