:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #172033;
  --muted: #5d6878;
  --border: #d8dde6;
  --accent: #1459d9;
  --accent-dark: #0d43a8;
  --error-bg: #fff0f0;
  --error-text: #9f1f1f;
  --success-bg: #ecf8f0;
  --success-text: #176734;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: var(--accent);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 40px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

nav {
  display: flex;
  align-items: center;
  gap: 14px;
}

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

.logout {
  text-decoration: none;
  font-weight: 700;
}

.page {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 40px) 48px;
}

h1,
h2 {
  margin: 0 0 10px;
  line-height: 1.15;
}

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

.auth-panel,
.upload-form,
.preview-panel,
.history {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: clamp(18px, 3vw, 28px);
}

.auth-panel {
  max-width: 420px;
  margin: 48px auto;
}

.dashboard {
  display: grid;
  gap: 22px;
}

.intro {
  display: grid;
  gap: 4px;
}

.form-stack,
.upload-form {
  display: grid;
  gap: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: #2d3748;
  font-weight: 700;
}

input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 11px 12px;
  color: var(--text);
  font: inherit;
  background: #fff;
}

input[type="color"] {
  min-height: 46px;
  padding: 5px;
}

input:focus {
  outline: 3px solid rgba(20, 89, 217, 0.18);
  border-color: var(--accent);
}

.checkbox-field {
  align-content: end;
  grid-template-columns: 18px 1fr;
  gap: 10px;
  min-height: 72px;
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  margin-top: 3px;
}

.info-button {
  display: inline-flex;
  width: 20px;
  height: 20px;
  margin-left: 6px;
  padding: 0;
  border-radius: 50%;
  background: #e9eef8;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 900;
}

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

.help {
  border-left: 4px solid var(--accent);
  background: #eef4ff;
  border-radius: 6px;
  padding: 12px 14px;
}

.help p {
  margin: 4px 0;
}

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 11px 16px;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.tour-button {
  width: fit-content;
  margin-top: 12px;
}

button:hover,
.button-link:hover {
  background: var(--accent-dark);
}

.button-link.secondary {
  background: #e9eef8;
  color: var(--accent);
}

.button-link.secondary:hover {
  background: #d8e2f5;
}

.button-link.danger {
  background: #fff0f0;
  color: var(--error-text);
}

.button-link.danger:hover {
  background: #f8d8d8;
}

.button-link.disabled,
.button-link.disabled:hover {
  background: #e2e6ee;
  color: #6a7280;
  cursor: not-allowed;
  pointer-events: none;
}

button[disabled] {
  cursor: wait;
  opacity: 0.72;
}

.alert {
  border-radius: 8px;
  padding: 13px 15px;
  font-weight: 700;
}

.alert a {
  margin-left: 12px;
}

.alert.error {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid #f0b8b8;
}

.alert.success {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid #b8e3c4;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-head.compact {
  align-items: flex-start;
  margin-bottom: 12px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.page-rules {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

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

.page-rule {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #fbfcfe;
}

.pdf-preview {
  width: 100%;
  height: min(78vh, 780px);
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f0f2f6;
}

.preview-note {
  margin-top: 10px;
}

.pick-hint {
  margin-top: 6px;
}

.pick-hint kbd {
  font-family: inherit;
  font-size: 0.85em;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #f0f2f6;
}

.page-rule.picked-flash {
  border-color: #2f7d3a;
  border-style: solid;
  background: #f1faf2;
  transition: background 0.4s ease, border-color 0.4s ease;
}

.color-picker-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.55);
}

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

.color-picker-dialog {
  background: #fff;
  border-radius: 10px;
  width: min(960px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
}

.cp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cp-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cp-swatch {
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: transparent;
  display: inline-block;
}

.cp-canvas-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f0f2f6;
}

.cp-canvas-wrap canvas {
  display: block;
  max-width: 100%;
  height: auto;
  cursor: crosshair;
}

.confirm-form {
  margin: 0;
  display: inline-flex;
}

.cp-jump {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9em;
}

.cp-jump input {
  width: 72px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.45);
}

.loading-overlay[hidden] {
  display: none;
}

body.processing,
body.processing * {
  cursor: progress !important;
}

.loader {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: inline-block;
  position: relative;
  border-top: 4px solid #fff;
  border-right: 4px solid transparent;
  box-sizing: border-box;
  animation: rotation 1s linear infinite;
}

.loader::after {
  content: '';
  box-sizing: border-box;
  position: absolute;
  left: 0;
  top: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border-left: 4px solid #ff3d00;
  border-bottom: 4px solid transparent;
  animation: rotation 0.5s linear infinite reverse;
}

@keyframes rotation {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.reuse-banner {
  background: #f7fbff;
  border: 1px solid #c9daf8;
  border-radius: 8px;
  color: #26415f;
  padding: 12px 14px;
}

.reuse-banner a {
  margin-left: 8px;
  font-weight: 800;
}

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

.countdown-ring {
  --countdown-percent: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 900;
  background:
    radial-gradient(circle closest-side, #fff 69%, transparent 70%),
    conic-gradient(var(--accent) var(--countdown-percent), #d8dde6 0);
}

.expired-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 999px;
  padding: 4px 10px;
  background: #f1f3f7;
  color: #6a7280;
  font-weight: 800;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 14px;
}

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

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f0f2f6;
  color: #2d3748;
  font-size: 0.92rem;
}

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

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

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

  .action-row {
    flex-direction: column;
  }

  .page-rule {
    grid-template-columns: 1fr;
  }

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

  .pdf-preview {
    min-height: 360px;
    height: 70vh;
  }

  button,
  .button-link {
    width: 100%;
  }
}
