:root {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #111a2d;
  --surface-2: #172238;
  --surface-hover: #1d2a43;
  --border: #2b3a55;
  --border-soft: #202d46;
  --text: #f8fafc;
  --text-secondary: #aab8cf;
  --text-muted: #7e8da7;
  --accent: #3ddc84;
  --accent-strong: #20bd6a;
  --accent-ink: #052e18;
  --warning: #fbbf24;
  --danger: #fb7185;
  --info: #60a5fa;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(1, 6, 16, 0.24);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -10%, rgba(61, 220, 132, 0.11), transparent 30rem),
    radial-gradient(circle at 100% 0, rgba(96, 165, 250, 0.08), transparent 32rem),
    var(--bg);
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgba(96, 165, 250, 0.7);
  outline-offset: 2px;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(28px, 4vw, 40px); line-height: 1.15; letter-spacing: -0.035em; }
h2 { margin-bottom: 0; font-size: 21px; line-height: 1.25; letter-spacing: -0.02em; }

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.muted { color: var(--text-secondary); }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-variant-numeric: tabular-nums; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 12px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid rgba(71, 85, 105, 0.45);
  background: rgba(11, 17, 32, 0.86);
  backdrop-filter: blur(16px);
}

.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; }
.brand > span:last-child { display: grid; }
.brand strong { font-size: 16px; }
.brand small { color: var(--text-muted); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  color: var(--accent);
  border: 1px solid rgba(61, 220, 132, 0.3);
  border-radius: 12px;
  background: rgba(61, 220, 132, 0.08);
}
.brand-mark svg { width: 24px; height: 24px; }

.top-actions { display: flex; align-items: center; gap: 10px; }
.top-actions form { margin: 0; }

.button, .icon-button, .text-button {
  border: 0;
  cursor: pointer;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease, opacity 180ms ease;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 650;
}

.button-primary { color: var(--accent-ink); background: var(--accent); }
.button-primary:hover:not(:disabled) { background: #65e59d; }
.button-secondary { color: var(--text); border-color: var(--border); background: var(--surface-2); }
.button-secondary:hover:not(:disabled), .button-ghost:hover:not(:disabled) { background: var(--surface-hover); border-color: #405273; }
.button-ghost { color: var(--text-secondary); border-color: var(--border-soft); background: transparent; }
.button-full { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: 0.42; }

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  color: var(--text-secondary);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
}
.icon-button:hover { color: var(--text); border-color: var(--border); background: var(--surface-2); }
.text-button { min-height: 44px; padding: 0 6px; color: var(--accent); background: transparent; font-weight: 650; }
.text-button:hover { color: #7eeba9; }

.page-shell { width: min(1320px, calc(100% - 32px)); margin: 0 auto; padding: 48px 0 80px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 32px; margin-bottom: 32px; }
.page-heading > div:first-child > p:last-child { max-width: 650px; margin-bottom: 0; color: var(--text-secondary); }
.summary-card { display: flex; gap: 24px; padding: 14px 18px; border: 1px solid var(--border-soft); border-radius: 12px; background: rgba(17, 26, 45, 0.72); color: var(--text-secondary); white-space: nowrap; }
.summary-card strong { color: var(--text); font-size: 18px; font-variant-numeric: tabular-nums; }

.flash-region { display: grid; gap: 8px; margin-bottom: 20px; }
.alert { padding: 12px 14px; border: 1px solid; border-radius: 10px; font-size: 14px; }
.alert-error { color: #fecdd3; border-color: rgba(251, 113, 133, 0.38); background: rgba(251, 113, 133, 0.09); }
.alert-success { color: #bbf7d0; border-color: rgba(61, 220, 132, 0.34); background: rgba(61, 220, 132, 0.08); }

.empty-state {
  display: grid;
  min-height: 390px;
  place-items: center;
  align-content: center;
  padding: 32px;
  text-align: center;
  border: 1px dashed #344663;
  border-radius: var(--radius);
  background: rgba(17, 26, 45, 0.42);
}
.empty-state h2 { margin-bottom: 10px; font-size: 24px; }
.empty-state > p:not(.eyebrow) { max-width: 440px; margin-bottom: 22px; color: var(--text-secondary); }
.empty-icon { display: grid; width: 64px; height: 64px; place-items: center; margin-bottom: 20px; color: var(--accent); border: 1px solid rgba(61, 220, 132, 0.24); border-radius: 18px; background: rgba(61, 220, 132, 0.07); }
.empty-icon svg { width: 32px; height: 32px; }

.region-list { display: grid; gap: 24px; }
.region-block { overflow: hidden; border: 1px solid var(--border-soft); border-radius: var(--radius); background: rgba(17, 26, 45, 0.66); box-shadow: var(--shadow); }
.region-header { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 22px 24px; border-bottom: 1px solid var(--border-soft); }
.region-title-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.count-pill { padding: 2px 8px; color: var(--text-secondary); border: 1px solid var(--border); border-radius: 999px; font-size: 12px; }
.credential-pill { padding: 2px 8px; color: #86efac; border: 1px solid rgba(61, 220, 132, 0.3); border-radius: 999px; background: rgba(61, 220, 132, 0.07); font-size: 12px; }
.region-actions { display: flex; flex: 0 0 auto; gap: 10px; }
.repo-line { display: flex; align-items: center; gap: 7px; max-width: min(62vw, 720px); margin-bottom: 0; overflow: hidden; color: var(--text-muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.repo-line svg { width: 16px; height: 16px; flex: 0 0 auto; }

.site-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 16px; padding: 20px; }
.site-card { display: flex; min-height: 304px; flex-direction: column; padding: 20px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.site-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.site-name { margin-bottom: 4px; font-size: 17px; font-weight: 700; }
.site-host { margin-bottom: 0; color: var(--text-muted); font-size: 12px; font-family: "SFMono-Regular", Consolas, monospace; }
.status-badge { display: inline-flex; min-height: 30px; align-items: center; gap: 7px; padding: 4px 9px; border: 1px solid; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 10px currentColor; }
.status-loading, .status-unknown { color: var(--text-secondary); border-color: var(--border); background: rgba(126, 141, 167, 0.08); }
.status-latest { color: #86efac; border-color: rgba(61, 220, 132, 0.32); background: rgba(61, 220, 132, 0.08); }
.status-outdated { color: #fde68a; border-color: rgba(251, 191, 36, 0.34); background: rgba(251, 191, 36, 0.08); }
.status-warning { color: #fdba74; border-color: rgba(251, 146, 60, 0.34); background: rgba(251, 146, 60, 0.08); }
.status-offline { color: #fda4af; border-color: rgba(251, 113, 133, 0.34); background: rgba(251, 113, 133, 0.08); }

.site-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 18px; }
.site-meta > div { min-width: 0; padding: 11px; border: 1px solid var(--border-soft); border-radius: 9px; background: rgba(23, 34, 56, 0.62); }
.site-meta dt { margin-bottom: 4px; color: var(--text-muted); font-size: 11px; }
.site-meta dd { margin: 0; overflow: hidden; color: var(--text); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.site-path { margin-bottom: 7px; overflow: hidden; color: var(--text-muted); font-size: 12px; font-family: "SFMono-Regular", Consolas, monospace; text-overflow: ellipsis; white-space: nowrap; }
.key-mode { margin: 0 0 7px; color: var(--text-muted); font-size: 12px; }
.status-detail { min-height: 42px; margin-bottom: 18px; color: var(--text-secondary); font-size: 13px; }
.site-actions { display: flex; gap: 10px; margin-top: auto; }
.site-actions .button { flex: 1; }
.region-empty { display: flex; min-height: 130px; align-items: center; justify-content: center; gap: 12px; color: var(--text-secondary); }
.region-empty p { margin: 0; }

.modal { width: min(92vw, 540px); max-width: calc(100vw - 32px); max-height: calc(100dvh - 32px); padding: 0; overflow-x: hidden; overflow-y: auto; color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); background: transparent; box-shadow: var(--shadow); }
#site-dialog, #site-edit-dialog { width: min(92vw, 660px); }
.modal::backdrop { background: rgba(1, 6, 16, 0.72); backdrop-filter: blur(5px); }
.modal-card { width: 100%; max-width: 100%; padding: 24px; background: var(--surface); }
.modal-card-wide { width: 100%; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.modal-header h2 { font-size: 24px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

.form-stack { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.form-grid > label { min-width: 0; }
.span-2 { grid-column: span 2; }
label { display: grid; gap: 7px; color: var(--text-secondary); font-size: 13px; font-weight: 600; }
label small { color: var(--text-muted); font-size: 12px; font-weight: 400; }
input, select, textarea { width: 100%; min-width: 0; min-height: 46px; padding: 10px 12px; color: var(--text); border: 1px solid var(--border); border-radius: 9px; background: #0d1628; }
textarea { min-height: 132px; resize: vertical; font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
input::placeholder, textarea::placeholder { color: #61708b; }
input:hover, select:hover, textarea:hover { border-color: #465979; }
input:focus, select:focus, textarea:focus { border-color: var(--info); }
.form-section { display: grid; gap: 14px; padding: 15px; border: 1px solid var(--border-soft); border-radius: 11px; background: rgba(13, 22, 40, 0.56); }
.form-section > p { display: flex; justify-content: space-between; gap: 12px; margin: 0; color: var(--text); font-size: 13px; }
.form-section > p small { color: var(--text-muted); font-weight: 400; }
.check-label { display: flex; align-items: center; gap: 9px; }
.check-label input { width: 17px; min-height: 17px; margin: 0; padding: 0; accent-color: var(--accent); }
.warning-note { margin: 0; padding: 11px 12px; color: #fde68a; border: 1px solid rgba(251, 191, 36, 0.25); border-radius: 9px; background: rgba(251, 191, 36, 0.06); font-size: 12px; }
.warning-note code { font-family: "SFMono-Regular", Consolas, monospace; }
.public-key { max-height: 180px; margin: 18px 0 0; padding: 14px; overflow: auto; color: #bbf7d0; border: 1px solid var(--border); border-radius: 10px; background: #09111f; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
.copy-feedback { align-self: center; margin-right: auto; color: var(--accent); font-size: 12px; }

.login-page { display: grid; place-items: center; padding: 24px; }
.login-shell { display: grid; width: min(100%, 980px); grid-template-columns: 1.1fr 0.9fr; align-items: center; gap: clamp(40px, 8vw, 100px); }
.login-copy h1 { max-width: 520px; font-size: clamp(38px, 6vw, 64px); }
.login-copy > p:last-child { max-width: 510px; color: var(--text-secondary); font-size: 17px; }
.login-copy .brand-mark { width: 52px; height: 52px; margin-bottom: 26px; }
.login-card { display: grid; gap: 24px; padding: 28px; border: 1px solid var(--border); border-radius: 18px; background: rgba(17, 26, 45, 0.88); box-shadow: var(--shadow); }
.login-card h2 { margin-bottom: 8px; font-size: 25px; }
.login-card p { margin-bottom: 0; }

@media (max-width: 760px) {
  .topbar { align-items: flex-start; }
  .brand small { display: none; }
  .top-actions { gap: 6px; }
  .top-actions .button { width: 44px; padding: 0; font-size: 0; }
  .top-actions .button svg { width: 20px; height: 20px; }
  .page-shell { width: min(100% - 24px, 1320px); padding-top: 32px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .summary-card { width: 100%; justify-content: space-between; }
  .region-header { align-items: flex-start; flex-direction: column; padding: 18px; }
  .region-actions { width: 100%; }
  .region-actions .button { flex: 1; }
  .region-title-row { flex-wrap: wrap; }
  .repo-line { max-width: calc(100vw - 64px); }
  .site-grid { padding: 12px; }
  .site-meta { grid-template-columns: 1fr; }
  .site-card { min-height: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .modal-card { padding: 20px; }
  .login-shell { grid-template-columns: 1fr; }
  .login-copy { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
