:root {
  --bg: #edf2f6;
  --panel: #ffffff;
  --paper: #ffffff;
  --line: #d7dfe8;
  --ink: #1f2937;
  --muted: #6b7280;
  --primary: #1178ea;
  --primary-soft: #e5f1ff;
  --danger: #cf374d;
  --accent: #f5eed5;
  --shadow: 0 16px 48px rgba(15, 23, 42, 0.08);
  --radius: 20px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(17, 120, 234, 0.12), transparent 22%),
    linear-gradient(180deg, #f8fafc, var(--bg));
}

.toast-stack {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 40;
  display: grid;
  gap: 10px;
}

.toast {
  min-width: 240px;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
  transform: translateY(-8px);
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  border-color: #b9e7d6;
  background: #effcf6;
  color: #0f7a5c;
}

.toast.error {
  border-color: #ffd2d9;
  background: #fff3f5;
  color: #b4233f;
}

.toast.info {
  border-color: #cfe0ff;
  background: #f3f8ff;
  color: #1f4db5;
}

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

.hidden {
  display: none !important;
}

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

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--primary);
  font-size: 12px;
}

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

.auth-screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(237, 242, 246, 0.96);
  z-index: 20;
}

.auth-screen.visible {
  display: flex;
}

.auth-card {
  width: min(100%, 420px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

.auth-copy {
  color: var(--muted);
  line-height: 1.6;
}

.auth-error {
  min-height: 22px;
  margin-top: 12px;
  color: var(--danger);
}

.app-shell {
  min-height: 100vh;
}

.global-topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
}

.topbar-brand .eyebrow {
  margin-bottom: 2px;
}

.topbar-brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  font-weight: 800;
}

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

.topbar-user p {
  margin-bottom: 0;
}

.topbar-user-info {
  text-align: right;
}

.topbar-user-info strong {
  display: block;
  font-size: 15px;
  line-height: 1.2;
}

.topbar-user-info p {
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.3;
}

#logout-button {
  padding: 10px 14px;
}

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

.shell-sidebar {
  padding: 24px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
}

.admin-sidebar {
  background:
    linear-gradient(180deg, rgba(14, 25, 46, 0.98), rgba(18, 35, 67, 0.96)),
    #122343;
  border-right: none;
  color: #e8eef8;
}

.admin-sidebar .eyebrow {
  color: #76b7ff;
}

.admin-sidebar h2,
.admin-sidebar p,
.admin-sidebar span {
  color: inherit;
}

.admin-shell-nav .nav-item {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
  color: #dbe8fb;
}

.admin-shell-nav .nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.admin-shell-nav .nav-item.active {
  background: linear-gradient(90deg, #1178ea, #2591ff);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 12px 24px rgba(17, 120, 234, 0.22);
}

.shell-brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 22px;
}

.brand-mark,
.logo-mark {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), #0f4d9d);
  color: #fff;
  font-size: 28px;
  font-weight: 800;
}

.shell-nav {
  display: grid;
  gap: 10px;
}

.nav-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.primary-nav {
  font-weight: 800;
}

.shell-content {
  padding: 22px;
  overflow: auto;
  min-width: 0;
}

.admin-shell-content {
  background:
    radial-gradient(circle at top right, rgba(17, 120, 234, 0.08), transparent 28%),
    linear-gradient(180deg, #f4f7fb, #edf2f6);
}

.shell-section {
  display: grid;
  gap: 18px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.section-header.compact {
  margin-bottom: 10px;
}

.two-column,
.editor-layout {
  display: grid;
  gap: 18px;
}

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

.editor-layout {
  grid-template-columns: minmax(0, 1fr) minmax(380px, 0.9fr);
  align-items: start;
}

.panel,
.preview-wrap {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}

.preview-wrap {
  overflow: auto;
}

.panel.inset {
  padding: 16px;
  box-shadow: none;
  background: #fbfcfd;
}

.field-grid,
.field-stack,
.document-list,
.template-list,
.metrics-grid,
.status-grid {
  display: grid;
  gap: 12px;
}

.upload-box {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  background: #f8fbff;
}

.upload-box span {
  font-weight: 700;
}

.upload-box input[type="file"] {
  width: 100%;
}

.item-image-preview {
  width: 100%;
  min-height: 120px;
  border-radius: 14px;
  overflow: hidden;
  background: #eef4fb;
  border: 1px solid var(--line);
}

.item-image-preview img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  background: #fff;
}

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

.metrics-grid {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

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

.subsection-nav {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.detail-tabs {
  margin-top: 4px;
}

.subnav-item {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
}

.subnav-item.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.quick-link-card {
  text-align: left;
  cursor: pointer;
}

.quick-link-card strong {
  display: block;
  font-size: 20px;
  margin-bottom: 6px;
}

.toolbar-actions,
.template-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  border: none;
  border-radius: 999px;
  padding: 11px 16px;
  background: #e8edf4;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.ghost-button {
  background: transparent;
  border: 1px solid var(--line);
}

.danger-button {
  background: #fee8eb;
  color: var(--danger);
}

input,
textarea,
select {
  width: 100%;
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid #cfd8e3;
  border-radius: 12px;
  background: #fff;
}

textarea {
  resize: vertical;
}

.metric-card,
.detail-card,
.document-item,
.template-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.admin-form-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #fbfdff, #f6f9fc);
}

.admin-console-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.15fr) minmax(360px, 1fr) minmax(320px, 0.9fr);
  gap: 18px;
  align-items: start;
}

.admin-single-column {
  max-width: 1120px;
}

.admin-account-layout {
  align-items: start;
}

.admin-wide-form {
  gap: 16px;
}

.admin-detail-panel,
.admin-side-stack {
  display: grid;
  gap: 12px;
  align-content: start;
}

.admin-detail-panel {
  position: sticky;
  top: 22px;
  gap: 14px;
}

.admin-list,
.admin-table-list {
  display: grid;
  gap: 12px;
}

.admin-pagination {
  justify-content: flex-end;
}

.admin-list-row {
  width: 100%;
  text-align: left;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
}

.admin-list-row.active {
  border-color: var(--primary);
  background: linear-gradient(180deg, #eef6ff, #e4f0ff);
  box-shadow: 0 0 0 3px rgba(17, 120, 234, 0.08);
}

.admin-list-row:hover {
  border-color: #9ec7fb;
}

.admin-list-main,
.admin-list-meta,
.admin-inline-actions,
.detail-overview,
.detail-pills,
.detail-kpi-grid,
.detail-list-item,
.admin-data-head,
.admin-data-row {
  display: grid;
  gap: 10px;
}

.admin-list-main {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.admin-list-meta {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
}

.admin-inline-actions {
  grid-template-columns: repeat(auto-fit, minmax(96px, auto));
  margin-top: 12px;
}

.admin-inline-actions button {
  padding-inline: 14px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  text-transform: capitalize;
}

.status-pill.success {
  background: #e6f7f0;
  color: #0f7a5c;
}

.status-pill.warning {
  background: #fff4d6;
  color: #946200;
}

.status-pill.danger {
  background: #ffe8eb;
  color: #b4233f;
}

.status-pill.neutral {
  background: #edf2f7;
  color: #4b5563;
}

.detail-overview {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.detail-pills {
  grid-auto-flow: row;
  justify-items: end;
}

.detail-kpi-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 16px;
}

.mini-stat {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fbfcfe;
}

#admin-action-target {
  border-left: 4px solid var(--primary);
  background: linear-gradient(180deg, #f7fbff, #eef5ff);
}

.mini-stat strong {
  display: block;
  margin-top: 6px;
}

.detail-section h4 {
  margin-bottom: 10px;
  color: #1f4db5;
}

.detail-list {
  display: grid;
  gap: 10px;
}

.detail-list-item {
  grid-template-columns: minmax(0, 1.4fr) repeat(3, minmax(0, 1fr));
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdff;
}

.admin-data-head,
.admin-data-row {
  align-items: center;
  padding: 14px 16px;
  border-radius: 16px;
}

.admin-data-head {
  background: #eff5fb;
  color: var(--muted);
  font-weight: 700;
  border: 1px solid var(--line);
}

.admin-data-row {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #f9fbfe);
}

.admin-table-subscriptions {
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 140px 120px 140px;
}

.admin-table-orders {
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.2fr) minmax(0, 1fr) 120px 120px;
}

.admin-table-documents {
  grid-template-columns: minmax(0, 1.3fr) 120px minmax(0, 1.1fr) minmax(0, 1fr) 140px;
}

.metric-card-tight strong {
  font-size: 24px;
}

.admin-merchant-view {
  display: grid;
  gap: 18px;
}

#admin-user-list .template-item,
#admin-subscription-list .template-item,
#admin-order-list .template-item,
#admin-document-list .template-item,
#company-list .template-item,
#admin-plan-list .template-item {
  background: linear-gradient(180deg, #ffffff, #f8fbff);
}

#admin-user-list .template-item {
  border-left: 4px solid var(--primary);
}

#admin-order-list .template-item {
  border-left: 4px solid #0f7a5c;
}

#admin-document-list .template-item {
  border-left: 4px solid #c98716;
}

.metric-card strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
}

.document-item.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.document-tag,
.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

.status-warning,
.expired-banner {
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 700;
}

.status-warning {
  background: #fff7dd;
  color: #8a6110;
}

.expired-banner {
  background: #fff1f2;
  color: var(--danger);
  border: 1px solid #ffd7dd;
}

.top-gap {
  margin-top: 16px;
}

.items-editor {
  display: grid;
  gap: 14px;
}

.item-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.preview {
  padding: 8px;
}

.doc-paper {
  width: min(100%, 980px);
  max-width: 980px;
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
}

.doc-header {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 18px;
}

.doc-company h1 {
  margin-bottom: 6px;
}

.doc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 8px;
}

.doc-top,
.doc-footer {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-top: 24px;
}

.doc-title {
  text-align: center;
  margin-top: 28px;
}

.doc-title h2 {
  color: var(--primary);
  margin-bottom: 6px;
}

.doc-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin: 28px 0 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fbff;
}

.meta-label {
  display: block;
  color: var(--muted);
  margin-bottom: 6px;
  font-size: 13px;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 18px;
}

.doc-table th,
.doc-table td {
  border: 1px solid var(--line);
  padding: 12px;
  vertical-align: top;
}

.doc-table th {
  background: #edf3fb;
  color: #1f4db5;
}

.summary-row {
  background: #e4f2fd;
}

.image-box {
  min-width: 140px;
  min-height: 100px;
}

.image-box img {
  width: 100%;
  max-width: 160px;
  max-height: 120px;
  object-fit: cover;
  border-radius: 10px;
}

.logo-slot,
.seal-slot,
.signature-slot {
  display: flex;
  align-items: center;
}

.logo-slot {
  width: 60px;
  height: 60px;
}

.logo-slot img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  display: none;
}

.seal-slot img {
  max-width: 160px;
  max-height: 160px;
  object-fit: contain;
  display: none;
}

.signature-slot img {
  max-width: 180px;
  max-height: 70px;
  object-fit: contain;
  display: none;
}

.bank-section,
.terms-section {
  margin-top: 24px;
}

.bank-section h3,
.terms-section h3 {
  margin-bottom: 12px;
  padding-left: 12px;
  border-left: 4px solid var(--primary);
  color: var(--primary);
}

.bank-card {
  padding: 16px;
  background: var(--accent);
  border-radius: 12px;
}

.seal-placeholder {
  width: 140px;
  height: 140px;
  border: 5px solid #b21f3d;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #b21f3d;
  font-weight: 800;
  transform: rotate(-18deg);
}

@media (max-width: 1760px) {
  .shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .admin-console-grid {
    grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
  }

  .admin-side-stack {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-account-layout {
    grid-template-columns: 1fr;
  }

  .editor-layout {
    grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  }

  .doc-paper {
    padding: 22px;
  }

  .doc-company h1 {
    font-size: 44px;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 1680px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }

  .admin-quick-grid {
    grid-template-columns: 1fr;
  }

  .preview-wrap {
    order: 2;
  }

  .doc-paper {
    width: 100%;
    max-width: none;
  }
}

@media (max-width: 1280px) {
  .editor-layout,
  .two-column,
  .shell,
  .admin-console-grid,
  .admin-side-stack,
  .admin-table-subscriptions,
  .admin-table-orders,
  .admin-table-documents,
  .detail-list-item {
    grid-template-columns: 1fr;
  }

  .shell-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 720px) {
  .global-topbar,
  .topbar-user,
  .section-header,
  .doc-top,
  .doc-footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .field-grid.two,
  .doc-summary,
  .doc-header,
  .admin-list-main,
  .admin-list-meta,
  .detail-overview,
  .detail-kpi-grid {
    grid-template-columns: 1fr;
  }

  .detail-pills {
    justify-items: start;
  }

  .doc-table th,
  .doc-table td {
    font-size: 12px;
    padding: 9px;
  }
}

@media print {
  .global-topbar,
  .shell-sidebar,
  .section-header,
  .expired-banner,
  #merchant-section-home,
  #merchant-section-documents,
  #merchant-section-customers,
  #merchant-section-products,
  #merchant-section-company,
  #merchant-section-subscription,
  #admin-shell {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .shell,
  .shell-content {
    display: block;
    padding: 0;
  }

  .preview-wrap {
    border: none;
    box-shadow: none;
    padding: 0;
  }

  .doc-paper {
    border: none;
    box-shadow: none;
    border-radius: 0;
    max-width: none;
    padding: 10mm;
  }
}
