:root {
  --bg: #f7f5fa;
  --surface: #ffffff;
  --surface-soft: #fbf9fd;
  --line: #ded8e8;
  --line-strong: #cfc4dd;
  --text: #18131f;
  --muted: #726b7c;
  --faint: #9a93a5;
  --primary: #854db9;
  --primary-dark: #6b39a0;
  --primary-soft: #ead0ff;
  --green: #68c76f;
  --red: #e56570;
  --shadow: 0 18px 48px rgba(41, 28, 58, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.admin-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
}

.admin-login-card {
  width: min(520px, 100%);
  padding: 40px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.admin-login-card h1,
.admin-topbar h1,
.dialog-card h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.25;
}

.login-copy {
  margin: 16px 0 24px;
  color: var(--muted);
  line-height: 1.7;
}

.login-actions {
  display: grid;
  gap: 12px;
}

.email-login {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(133, 77, 185, 0.12);
}

.primary-button,
.ghost-button,
.email-login button,
.icon-button {
  min-height: 42px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
}

.primary-button,
.email-login button {
  color: #fff;
  background: var(--primary);
  padding: 0 18px;
}

.primary-button:hover,
.email-login button:hover {
  background: var(--primary-dark);
}

.ghost-button,
.icon-button {
  color: var(--text);
  background: #fff;
  border-color: var(--line);
  padding: 0 14px;
}

.ghost-button:hover,
.icon-button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.login-status {
  min-height: 22px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 14px;
}

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

.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: #fff;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  padding: 10px 8px 22px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, #854db9, #a9a5ea);
  font-weight: 900;
}

.admin-brand strong,
.admin-brand small {
  display: block;
}

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

.admin-nav {
  display: grid;
  gap: 4px;
}

.admin-nav button {
  width: 100%;
  min-height: 42px;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  text-align: left;
  font-weight: 700;
}

.admin-nav button:hover,
.admin-nav button.is-active {
  color: var(--primary);
  background: #f2eff8;
}

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

.admin-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 20px;
}

.admin-user {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-user span,
.status-pill,
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  background: #f0ebf6;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
}

.admin-user strong {
  color: var(--muted);
  font-size: 14px;
}

.admin-notice {
  margin-bottom: 16px;
  padding: 14px 16px;
  background: #fff8e8;
  border: 1px solid #ead8a8;
  color: #6f5514;
}

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

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

.metric-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(41, 28, 58, 0.05);
}

.metric-card {
  padding: 18px;
}

.metric-card span,
.panel-header p,
.table-meta {
  color: var(--muted);
  font-size: 13px;
}

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

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

.panel-header h2 {
  margin: 0;
  font-size: 20px;
}

.panel-header p {
  margin: 4px 0 0;
}

.table-wrap {
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

td {
  font-size: 14px;
  line-height: 1.5;
}

tbody tr:hover {
  background: #fcfaff;
}

.doc-id {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
}

.status-pill[data-tone="active"],
.status-pill[data-tone="published"],
.status-pill[data-tone="paid"],
.status-pill[data-tone="open"] {
  background: #e8f8ea;
  color: #277d35;
}

.status-pill[data-tone="hidden"],
.status-pill[data-tone="pending"],
.status-pill[data-tone="draft"] {
  background: #f7eefc;
  color: var(--primary-dark);
}

.status-pill[data-tone="canceled"],
.status-pill[data-tone="archived"],
.status-pill[data-tone="failed"] {
  background: #feecef;
  color: #b4303d;
}

.cell-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  background: #f7f3fb;
  color: var(--muted);
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.row-actions button {
  min-height: 32px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 0 10px;
  font-weight: 800;
}

.row-actions button:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.empty-state,
.error-state {
  padding: 32px 20px;
  color: var(--muted);
  text-align: center;
}

.error-state {
  color: #a13843;
}

.admin-dialog {
  width: min(720px, calc(100vw - 28px));
  border: 0;
  padding: 0;
  background: transparent;
}

.admin-dialog::backdrop {
  background: rgba(18, 15, 22, 0.42);
}

.dialog-card {
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.dialog-card header,
.dialog-card footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.dialog-card footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.dialog-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}

.dialog-fields {
  display: grid;
  gap: 14px;
  max-height: min(62vh, 620px);
  overflow-y: auto;
  padding: 20px;
}

.field-label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.field-label small {
  color: var(--faint);
  font-weight: 600;
}

.ledger-panel {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding: 18px 20px;
}

.ledger-panel h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.admin-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 14px);
  min-width: 240px;
  max-width: min(480px, calc(100vw - 28px));
  padding: 14px 18px;
  background: #18131f;
  color: #fff;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 20;
}

.admin-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

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

  .admin-sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .admin-nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .admin-main {
    padding: 20px;
  }

  .admin-topbar {
    display: grid;
  }

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

@media (max-width: 640px) {
  .admin-login {
    padding: 16px;
  }

  .admin-login-card {
    padding: 26px 20px;
  }

  .email-login {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .admin-user {
    justify-content: flex-start;
  }
}
