:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
  color: #1f2933;
  background: #f4f7f8;
  --bg: #f4f7f8;
  --surface: #ffffff;
  --line: #d7e0e3;
  --line-strong: #9fb1b8;
  --text: #1f2933;
  --muted: #65747b;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --blue: #2563eb;
  --amber: #b7791f;
  --red: #b42318;
  --green: #15803d;
  --sidebar: #243238;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
}

body.drawer-open {
  overflow: hidden;
}

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

button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.button-primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #ffffff;
}

.button-primary:hover {
  background: var(--teal-dark);
  color: #ffffff;
}

.button-danger {
  border-color: #e4a29a;
  color: var(--red);
}

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

.textarea {
  min-height: 84px;
  resize: vertical;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(244, 247, 248, 0.95)),
    var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 44px rgba(20, 35, 42, 0.12);
}

.login-panel h1 {
  margin: 0 0 4px;
  font-size: 24px;
  letter-spacing: 0;
}

.login-panel p {
  margin: 0 0 24px;
  color: var(--muted);
}

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

.field {
  display: grid;
  gap: 6px;
}

.field > span,
.field label {
  font-size: 13px;
  color: #415059;
}

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

.sidebar {
  background: var(--sidebar);
  color: #e6eef0;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: grid;
  gap: 2px;
  padding: 0 8px;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
}

.brand-subtitle {
  font-size: 12px;
  color: #a8bbc2;
}

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

.nav button {
  width: 100%;
  justify-content: flex-start;
  border-color: transparent;
  background: transparent;
  color: #d5e1e5;
  text-align: left;
}

.nav button.active,
.nav button:hover {
  background: #34474f;
  color: #ffffff;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 0 8px;
  font-size: 12px;
  color: #b7c6cb;
}

.main {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.content {
  min-width: 0;
  padding: 20px 24px 28px;
}

.toolbar {
  display: grid;
  grid-template-columns: 180px minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.data-summary {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #bfd9cf;
  border-radius: 10px;
  background: #eff9f4;
  color: #315b4d;
  font-size: 14px;
  line-height: 1.5;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 10px;
}

.metric-card {
  display: grid;
  gap: 6px;
  min-height: 92px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  color: var(--teal-dark);
  font-size: 28px;
  line-height: 1;
}

.data-note {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
}

.user-toolbar {
  grid-template-columns: minmax(260px, 1fr) auto auto;
}

.feedback-toolbar {
  grid-template-columns: minmax(260px, 1fr) auto auto;
}

.error-filter-panel {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.error-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.flow-filter-panel {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.flow-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.flow-filters label {
  display: grid;
  gap: 6px;
  color: #415059;
  font-size: 13px;
}

.flow-filters select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
}

.analytics-stack {
  display: grid;
  gap: 16px;
}

.analytics-panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.analytics-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.analytics-panel-header h3 {
  margin: 0 0 4px;
  font-size: 17px;
}

.analytics-panel-header p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.duration-bars {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid #dce9e6;
  border-radius: 8px;
  background: #f7fbfa;
}

.duration-bars .empty {
  padding: 24px 12px;
}

.duration-row {
  display: grid;
  gap: 6px;
}

.duration-row-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
}

.duration-row-meta strong {
  color: var(--teal-dark);
}

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

.duration-bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.analytics-table {
  min-width: 820px;
}

.analytics-model-table {
  min-width: 1050px;
}

.analytics-character-card-table {
  min-width: 1120px;
}

.analytics-table .number-cell {
  text-align: center;
}

.filter-keyword {
  grid-column: span 2;
}

.filter-actions,
.pagination {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.filter-actions {
  justify-content: flex-end;
  padding-top: 2px;
}

.pagination {
  justify-content: flex-end;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
}

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

.error-table {
  min-width: 1560px;
}

.feedback-table {
  min-width: 1120px;
}

.app-user-table {
  min-width: 1710px;
}

.app-user-table .number-cell {
  color: var(--teal-dark);
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}

.table-sort-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
}

.table-sort-button:hover,
.table-sort-button:focus-visible,
.table-sort-button.active {
  color: var(--teal);
}

.sort-indicator {
  font-size: 12px;
  line-height: 1;
}

.view-projects-button {
  white-space: nowrap;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  justify-content: flex-end;
  background: rgba(17, 31, 38, 0.42);
}

.project-drawer {
  width: min(760px, calc(100vw - 48px));
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg);
  box-shadow: -18px 0 44px rgba(20, 35, 42, 0.2);
}

.project-drawer-header {
  min-height: 76px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.project-drawer-header h3,
.project-drawer-header p,
.user-project-card h4 {
  margin: 0;
}

.project-drawer-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.drawer-close {
  flex: 0 0 auto;
}

.drawer-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.project-drawer-body {
  min-height: 0;
  overflow: auto;
  padding: 18px 20px 24px;
}

.drawer-loading,
.drawer-error {
  min-height: 220px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}

.drawer-error p {
  margin: 0;
  color: var(--red);
}

.drawer-user-summary {
  margin-bottom: 14px;
  padding: 13px 14px;
  border: 1px solid #bfd9cf;
  border-radius: 8px;
  background: #eff9f4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
}

.drawer-user-summary > div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.user-project-list {
  display: grid;
  gap: 12px;
}

.user-project-card {
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.user-project-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.user-project-card h4 {
  margin-bottom: 3px;
  font-size: 16px;
}

.project-payment-tags {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.project-tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafb;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.project-tag-paid {
  border-color: #8fc99f;
  background: #eefbf1;
  color: var(--green);
}

.user-project-facts {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid #e7edef;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px 16px;
}

.user-project-facts > div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.user-project-facts dt {
  color: var(--muted);
  font-size: 12px;
}

.user-project-facts dd {
  margin: 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.drawer-pagination {
  margin-top: 16px;
}

.drawer-empty {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
}

.feedback-table th:nth-child(1),
.feedback-table td:nth-child(1) {
  width: 170px;
}

.feedback-table th:nth-child(2),
.feedback-table td:nth-child(2) {
  width: 180px;
}

.feedback-table th:nth-child(4),
.feedback-table td:nth-child(4) {
  width: 290px;
}

.feedback-table th:nth-child(5),
.feedback-table td:nth-child(5) {
  width: 190px;
}

.feedback-content {
  min-width: 280px;
  max-width: 560px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.feedback-thumbnails {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px;
}

.feedback-thumbnail-link {
  display: grid;
  gap: 4px;
  color: var(--teal-dark);
  font-size: 12px;
  text-decoration: none;
}

.feedback-thumbnail {
  display: block;
  width: 76px;
  height: 76px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #f8fafb;
  object-fit: cover;
}

.error-table th:nth-child(7),
.error-table td:nth-child(7) {
  width: 340px;
}

.error-table th:nth-child(9),
.error-table td:nth-child(9) {
  width: 180px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid #e7edef;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8fafb;
  color: #43525a;
  font-size: 12px;
  font-weight: 700;
}

tr:last-child td {
  border-bottom: 0;
}

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

.strong {
  font-weight: 700;
}

.nowrap {
  white-space: nowrap;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.error-code {
  display: inline-block;
  max-width: 180px;
  padding: 3px 6px;
  border-radius: 4px;
  background: #fff1ef;
  color: var(--red);
  overflow-wrap: anywhere;
  white-space: normal;
}

.error-reason {
  max-width: 340px;
  max-height: 6em;
  overflow: hidden;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  background: #f8fafb;
}

.status-paid_waiting_print,
.status-printing {
  border-color: #f0c36a;
  color: var(--amber);
  background: #fff8e8;
}

.status-printed {
  border-color: #87b7e8;
  color: var(--blue);
  background: #eff6ff;
}

.status-shipped,
.status-completed,
.status-active {
  border-color: #8fc99f;
  color: var(--green);
  background: #eefbf1;
}

.status-cancelled,
.status-refund_failed,
.status-disabled {
  border-color: #efb0a8;
  color: var(--red);
  background: #fff1ef;
}

.status-refund_pending,
.status-refunded {
  border-color: #87b7e8;
  color: var(--blue);
  background: #eff6ff;
}

.grid-detail {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel-header {
  min-height: 52px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header h3 {
  margin: 0;
  font-size: 15px;
}

.panel-body {
  padding: 16px;
}

.definition-grid {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 10px 14px;
  font-size: 14px;
}

.definition-grid dt {
  color: var(--muted);
}

.definition-grid dd {
  margin: 0;
  word-break: break-word;
}

.inline-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.table-actions,
.pdf-actions,
.pdf-info-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.pdf-actions {
  margin-bottom: 6px;
}

.table-actions button,
.pdf-actions button,
.pdf-info-row button {
  min-height: 32px;
  padding: 0 10px;
  white-space: nowrap;
}

.pdf-info-row {
  justify-content: space-between;
}

.pdf-info-row span {
  min-width: 0;
}

.paper-layout-preview {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.paper-layout-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.paper-layout-preview h3,
.paper-layout-preview p {
  margin: 0;
}

.paper-layout-preview p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.paper-layout-preview-empty {
  padding: 24px;
  text-align: center;
}

.paper-layout-progress {
  max-width: 480px;
  margin: 18px auto 0;
  text-align: left;
}

.paper-layout-progress-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
}

.paper-layout-progress-copy strong {
  color: var(--text);
}

.paper-layout-progress-track {
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}

.paper-layout-progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 180ms ease;
}

.paper-layout-error {
  color: #b45309 !important;
}

.print-pdf-frame {
  display: block;
  width: 100%;
  min-height: 760px;
  border: 0;
  background: #eef2f3;
}

.section-stack {
  display: grid;
  gap: 16px;
}

.message {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 6px;
  color: var(--muted);
}

.message.error {
  border-color: #efb0a8;
  color: var(--red);
  background: #fff7f5;
}

.message.success {
  border-color: #8fc99f;
  color: var(--green);
  background: #f2fbf4;
}

.empty {
  padding: 44px 16px;
  text-align: center;
  color: var(--muted);
}

.admin-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

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

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

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

  .sidebar-footer {
    display: none;
  }

  .toolbar,
  .grid-detail,
  .admin-form,
  .metric-grid {
    grid-template-columns: 1fr;
  }

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

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

  .filter-keyword {
    grid-column: span 2;
  }

  .topbar {
    height: auto;
    padding: 14px 16px;
    align-items: flex-start;
    flex-direction: column;
  }

  .content {
    padding: 16px;
  }

  .paper-layout-preview-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .print-pdf-frame {
    min-height: 560px;
  }
}

@media (max-width: 560px) {
  .error-filters,
  .flow-filters {
    grid-template-columns: 1fr;
  }

  .filter-keyword {
    grid-column: auto;
  }

  .filter-actions,
  .pagination {
    justify-content: stretch;
  }

  .filter-actions button,
  .pagination button {
    flex: 1 1 auto;
  }

  .project-drawer {
    width: 100vw;
  }

  .project-drawer-header,
  .project-drawer-body {
    padding-left: 14px;
    padding-right: 14px;
  }

  .drawer-user-summary,
  .user-project-card-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .project-payment-tags {
    justify-content: flex-start;
  }

  .user-project-facts {
    grid-template-columns: 1fr;
  }
}
