:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --surface-strong: #eaf2ff;
  --text: #101827;
  --muted: #667085;
  --border: #d9e2ef;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eaf2ff;
  --accent-glow: rgba(37, 99, 235, 0.22);
  --gold: #b7791f;
  --danger: #b42318;
  --success: #087443;
  --warning: #c2410c;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #ffffff 0%, #f6f8fb 46%, #eef4ff 100%),
    repeating-linear-gradient(90deg, rgba(37, 99, 235, 0.035) 0 1px, transparent 1px 78px);
  color: var(--text);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Segoe UI", system-ui, sans-serif;
}

body.locked .app {
  display: none;
}

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

body.locked .login-screen {
  display: grid;
}

.login-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 430px);
  gap: 28px;
  width: min(1120px, 100%);
  align-items: stretch;
}

.login-hero {
  display: grid;
  align-content: center;
  gap: 22px;
  min-height: 620px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(239, 246, 255, 0.95)),
    repeating-linear-gradient(0deg, rgba(37, 99, 235, 0.04) 0 1px, transparent 1px 40px);
  box-shadow: var(--shadow);
  padding: 36px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #1e293b;
  font-size: 14px;
  font-weight: 850;
}

.brand-mark {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.24);
}

.login-hero h1 {
  max-width: 620px;
  font-size: clamp(34px, 4vw, 54px);
  line-height: 1.08;
  letter-spacing: 0;
}

.login-hero p {
  max-width: 580px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.75;
}

.login-preview {
  border: 1px solid #cbd7e8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 18px 46px rgba(15, 23, 42, 0.09);
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  gap: 7px;
  padding: 12px 14px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}

.preview-toolbar span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #cbd5e1;
}

.preview-grid {
  display: grid;
  grid-template-columns: 0.85fr 1.15fr;
  gap: 14px;
  padding: 16px;
}

.preview-settings,
.preview-result {
  display: grid;
  gap: 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #ffffff;
  padding: 14px;
}

.preview-settings span,
.preview-result span {
  border-radius: 6px;
  background: #f1f5f9;
  color: #475467;
  padding: 9px 10px;
  font-size: 12px;
  font-weight: 750;
}

.mock-image {
  min-height: 150px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.18), transparent 48%),
    linear-gradient(160deg, #dbeafe, #ffffff 46%, #bbf7d0);
}

.login-card {
  display: grid;
  gap: 14px;
  align-content: center;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-card p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.login-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7f9fc;
}

.login-tabs button {
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 750;
}

.login-tabs button.active {
  background: #ffffff;
  color: var(--accent);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

#adminEntryTab.active {
  color: #c2410c;
}

.auth-form {
  display: grid;
  gap: 10px;
}

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

.app {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}

.app-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
}

body.admin-mode .app-body {
  grid-template-columns: 168px minmax(0, 1fr);
}

.app-content {
  min-width: 0;
}

.admin-sidebar {
  display: none;
  position: sticky;
  top: 18px;
  gap: 10px;
  align-self: start;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.07);
  padding: 10px;
}

body.admin-mode .admin-sidebar {
  display: flex;
  flex-direction: column;
}

.admin-sidebar button {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
}

.admin-sidebar button:hover,
.admin-sidebar button.active {
  background: #eff6ff;
}

.admin-sidebar button.active {
  color: var(--accent);
  border-color: #bfdbfe;
}

.admin-menu {
  display: grid;
  gap: 8px;
}

.admin-subnav {
  display: grid;
  gap: 7px;
  padding-left: 10px;
}

.admin-subnav button {
  position: relative;
  padding: 9px 10px;
  font-size: 12px;
  color: #526177;
  background: #fbfdff;
}

.admin-subnav button::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 50%;
  width: 7px;
  height: 1px;
  background: #cdd8e7;
}

.admin-subnav button.active {
  color: var(--accent);
  background: #eff6ff;
  border-color: #bfdbfe;
}

.admin-sidebar .status {
  width: 100%;
  min-width: 0;
  border-radius: 7px;
  box-shadow: none;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.1;
  font-weight: 820;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
  font-weight: 760;
}

.topbar p,
.result-head p,
.meta {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.status {
  min-width: 88px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(22, 32, 51, 0.08);
}

.status.running {
  color: #7a4d05;
  background: #fff7df;
  border-color: #edd490;
}

.status.ok {
  color: var(--success);
  background: #e8f7ef;
  border-color: #b8e4ca;
}

.status.error {
  color: var(--danger);
  background: #fff0ee;
  border-color: #efc5bf;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 410px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.admin-panel {
  margin-bottom: 20px;
  border: 1px solid rgba(213, 223, 235, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  padding: 18px;
}

.admin-login {
  display: grid;
  gap: 14px;
}

.admin-login h2,
.admin-head h2,
.server-log-head h2 {
  margin-bottom: 6px;
}

.admin-login p,
.admin-head p,
.server-log-head span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.admin-login-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr) auto;
  gap: 10px;
}

.admin-login-row button,
.admin-actions button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.admin-login-row button:hover,
.admin-actions button:hover {
  filter: brightness(0.97);
}

.admin-dashboard {
  display: grid;
  gap: 16px;
}

.admin-head,
.server-log-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

#clearServerLogs {
  background: #fff0ee;
  color: var(--danger);
}

#adminLogoutBtn {
  background: var(--surface-strong);
  color: #526177;
}

.user-admin {
  scroll-margin-top: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdff;
  overflow: hidden;
}

.user-admin-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.user-admin-head h2 {
  margin-bottom: 6px;
}

.user-admin-head p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.user-admin-head button,
.server-log-head button,
.user-password button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  padding: 10px 13px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.user-list {
  display: grid;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 112px 104px minmax(300px, 420px) minmax(230px, 300px);
  gap: 12px;
  align-items: center;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
}

.user-row:last-child {
  border-bottom: 0;
}

.user-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.user-title strong {
  color: #172033;
  font-size: 15px;
}

.user-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.user-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #35445b;
  font-size: 13px;
  font-weight: 750;
}

.user-toggle input {
  width: auto;
}

.user-password {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.user-password input {
  min-width: 0;
}

.user-quota {
  display: grid;
  gap: 7px;
}

.user-quota-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.user-quota-controls {
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto auto;
  gap: 8px;
}

.user-quota-controls input {
  min-width: 0;
}

.user-quota-controls button {
  border: 0;
  border-radius: 7px;
  background: var(--surface-strong);
  color: var(--accent);
  cursor: pointer;
  padding: 10px 11px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 14px;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(100px, 1fr));
  gap: 10px;
}

.server-log {
  scroll-margin-top: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdff;
  overflow: hidden;
}

.server-log-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.server-log-head > div {
  min-width: 0;
}

.server-log-filter {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}

.server-log-filter-title {
  color: #64748b;
  font-size: 12px;
  font-weight: 800;
}

.server-log-customers {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.server-log-customers button,
.server-log-pager button {
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #ffffff;
  color: #334155;
  cursor: pointer;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 800;
}

.server-log-customers button:hover,
.server-log-pager button:hover:not(:disabled) {
  border-color: #93c5fd;
  background: #eff6ff;
  color: var(--accent);
}

.server-log-customers button.active {
  border-color: #93c5fd;
  background: var(--accent-soft);
  color: var(--accent);
}

.server-log-empty-filter {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
}

.server-log-list {
  display: grid;
}

.server-log-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 14px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
}

.server-log-item:last-child {
  border-bottom: 0;
}

.server-log-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.server-log-title strong {
  color: #172033;
  font-size: 14px;
}

.server-log-title > span:last-child,
.server-log-detail,
.server-log-main p,
.server-log-side {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.server-log-detail {
  margin-top: 6px;
}

.server-log-main p {
  margin-top: 6px;
  max-height: 58px;
  overflow: hidden;
}

.server-error {
  width: fit-content;
  max-width: 100%;
  margin-top: 8px;
  border-radius: 6px;
  background: #fff0ee;
  color: var(--danger);
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.server-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.server-images a,
.server-images button {
  display: inline-grid;
  min-width: 76px;
  color: var(--accent);
  border: 1px solid #bfdbfe;
  border-radius: 7px;
  background: var(--accent-soft);
  cursor: pointer;
  padding: 7px 9px;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.server-images a:hover,
.server-images button:hover {
  background: #dbeafe;
}

.server-log-side {
  display: grid;
  align-content: start;
  justify-items: end;
  gap: 5px;
  min-width: 0;
  text-align: right;
  overflow-wrap: anywhere;
}

.server-log-side strong {
  color: #172033;
  font-size: 13px;
  word-break: break-all;
}

.server-log-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: #ffffff;
}

.server-log-pager span {
  min-width: 128px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.server-log-pager button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.panel,
.results {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(213, 223, 235, 0.92);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls {
  padding: 18px;
  position: sticky;
  top: 18px;
}

.section-title {
  margin: 2px 0 12px;
  color: #1e293b;
  font-size: 15px;
  font-weight: 800;
}

.section-title:not(:first-child) {
  margin-top: 20px;
}

.key-card {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}

.key-card > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.key-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.key-card strong {
  color: #172033;
  font-size: 13px;
}

.key-card strong.configured {
  color: var(--success);
}

.key-card strong.missing {
  color: var(--danger);
}

.key-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.key-actions button {
  border: 0;
  border-radius: 7px;
  background: var(--surface-strong);
  color: #526177;
  cursor: pointer;
  padding: 9px 10px;
  font-size: 13px;
  font-weight: 800;
}

.key-actions button:first-child {
  background: var(--accent);
  color: #ffffff;
}

.key-actions button:hover {
  filter: brightness(0.97);
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

label {
  font-size: 12px;
  font-weight: 800;
  color: #35445b;
  letter-spacing: 0;
}

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

select {
  cursor: pointer;
}

textarea {
  resize: vertical;
  min-height: 190px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #f1f5f9;
  border: 1px solid #d9e2ef;
  border-radius: 8px;
  padding: 6px;
  gap: 8px;
}

.segmented button,
#downloadJson,
#downloadImage,
#clearHistory,
#clearImage,
#clearReferenceImage {
  border: 0;
  border-radius: 7px;
  color: #526177;
  background: transparent;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
}

.segmented button.active {
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.24);
}

.segmented button {
  min-height: 44px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.84);
  color: #475467;
  font-size: 14px;
}

.segmented button:not(.active):hover {
  border-color: #bfdbfe;
  color: var(--accent);
}

#downloadJson,
#downloadImage,
#clearHistory,
#clearImage,
#clearReferenceImage {
  background: #eef4ff;
  color: var(--accent);
}

#downloadJson:hover,
#downloadImage:hover,
#clearHistory:hover,
#clearImage:hover,
#clearReferenceImage:hover {
  background: #dbeafe;
}

#downloadJson:disabled,
#downloadImage:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  padding: 14px;
  font-weight: 820;
  box-shadow: 0 16px 30px rgba(37, 99, 235, 0.24);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  display: grid;
  gap: 4px;
  min-height: 64px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 11px 12px;
}

.stat-card.wide {
  grid-column: 1 / -1;
}

.stat-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.stat-card strong {
  color: #13213a;
  font-size: 16px;
  line-height: 1.25;
  word-break: break-word;
}

.quota-card {
  display: grid;
  gap: 4px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #eff6ff);
  padding: 12px;
}

.quota-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.quota-card strong {
  color: var(--accent);
  font-size: 18px;
  line-height: 1.25;
}

.primary:hover {
  background: var(--accent-dark);
}

.primary:disabled {
  opacity: 0.65;
  cursor: progress;
}

.preview {
  border: 1px dashed #93c5fd;
  border-radius: 8px;
  padding: 12px;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  display: grid;
  gap: 10px;
}

.reference-upload {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.preview-label {
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.4;
}

.preview img {
  display: block;
  width: 100%;
  max-height: none;
  object-fit: contain;
  border-radius: 6px;
  background: var(--surface-strong);
}

.reference-preview {
  border-style: solid;
  border-color: #93c5fd;
}

.hidden {
  display: none !important;
}

.results {
  min-height: calc(100vh - 104px);
  padding: 18px;
}

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

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 14px;
  min-height: 430px;
}

.result-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.empty {
  min-height: 430px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background:
    linear-gradient(180deg, rgba(251, 253, 255, 0.9), rgba(242, 247, 252, 0.9));
}

.image-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdff;
  overflow: hidden;
}

.image-frame {
  position: relative;
  display: grid;
  min-height: 280px;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(219, 234, 254, 0.92), rgba(248, 250, 252, 0.96)),
    repeating-linear-gradient(45deg, rgba(37, 99, 235, 0.05) 0 1px, transparent 1px 18px);
}

.image-card img {
  display: block;
  width: 100%;
  max-height: 760px;
  object-fit: contain;
}

.image-overlay-actions {
  position: absolute;
  left: 50%;
  top: 50%;
  display: flex;
  gap: 10px;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease;
}

.image-frame:hover .image-overlay-actions,
.image-frame:focus-within .image-overlay-actions {
  opacity: 1;
  pointer-events: auto;
}

.image-overlay-actions button,
.image-overlay-actions a {
  border: 0;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--accent);
  cursor: pointer;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.18);
  white-space: nowrap;
}

.image-overlay-actions button:hover,
.image-overlay-actions a:hover {
  background: var(--accent);
  color: #ffffff;
}

@media (hover: none) {
  .image-overlay-actions {
    opacity: 1;
    pointer-events: auto;
  }
}

.image-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-top: 1px solid var(--border);
}

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

.inline-actions button,
.inline-actions a {
  border: 0;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.inline-actions button:hover,
.inline-actions a:hover {
  background: #dbeafe;
}

.image-actions span {
  color: #526177;
  font-size: 13px;
}

.image-actions strong {
  color: #162033;
  margin-left: 6px;
}

.image-actions a {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.raw {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdff;
  overflow: hidden;
}

.history {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdff;
  overflow: hidden;
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.history-list {
  display: grid;
  gap: 0;
}

.history-empty {
  color: var(--muted);
  padding: 18px 14px;
  font-size: 14px;
}

.history-item {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 128px;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}

.history-item:last-child {
  border-bottom: 0;
}

.history-thumb {
  width: 76px;
  height: 58px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-strong);
  cursor: pointer;
  padding: 0;
}

.history-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-thumb:hover {
  border-color: var(--accent);
}

.empty-thumb {
  display: grid;
  place-items: center;
  color: var(--muted);
  cursor: default;
  font-size: 12px;
}

.history-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.history-title strong {
  overflow: hidden;
  color: #172033;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-main p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.history-status {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.history-status.ok {
  color: var(--success);
  background: #e8f7ef;
}

.history-status.error {
  color: var(--danger);
  background: #fff0ee;
}

.history-side {
  display: grid;
  justify-items: end;
  gap: 3px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
  overflow-wrap: anywhere;
}

.history-download {
  width: fit-content;
  border: 0;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.history-download:hover {
  background: #dbeafe;
}

.history-side strong {
  color: #172033;
  font-size: 14px;
}

.raw summary {
  cursor: pointer;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 800;
}

pre {
  margin: 0;
  max-height: 420px;
  overflow: auto;
  padding: 14px;
  border-top: 1px solid var(--border);
  color: #253247;
  background: #f8fbff;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
}

.preview-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
}

.preview-modal-panel {
  position: relative;
  display: grid;
  gap: 12px;
  width: min(1080px, 96vw);
  max-height: 94vh;
  border: 1px solid rgba(217, 226, 239, 0.95);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 30px 80px rgba(15, 23, 42, 0.32);
  padding: 14px;
}

.preview-modal-head,
.preview-modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.preview-modal-head button,
.preview-modal-actions a {
  border: 0;
  border-radius: 7px;
  background: var(--surface-strong);
  color: var(--accent);
  cursor: pointer;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.preview-modal-actions {
  justify-content: flex-end;
}

#previewImage {
  display: block;
  width: 100%;
  max-height: calc(94vh - 124px);
  object-fit: contain;
  border-radius: 6px;
  background: #f1f5f9;
}

@media (max-width: 980px) {
  .app {
    width: min(100vw - 20px, 760px);
    padding: 16px 0;
  }

  .login-screen {
    padding: 18px;
  }

  .login-shell {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .login-hero {
    min-height: auto;
    padding: 24px;
  }

  .login-hero h1 {
    font-size: 34px;
  }

  .login-preview {
    display: none;
  }

  .topbar,
  .result-head {
    align-items: stretch;
    flex-direction: column;
  }

  body.admin-mode .app-body {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    position: static;
  }

  body.admin-mode .admin-sidebar {
    display: grid;
    grid-template-columns: minmax(88px, 1fr) minmax(160px, 1.6fr) minmax(88px, 1fr) minmax(88px, 1fr);
    align-items: stretch;
  }

  .admin-sidebar button,
  .admin-sidebar .status {
    text-align: center;
  }

  .admin-subnav {
    padding-left: 0;
  }

  .admin-subnav button::before {
    display: none;
  }

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

  .admin-grid,
  .admin-stats,
  .user-row {
    grid-template-columns: 1fr;
  }

  .user-admin-head {
    flex-direction: column;
  }

  .controls {
    position: static;
  }
}

@media (max-width: 520px) {
  .login-screen {
    padding: 12px;
  }

  .login-card,
  .login-hero {
    padding: 18px;
  }

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

  .login-tabs button {
    min-height: 44px;
  }

  .login-hero h1 {
    font-size: 30px;
  }

  .brand {
    align-items: flex-start;
  }

  h1 {
    font-size: 25px;
  }

  .option-grid,
  .stat-grid,
  .result-metrics {
    grid-template-columns: 1fr;
  }

  .admin-login-row,
  .server-log-item {
    grid-template-columns: 1fr;
  }

  body.admin-mode .admin-sidebar {
    grid-template-columns: 1fr;
  }

  .server-log-side {
    justify-items: start;
    text-align: left;
  }

  .admin-head {
    flex-direction: column;
  }

  .server-log-head {
    align-items: flex-start;
    flex-direction: row;
  }

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

  .stat-card.wide {
    grid-column: auto;
  }

  .history-item {
    grid-template-columns: 70px 1fr;
  }

  .history-side {
    grid-column: 2;
    justify-items: start;
    text-align: left;
  }
}
