:root {
  --app-ink: #172033;
  --app-muted: #718096;
  --app-line: #e5eaf3;
  --app-bg: #f4f7fb;
  --app-panel: #ffffff;
  --app-primary: #2563eb;
  --app-primary-soft: #eaf2ff;
  --nav-bg: #ffffff;
  --nav-fg: #172033;
  --nav-muted: #718096;
  --nav-active-bg: #eaf2ff;
  --nav-active-fg: #1d4ed8;
  --nav-border: #e5eaf3;
}

body {
  background: var(--app-bg);
  color: var(--app-ink);
  letter-spacing: 0;
}

a {
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
  background: var(--app-bg);
}

.app-shell[data-nav-theme="blue"] {
  --nav-bg: #14213d;
  --nav-fg: #ffffff;
  --nav-muted: #b8c4d8;
  --nav-active-bg: rgba(255, 255, 255, .16);
  --nav-active-fg: #ffffff;
  --nav-border: rgba(255, 255, 255, .12);
  --app-primary: #2563eb;
  --app-primary-soft: #eaf2ff;
}

.app-shell[data-nav-theme="yellow"] {
  --nav-bg: #fff8e6;
  --nav-fg: #3b2a06;
  --nav-muted: #8a6a19;
  --nav-active-bg: #ffedba;
  --nav-active-fg: #9a5b00;
  --nav-border: #f4dd9a;
  --app-primary: #d97706;
  --app-primary-soft: #fff4d8;
}

.app-shell[data-nav-theme="green"] {
  --nav-bg: #ecfdf5;
  --nav-fg: #083b2c;
  --nav-muted: #407866;
  --nav-active-bg: #d1fae5;
  --nav-active-fg: #047857;
  --nav-border: #bcebd7;
  --app-primary: #059669;
  --app-primary-soft: #e1fbef;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1040;
  height: 66px;
  padding: 0 22px;
  background: var(--nav-bg);
  color: var(--nav-fg);
  border-bottom: 1px solid var(--nav-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 8px 24px rgba(23, 32, 51, .05);
}

.topbar-left,
.topbar-actions,
.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-mini {
  display: inline-flex;
  align-items: center;
}

.mini-status-button {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--nav-fg);
  display: inline-flex;
  align-items: center;
}

.mini-status-button::after {
  color: var(--nav-muted);
  margin-left: 6px;
}

.mini-qr-menu {
  min-width: 188px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--app-line);
  box-shadow: 0 14px 40px rgba(23, 32, 51, .12);
}

.mini-qr-frame {
  background: #fff;
  border: 1px solid var(--app-line);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  justify-content: center;
}

.mini-qr-image,
.mini-qr-frame .qrcode-box,
.mini-qr-frame .qrcode-box img,
.mini-qr-frame .qrcode-box canvas {
  width: 132px !important;
  height: 132px !important;
}

.mini-qr-caption {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: center;
}

.mini-qr-caption strong {
  color: var(--app-ink);
  font-size: 13px;
}

.mini-qr-caption span {
  color: var(--app-muted);
  font-size: 12px;
  word-break: break-all;
}

.sidebar-toggle {
  border: 1px solid var(--nav-border);
  background: rgba(255, 255, 255, .72);
  color: var(--nav-fg);
  border-radius: 8px;
}

.sidebar-toggle {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.brand-mark,
.login-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--app-primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 23px;
  font-weight: 800;
}

.brand-mark:hover {
  color: #fff;
}

.brand-copy,
.user-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.22;
}

.brand-name {
  color: var(--nav-fg);
  font-size: 17px;
  font-weight: 800;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy span,
.user-copy small {
  color: var(--nav-muted);
  font-size: 12px;
}

.user-menu-button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--nav-fg);
  box-shadow: none;
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 9px;
  border-radius: 8px;
}

.user-menu-button:hover,
.user-menu-button:focus,
.user-menu-button.show {
  background: transparent;
  color: var(--nav-fg);
  box-shadow: none;
  outline: none;
}

.user-menu-button::after {
  color: var(--nav-muted);
  margin-left: 2px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--app-primary-soft);
  color: var(--app-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}

.user-copy strong {
  color: var(--nav-fg);
  font-size: 14px;
}

.user-dropdown-menu {
  border-radius: 8px;
  border-color: var(--app-line);
  box-shadow: 0 14px 40px rgba(23, 32, 51, .12);
}

.user-dropdown-menu .dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-body {
  display: flex;
  min-height: calc(100vh - 66px);
}

.app-sidebar {
  width: 244px;
  flex: 0 0 244px;
  background: var(--nav-bg);
  color: var(--nav-fg);
  border-right: 1px solid var(--nav-border);
  padding: 20px 12px;
  transition: width .18s ease, flex-basis .18s ease;
}

.app-sidebar-section {
  position: sticky;
  top: 86px;
}

.sidebar-label {
  color: var(--nav-muted);
  font-size: 12px;
  font-weight: 800;
  margin: 0 10px 12px;
}

.sidebar-menu {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-item {
  margin-bottom: 6px;
}

.sidebar-item a {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--nav-fg);
  border-radius: 8px;
  padding: 0 12px;
  transition: background .15s ease, color .15s ease;
}

.sidebar-item a:hover {
  background: rgba(37, 99, 235, .08);
  color: var(--nav-active-fg);
}

.sidebar-item.active a {
  background: var(--nav-active-bg);
  color: var(--nav-active-fg);
  font-weight: 800;
}

.sidebar-item i {
  font-size: 20px;
  width: 24px;
  text-align: center;
}

body.sidebar-collapsed .app-sidebar {
  width: 76px;
  flex-basis: 76px;
}

body.sidebar-collapsed .sidebar-label,
body.sidebar-collapsed .sidebar-item span {
  display: none;
}

body.sidebar-collapsed .sidebar-item a {
  justify-content: center;
  padding: 0;
}

.app-main {
  flex: 1;
  min-width: 0;
  padding: 26px;
  transition: opacity .15s ease;
}

.app-main.is-loading {
  opacity: .55;
}

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.page-heading h1 {
  font-size: 24px;
  line-height: 1.2;
  margin: 0;
  font-weight: 800;
  color: var(--app-ink);
}

.page-heading p {
  margin: 6px 0 0;
  color: var(--app-muted);
}

.page-heading-action {
  display: flex;
  justify-content: flex-end;
  min-width: 280px;
}

.dashboard-site-filter {
  min-width: 280px;
}

.dashboard-site-filter .form-control {
  min-height: 42px;
}

.card {
  border: 1px solid var(--app-line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(23, 32, 51, .05);
}

.card .card-body {
  padding: 22px;
}

.card-title {
  font-weight: 800;
  color: var(--app-ink);
}

.btn {
  border-radius: 8px;
  font-weight: 650;
}

.btn-primary {
  background: var(--app-primary);
  border-color: var(--app-primary);
}

.btn-outline-primary {
  color: var(--app-primary);
  border-color: var(--app-primary);
}

.form-control,
.form-select {
  border-radius: 8px;
  border-color: #d8deea;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label,
.form-check-label {
  color: #344054;
  font-weight: 650;
}

.markdown-toolbar {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border: 1px solid #d8deea;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: #f8fafc;
}

.md-tool {
  width: 30px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #475569;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
}

.md-tool:hover,
.md-tool:focus {
  background: var(--app-primary-soft);
  color: var(--app-primary);
  outline: none;
}

.markdown-textarea {
  min-height: 220px;
  resize: vertical;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.65;
}

.markdown-textarea.markdown-compact {
  height: 150px;
  min-height: 150px;
}

.app-drawer .markdown-textarea {
  min-height: 300px;
}

.app-drawer .markdown-textarea.markdown-compact {
  height: 180px;
  min-height: 180px;
}

.markdown-preview {
  margin-top: 10px;
  border: 1px solid var(--app-line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.markdown-preview-title {
  min-height: 34px;
  padding: 8px 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--app-line);
  color: #526177;
  font-size: 12px;
  font-weight: 800;
}

.markdown-preview-body {
  padding: 12px;
  max-height: 260px;
  overflow: auto;
}

.markdown-compact + .markdown-preview .markdown-preview-body {
  max-height: 150px;
}

.markdown-body {
  color: var(--app-ink);
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}

.markdown-body p,
.markdown-body ul,
.markdown-body blockquote,
.markdown-body pre {
  margin: 0 0 10px;
}

.markdown-body p:last-child,
.markdown-body ul:last-child,
.markdown-body blockquote:last-child,
.markdown-body pre:last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  color: var(--app-ink);
  font-weight: 800;
  margin: 0 0 10px;
  line-height: 1.35;
}

.markdown-body h1 { font-size: 22px; }
.markdown-body h2 { font-size: 19px; }
.markdown-body h3 { font-size: 17px; }
.markdown-body h4 { font-size: 15px; }

.markdown-body ul {
  padding-left: 20px;
}

.markdown-body blockquote {
  border-left: 3px solid var(--app-primary);
  padding: 8px 10px;
  background: #f8fafc;
  color: #526177;
  border-radius: 6px;
}

.markdown-body code {
  color: #be123c;
  background: #fff1f2;
  border-radius: 4px;
  padding: 2px 5px;
}

.markdown-body pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 8px;
  overflow: auto;
}

.markdown-body pre code {
  color: inherit;
  background: transparent;
  padding: 0;
}

.announcement-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.announcement-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--app-line);
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  color: var(--app-ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.announcement-item:hover,
.announcement-item:focus {
  border-color: var(--app-primary);
  box-shadow: 0 10px 24px rgba(37, 99, 235, .1);
  outline: none;
}

.announcement-title {
  display: block;
  margin-bottom: 6px;
  font-weight: 800;
}

.announcement-summary {
  max-height: 96px;
  overflow: hidden;
}

.announcement-detail-modal .modal-content {
  border: 0;
  border-radius: 8px;
}

.form-check {
  min-height: 32px;
  padding-left: 2.75em;
  display: flex;
  align-items: center;
}

.form-check .form-check-input {
  float: none;
  margin-left: -2.75em;
  margin-top: 0;
}

.table {
  color: var(--app-ink);
}

.table td,
.table th {
  vertical-align: middle;
  border-color: #edf1f6;
}

.table thead th {
  background: #f7f9fc;
  color: #526177;
  font-size: 12px;
  font-weight: 800;
}

.table-select-cell {
  width: 42px;
  text-align: center;
}

.table-bulk-actions {
  min-height: 38px;
  padding: 8px 10px;
  background: #f8fafc;
  border: 1px solid var(--app-line);
  border-radius: 8px;
}

.bulk-check-all {
  display: inline-flex;
  align-items: center;
  margin: 0;
  color: #344054;
  font-weight: 650;
}

.table-pagination {
  border-top: 1px solid var(--app-line);
  margin-top: 12px;
  padding-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.pagination-summary {
  color: var(--app-muted);
  font-size: 13px;
}

.table-pagination .page-link {
  border-color: var(--app-line);
  color: var(--app-primary);
}

.table-pagination .page-item.active .page-link {
  background: var(--app-primary);
  border-color: var(--app-primary);
}

.badge {
  border-radius: 6px;
  padding: 6px 9px;
}

.metric-card {
  border: 1px solid var(--app-line);
  border-radius: 8px;
  cursor: pointer;
  min-height: 118px;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.metric-card:hover,
.metric-card.active {
  transform: translateY(-2px);
  border-color: var(--app-primary);
  box-shadow: 0 12px 28px rgba(37, 99, 235, .13);
}

.metric-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.metric-icon {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--app-primary-soft);
  color: var(--app-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.metric-card .metric-value {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 0;
  color: var(--app-primary);
}

.action-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.mini-preview {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border: 1px solid var(--app-line);
  border-radius: 8px;
}

.code-list {
  max-height: 280px;
  overflow: auto;
  background: #f8fafc;
  border: 1px solid var(--app-line);
  border-radius: 8px;
  padding: 12px;
  font-family: Consolas, Monaco, monospace;
  font-size: 13px;
}

.renew-summary {
  border: 1px solid var(--app-line);
  border-radius: 8px;
  background: #f8fafc;
  margin-bottom: 18px;
  overflow: hidden;
}

.renew-summary > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}

.renew-summary > div + div {
  border-top: 1px solid var(--app-line);
}

.renew-summary span {
  color: var(--app-muted);
}

.renew-summary strong {
  color: var(--app-ink);
  font-size: 18px;
}

.nowrap {
  white-space: nowrap;
}

.text-break-all {
  word-break: break-all;
}

.qrcode-box {
  width: 136px;
  min-height: 136px;
  border: 1px dashed #b7c2d4;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  background: #fff;
}

.mini-program-qr {
  width: 136px;
  height: 136px;
  object-fit: contain;
  border: 1px solid var(--app-line);
  border-radius: 8px;
  background: #fff;
  padding: 6px;
}

.app-toast-stack {
  position: fixed;
  top: 82px;
  right: 22px;
  z-index: 3000;
  width: min(360px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.app-toast {
  transform: translateX(18px);
  opacity: 0;
  pointer-events: auto;
  background: #fff;
  border: 1px solid var(--app-line);
  border-left: 4px solid var(--app-primary);
  border-radius: 8px;
  box-shadow: 0 18px 42px rgba(23, 32, 51, .16);
  padding: 13px 12px;
  display: grid;
  grid-template-columns: 26px 1fr 24px;
  align-items: start;
  gap: 8px;
  transition: opacity .2s ease, transform .2s ease;
}

.app-toast.show {
  opacity: 1;
  transform: translateX(0);
}

.app-toast-icon {
  color: var(--app-primary);
  font-size: 21px;
  line-height: 1;
}

.app-toast-message {
  color: var(--app-ink);
  font-size: 14px;
  line-height: 1.45;
}

.app-toast-close {
  border: 0;
  background: transparent;
  color: var(--app-muted);
  font-size: 18px;
  line-height: 1;
  padding: 0;
}

.app-toast-warning {
  border-left-color: #f59e0b;
}

.app-toast-warning .app-toast-icon {
  color: #d97706;
}

.app-toast-danger {
  border-left-color: #dc2626;
}

.app-toast-danger .app-toast-icon {
  color: #dc2626;
}

.offcanvas.app-drawer {
  width: min(560px, 100vw);
  border-left: 1px solid var(--app-line);
}

.app-drawer .offcanvas-header {
  background: #f8fafc;
  border-bottom: 1px solid var(--app-line);
  min-height: 64px;
}

.app-drawer .offcanvas-title {
  font-weight: 800;
  color: var(--app-ink);
}

.app-drawer .offcanvas-body {
  padding: 22px;
  overflow-y: auto;
}

.drawer-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: #fff;
  border-top: 1px solid var(--app-line);
  margin: 24px -22px -22px;
  padding: 16px 22px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.theme-grid {
  display: grid;
  gap: 12px;
}

.theme-choice {
  width: 100%;
  border: 1px solid var(--app-line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  text-align: left;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 4px 12px;
  align-items: center;
}

.theme-choice span {
  grid-row: span 2;
  width: 38px;
  height: 38px;
  border: 1px solid var(--app-line);
  border-radius: 8px;
}

.theme-choice strong {
  color: var(--app-ink);
}

.theme-choice small {
  color: var(--app-muted);
}

.theme-choice.active {
  border-color: var(--app-primary);
  background: var(--app-primary-soft);
}

.login-shell {
  min-height: 100vh;
  background: linear-gradient(135deg, #f8fbff 0%, #edf4ff 55%, #dbeafe 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 8px;
  padding: 34px;
  box-shadow: 0 24px 64px rgba(23, 32, 51, .13);
}

.login-card .login-mark {
  margin-bottom: 18px;
}

.login-card h3 {
  font-weight: 800;
  margin-bottom: 4px;
}

.login-card > p {
  color: var(--app-muted);
  margin-bottom: 24px;
}

@media (max-width: 991px) {
  .brand-copy {
    display: none;
  }

  .app-sidebar {
    position: fixed;
    top: 66px;
    bottom: 0;
    left: 0;
    z-index: 1030;
    transform: translateX(-100%);
  }

  body.sidebar-collapsed .app-sidebar,
  .app-sidebar {
    width: 244px;
    flex-basis: 244px;
  }

  body:not(.sidebar-collapsed) .app-sidebar {
    transform: translateX(0);
  }

  body.sidebar-collapsed .sidebar-label,
  body.sidebar-collapsed .sidebar-item span {
    display: block;
  }

  body.sidebar-collapsed .sidebar-item a {
    justify-content: flex-start;
    padding: 0 12px;
  }

  .app-main {
    padding: 18px;
  }

  .page-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .page-heading-action,
  .dashboard-site-filter {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 575px) {
  .app-topbar {
    padding: 0 12px;
  }

  .user-copy,
  .topbar-user .badge {
    display: none;
  }

  .app-main {
    padding: 14px;
  }

  .page-heading h1 {
    font-size: 21px;
  }
}
