:root {
  --bg: #f6f4ef;
  --ink: #141313;
  --muted: #6b625a;
  --accent: #ff6b35;
  --accent-2: #1b9aaa;
  --card: #fff7e6;
  --card-2: #fef1d1;
  --line: #e3d6bf;
  --shadow: 0 10px 30px rgba(0, 0, 0, .12);
  --success-bg: #dcfce7;
  --success-text: #166534;
  --warn-bg: #fff3c4;
  --warn-text: #9a6700;
  --error-bg: #fee2e2;
  --error-text: #b42318;
  --info-bg: #e0f2fe;
  --info-text: #0c4a6e;
  --page-max: 1440px;
  --page-pad: clamp(14px, 3vw, 32px);
  --section-gap: clamp(16px, 2.4vw, 24px);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #ffe6b3, transparent 60%),
    radial-gradient(1000px 600px at 100% 0%, #c8fff4, transparent 55%),
    var(--bg);
  font-family: "Space Grotesk", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow-x: hidden;
}

.page {
  width: min(100%, var(--page-max));
  min-height: calc(100vh - clamp(48px, 8vw, 96px));
  margin: clamp(18px, 3.5vw, 36px) auto clamp(48px, 7vw, 80px);
  padding: 0 var(--page-pad);
}

header {
  display: grid;
  gap: 14px clamp(18px, 3vw, 28px);
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  margin-bottom: var(--section-gap);
}

header > div:first-child {
  min-width: 0;
}

.title {
  font-size: clamp(26px, 3vw, 36px);
  line-height: 1.15;
  letter-spacing: 0.5px;
  margin: 0;
}

.subtitle {
  color: var(--muted);
  margin: 6px 0 0;
  font-size: clamp(13px, 1.6vw, 14px);
  line-height: 1.6;
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  width: max-content;
  max-width: min(760px, 54vw);
  min-width: 0;
}

.actions > * {
  flex: 0 0 auto;
}

button {
  appearance: none;
  min-height: 40px;
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  color: var(--ink);
  background: linear-gradient(135deg, #ffd166, #ff9f1c);
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, opacity 0.15s ease;
}

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

button.secondary {
  background: linear-gradient(135deg, #b3f2ee, #58c8c4);
}

button.ghost {
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: none;
}

button.active {
  border: 1px solid rgba(20, 19, 19, 0.12);
  box-shadow: inset 0 0 0 2px rgba(20, 19, 19, 0.06), var(--shadow);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.hidden {
  display: none !important;
}

.pill {
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
  white-space: nowrap;
}

.view-stack {
  display: grid;
  gap: var(--section-gap);
  min-width: 0;
}

.view {
  display: grid;
  gap: var(--section-gap);
  min-width: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr));
  gap: clamp(12px, 1.8vw, 16px);
  margin-bottom: var(--section-gap);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: clamp(14px, 2vw, 18px);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.card:nth-child(2) {
  background: var(--card-2);
}

.card h3 {
  margin: 0 0 10px;
  font-size: clamp(12px, 1.4vw, 14px);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.card .value {
  font-size: clamp(24px, 3vw, 30px);
  line-height: 1.1;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: clamp(16px, 2.4vw, 24px);
  box-shadow: var(--shadow);
  display: grid;
  gap: clamp(14px, 1.8vw, 18px);
  min-width: 0;
}

.panel h2,
.panel h3,
.panel h4,
.panel p {
  margin: 0;
}

.panel-note {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 18px;
  flex-wrap: wrap;
  min-width: 0;
}

.section-head > div:first-child {
  flex: 1 1 280px;
  min-width: 0;
}

.section-head h2,
.section-head h3 {
  font-size: clamp(20px, 2.3vw, 22px);
  line-height: 1.25;
}

.section-head h3 {
  font-size: clamp(17px, 2vw, 18px);
}

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

.table-wrap {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow-x: auto;
  overflow-y: hidden;
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
}

.table-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fffdf7;
  flex-wrap: wrap;
  min-width: 0;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}

.toolbar-left {
  flex: 1 1 220px;
}

.toolbar-right {
  flex: 2 1 380px;
  justify-content: flex-end;
}

.toolbar-left select,
.toolbar-right select,
.toolbar-right input[type="text"] {
  width: auto;
}

.toolbar-right input[type="text"] {
  flex: 1 1 180px;
  min-width: min(220px, 100%);
}

select,
input[type="text"],
input[type="number"],
textarea {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}

textarea {
  min-height: clamp(180px, 34vh, 280px);
  resize: vertical;
  line-height: 1.6;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 10px 14px;
  border-bottom: 1px solid #f0e7d7;
  text-align: left;
  white-space: nowrap;
}

th {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  background: #fffdf7;
}

tr:hover td {
  background: #fff6df;
}

.status {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  display: inline-block;
}

.status.active {
  background: #dcfce7;
  color: #166534;
}

.status.cooldown {
  background: #ffe4e6;
  color: #9f1239;
}

.status.disabled {
  background: #e2e8f0;
  color: #475569;
}

.status.refresh-disabled {
  margin-left: 6px;
  background: var(--warn-bg);
  color: var(--warn-text);
}

.stats-action-state {
  margin-top: -8px;
}

.recent-events-panel {
  gap: 14px;
}

#eventsView .recent-events-panel {
  align-self: start;
}

#eventsView .event-list {
  gap: 14px;
}

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

.event-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 14px 16px;
  border: 1px solid #f0e7d7;
  border-radius: 16px;
  background: #fffdf7;
}

.event-item-main {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.event-item-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.event-action {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
}

.event-action.remove {
  background: var(--error-bg);
  color: var(--error-text);
}

.event-action.disable {
  background: #e2e8f0;
  color: #475569;
}

.event-action.refresh-disable {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.event-email {
  font-size: 15px;
  overflow-wrap: anywhere;
}

.event-reason,
.event-meta {
  color: var(--muted);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.event-reason {
  color: var(--ink);
}

.event-time {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.account-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.account-email {
  font-weight: 600;
  min-width: 0;
  overflow-wrap: anywhere;
}

.row-action {
  padding: 6px 12px;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.row-action.ghost {
  background: #fffaf0;
}

.row-action.danger {
  color: #9f1d1d;
  background: #fff1f1;
  border-color: rgba(220, 38, 38, 0.25);
}

.row-action.danger:hover:not(:disabled) {
  background: #ffe3e3;
}

.enabled-toggle-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  user-select: none;
}

.enabled-toggle {
  width: 14px;
  height: 14px;
  accent-color: var(--accent-2);
}

.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
}

.pagination button {
  padding: 6px 12px;
  font-size: 12px;
}

.footer {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.placeholder {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: clamp(14px, 2vw, 18px);
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  margin-bottom: var(--section-gap);
}

.placeholder-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr));
  gap: 12px;
}

.skeleton {
  height: 16px;
  border-radius: 999px;
  background: linear-gradient(90deg, #f3ead7 25%, #fff7e6 50%, #f3ead7 75%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
}

.skeleton.big {
  height: 28px;
  border-radius: 12px;
}

.hero-actions,
.import-actions,
.file-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}

.hero-actions {
  justify-content: flex-end;
}

.dropzone {
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: clamp(14px, 2vw, 18px);
  background: #fffdf7;
  display: grid;
  gap: 8px;
  min-width: 0;
}

.dropzone strong {
  font-size: 16px;
}

.dropzone span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: clamp(14px, 2vw, 16px);
}

.form-grid label,
.qmsg-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.check-row {
  grid-column: 1 / -1;
  display: flex !important;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdf7;
  color: var(--ink) !important;
  font-size: 14px !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}

.check-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-2);
}

.compact-head {
  align-items: flex-end;
}

.compact-textarea {
  min-height: clamp(110px, 22vh, 140px);
}

.qmsg-form code {
  background: #fff6df;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 4px;
}

.alert-stack,
.result-stack,
.error-stack {
  display: grid;
  gap: 12px;
}

.alert {
  border-radius: 16px;
  border: 1px solid transparent;
  padding: 14px 16px;
  display: grid;
  gap: 8px;
  line-height: 1.7;
  font-size: 14px;
}

.alert strong {
  font-size: 15px;
}

.alert.info {
  background: var(--info-bg);
  color: var(--info-text);
  border-color: rgba(12, 74, 110, 0.15);
}

.alert.success {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: rgba(22, 101, 52, 0.15);
}

.alert.warning {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: rgba(154, 103, 0, 0.15);
}

.alert.error {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: rgba(180, 35, 24, 0.15);
}

.alert-list,
.error-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr));
  gap: clamp(12px, 1.8vw, 16px);
}

.result-card {
  background: linear-gradient(180deg, #fff8ea, #fffdf7);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  display: grid;
  gap: 8px;
}

.result-card span {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.result-card strong {
  font-size: 28px;
  line-height: 1;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 247, 230, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.login-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 600px at 10% -10%, #ffe6b3, transparent 60%),
    radial-gradient(1000px 600px at 100% 0%, #c8fff4, transparent 55%),
    var(--bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: clamp(12px, 3vw, 20px);
  overflow-y: auto;
}

.login-overlay.active {
  display: flex;
}

.login-card {
  width: min(520px, 100%);
  max-height: calc(100vh - 2 * clamp(12px, 3vw, 20px));
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: clamp(18px, 3vw, 24px);
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}

.login-card h2 {
  margin: 0;
  font-size: 22px;
}

.login-card label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  background: #fff;
}

.login-card input.invalid {
  border-color: #d92d20;
  box-shadow: 0 0 0 3px rgba(217, 45, 32, 0.12);
}

.login-error {
  min-height: 20px;
  margin: -4px 0 0;
  color: #b42318;
  font-size: 13px;
}

.login-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.loading-overlay.active {
  display: flex;
}

.spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 5px solid #ffd8a8;
  border-top-color: #ff6b35;
  animation: spin 0.9s linear infinite;
  box-shadow: var(--shadow);
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.login-url-block {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-url-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}

.login-url-row input {
  flex: 1 1 320px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
  font-size: 12px;
}

.login-url-row button {
  flex: 0 0 auto;
}

.login-state-hint {
  margin: 0;
  font-size: 12px;
}

#loginCallbackInput {
  width: 100%;
  min-height: 90px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
  font-size: 12px;
  resize: vertical;
}

@media (max-width: 1180px) {
  header {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: flex-start;
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 980px) {
  .table-toolbar {
    align-items: stretch;
  }

  .toolbar-left,
  .toolbar-right {
    flex: 1 1 100%;
    justify-content: flex-start;
  }

  .toolbar-right input[type="text"] {
    min-width: min(260px, 100%);
  }
}

@media (max-width: 760px) {
  .actions {
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 8px;
    margin-inline: calc(var(--page-pad) * -1);
    padding: 2px var(--page-pad) 8px;
    overflow-x: auto;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .actions button,
  .actions .pill {
    min-width: max-content;
  }

  .section-head,
  .compact-head {
    align-items: stretch;
  }

  .hero-actions,
  .import-actions,
  .file-meta {
    width: 100%;
    justify-content: flex-start;
  }

  .table-wrap {
    overflow: visible;
    background: transparent;
    border: 0;
    box-shadow: none;
  }

  .table-toolbar {
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
    background: transparent;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  tr:hover td {
    background: transparent;
  }

  td {
    display: grid;
    grid-template-columns: minmax(88px, 34%) minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    min-height: 42px;
    padding: 10px 14px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.6;
    text-transform: uppercase;
    letter-spacing: 0.8px;
  }

  td:first-child {
    grid-template-columns: 1fr;
    gap: 8px;
    background: #fffdf7;
  }

  td:first-child::before {
    content: none;
  }

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

  .account-cell {
    align-items: flex-start;
    gap: 8px;
  }

  .account-email {
    flex: 1 1 100%;
    font-size: 15px;
  }
}

@media (max-width: 640px) {
  .page {
    min-height: calc(100vh - 48px);
  }

  .panel,
  .card,
  .placeholder {
    border-radius: 16px;
  }

  .dropzone,
  .alert,
  .result-card {
    border-radius: 14px;
  }

  .hero-actions button,
  .import-actions button,
  .login-actions button,
  .file-meta button,
  .login-url-row button {
    flex: 1 1 140px;
  }

  .login-url-row input {
    flex-basis: 100%;
  }

  .login-overlay {
    align-items: flex-start;
  }

  .login-card {
    width: 100%;
    max-height: none;
  }

  .event-item {
    grid-template-columns: 1fr;
  }

  .event-time {
    white-space: normal;
  }

  .row-action {
    padding: 5px 10px;
  }
}

@media (max-width: 480px) {
  :root {
    --page-pad: 12px;
    --section-gap: 14px;
  }

  .page {
    margin-top: 14px;
    margin-bottom: 40px;
  }

  .actions button {
    min-height: 38px;
    padding: 9px 14px;
    font-size: 13px;
  }

  .pill {
    padding: 6px 9px;
  }

  .panel,
  .login-card {
    padding: 14px;
  }

  .table-toolbar,
  .toolbar-left,
  .toolbar-right,
  .pagination,
  .hero-actions,
  .import-actions,
  .file-meta,
  .login-actions,
  .login-url-row {
    gap: 8px;
  }

  .toolbar-left > *,
  .toolbar-right > *,
  .pagination {
    flex: 1 1 auto;
  }

  .toolbar-left select,
  .toolbar-right select,
  .toolbar-right input[type="text"] {
    width: 100%;
  }

  .pagination button {
    flex: 1 1 0;
  }

  textarea {
    min-height: 160px;
  }

  .compact-textarea,
  #loginCallbackInput {
    min-height: 96px;
  }

  td {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .row-action,
  .enabled-toggle-wrap {
    flex: 1 1 auto;
    justify-content: center;
  }
}
