:root {
  --bg: #eef2f7;
  --bg-panel: #f8fafc;
  --surface: #ffffff;
  --surface-strong: #f8fafc;
  --line: #d9e2ec;
  --text: #102136;
  --muted: #5f6f82;
  --brand: #175cd3;
  --brand-strong: #1849a9;
  --brand-soft: #e0eaff;
  --success-bg: #eef8f0;
  --success-line: #b6d9bd;
  --success-text: #264a2f;
  --danger-bg: #fff1ef;
  --danger-line: #f2beb8;
  --danger-text: #7e3027;
  --shadow: 0 12px 30px rgba(16, 33, 54, 0.08);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(180deg, #f7f9fc 0%, #eef2f7 100%);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Avenir Next", Montserrat, "Segoe UI", sans-serif;
}

a {
  color: inherit;
}

a:hover {
  color: var(--brand-strong);
}

.page-shell {
  width: min(1400px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 14px 0 10px;
  font-size: 1.8rem;
  line-height: 1.1;
}

.auth-form {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.auth-alert {
  margin-top: 18px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 20px;
  padding: 8px 2px;
}

.dashboard-header h1 {
  margin: 14px 0 6px;
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.logout-form {
  margin: 0;
}

.dashboard-subtitle,
.panel-subtitle,
.hint,
.meta-list,
.detail-label {
  color: var(--muted);
}

.dashboard-subtitle {
  margin: 0;
  max-width: 64ch;
  line-height: 1.65;
}

.dashboard-header-meta {
  min-width: 220px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.dashboard-meta-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.dashboard-header-meta strong {
  display: block;
  font-size: 1.05rem;
}

.dashboard-action {
  width: 100%;
  margin-top: 14px;
}

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

.dashboard-stats {
  margin-bottom: 20px;
}

.stat-card,
.side-card,
.panel,
.result-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 18px 20px;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  color: var(--brand-strong);
  font-size: 1.05rem;
}

.side-card {
  padding: 24px;
}

.side-card h2,
.panel h2,
.result-card h2 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.meta-list {
  margin: 0;
  padding-left: 18px;
  line-height: 1.8;
}

.panel {
  padding: 28px;
}

.toolbar-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.toolbar-copy h2 {
  margin: 0 0 6px;
  font-size: 1.2rem;
}

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

.mini-code {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-panel);
  color: var(--muted);
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.8rem;
}

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

.panel-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.panel-subtitle {
  margin: 6px 0 0;
  line-height: 1.7;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-size: 0.82rem;
  font-weight: 700;
}

.field-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-grid .field:first-child,
.field-grid .field--full {
  grid-column: 1 / -1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field label {
  font-weight: 700;
  font-size: 0.95rem;
}

.field input,
.field select {
  width: 100%;
  appearance: none;
  border: 1px solid rgba(111, 67, 24, 0.16);
  background: var(--surface-strong);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 16px;
  font: inherit;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: rgba(138, 90, 43, 0.65);
  box-shadow: 0 0 0 4px rgba(138, 90, 43, 0.12);
}

.hint {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.55;
}

.actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 24px;
}

.button,
.link-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  text-decoration: none;
  font-weight: 700;
}

.button {
  border: 0;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: #fff9f3;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(111, 67, 24, 0.18);
}

.button:hover {
  transform: translateY(-1px);
}

.link-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
}

.callout {
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid transparent;
  line-height: 1.7;
}

.callout strong {
  display: block;
  margin-bottom: 4px;
}

.callout.error {
  background: var(--danger-bg);
  border-color: var(--danger-line);
  color: var(--danger-text);
}

.callout.success {
  background: var(--success-bg);
  border-color: var(--success-line);
  color: var(--success-text);
}

.detail-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.84rem;
}

.history-panel {
  margin-top: 0;
}

.history-app {
  display: grid;
  gap: 20px;
}

.history-filter-row {
  display: flex;
  justify-content: flex-start;
}

.history-filter-field {
  width: min(320px, 100%);
}

.history-status {
  min-height: 24px;
  color: var(--muted);
  font-size: 0.95rem;
}

.history-status.is-error {
  color: var(--danger-text);
}

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

.empty-state {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.7);
  padding: 16px 18px;
}

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

.history-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 960px;
}

.history-table th,
.history-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.93rem;
}

.history-table th {
  background: var(--bg-panel);
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.history-table tbody tr:hover {
  background: #f8fbff;
}

.history-table tbody tr:last-child td {
  border-bottom: 0;
}

.history-table a {
  color: var(--brand-strong);
  text-decoration: none;
}

.history-table a:hover {
  text-decoration: underline;
}

.cell-number {
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  white-space: nowrap;
}

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

.icon-copy-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  cursor: pointer;
  transition: all 160ms ease;
}

.icon-copy-button:hover {
  color: var(--brand-strong);
  border-color: #b9cced;
  background: #eef4ff;
}

.cell-title {
  font-weight: 700;
  line-height: 1.4;
}

.cell-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

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

.table-action-button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 0.82rem;
}

.table-action-button.is-danger {
  color: #a63232;
  border-color: #efc6c6;
  background: #fff5f5;
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

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

.pagination-button[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.pagination-info {
  color: var(--muted);
  text-align: center;
}

.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 33, 54, 0.48);
  backdrop-filter: blur(4px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-dialog {
  width: min(720px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 30px 80px rgba(16, 33, 54, 0.22);
  padding: 24px;
}

.modal-dialog-compact {
  width: min(560px, 100%);
}

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

.modal-header h2 {
  margin: 12px 0 0;
  font-size: 1.4rem;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
}

.modal-form {
  display: grid;
  gap: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.toast {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 60;
  min-width: 320px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 14px 16px;
  border-radius: 14px;
  background: #103a7a;
  color: #fff;
  box-shadow: 0 16px 36px rgba(16, 33, 54, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.toast.is-error {
  background: #a63232;
}

@media (max-width: 920px) {
  .stat-row {
    grid-template-columns: 1fr;
  }

  .panel,
  .side-card,
  .toolbar-panel {
    padding: 24px;
  }

  .dashboard-header {
    flex-direction: column;
  }

  .dashboard-header-meta {
    width: 100%;
  }

  .toolbar-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 20px, 1120px);
    padding: 18px 0 40px;
  }

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

  .panel-header,
  .actions,
  .modal-actions {
    flex-direction: column;
    align-items: stretch;
  }

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

  .pagination-info {
    order: -1;
  }

  .toast {
    left: 16px;
    right: 16px;
    top: 16px;
    min-width: 0;
  }
}
