:root {
  color-scheme: dark;
  --bg: #050816;
  --panel: rgba(10, 17, 34, 0.78);
  --panel-strong: rgba(12, 20, 39, 0.94);
  --line: rgba(148, 163, 184, 0.2);
  --text: #eef6ff;
  --muted: rgba(226, 232, 240, 0.66);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
  --sidebar-width: 288px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 18% 12%, rgba(34, 211, 238, 0.2), transparent 28%),
    radial-gradient(circle at 82% 18%, rgba(244, 114, 182, 0.13), transparent 30%),
    radial-gradient(circle at 58% 82%, rgba(52, 211, 153, 0.14), transparent 32%),
    linear-gradient(135deg, #030712 0%, #08111f 50%, #060817 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(125, 211, 252, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(125, 211, 252, 0.06) 1px, transparent 1px);
  background-size: 38px 38px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.9), rgba(0,0,0,0.18));
  animation: gridDrift 22s linear infinite;
}

button {
  font: inherit;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) 12px 1fr;
  height: 100dvh;
  padding: 14px;
  gap: 14px;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 72px 12px 1fr;
}

.app-shell.sidebar-collapsed .brand-block div,
.app-shell.sidebar-collapsed .site-button span:not(.site-dot),
.app-shell.sidebar-collapsed .rail-actions button:not(#toggleSidebar) {
  display: none;
}

.app-shell.sidebar-collapsed .side-rail {
  align-items: center;
  padding: 12px;
}

.app-shell.sidebar-collapsed .brand-mark {
  width: 44px;
  height: 44px;
}

.app-shell.sidebar-collapsed .site-button {
  justify-content: center;
  width: 46px;
  min-height: 46px;
  padding: 0;
}

.app-shell.sidebar-collapsed .site-dot {
  width: 16px;
  height: 16px;
}

.app-shell.sidebar-collapsed #toggleSidebar {
  width: 48px;
  min-height: 44px;
  padding: 0 4px;
  font-size: 12px;
}

.app-shell.workspace-fullscreen {
  grid-template-columns: 1fr;
  padding: 0;
}

.app-shell.workspace-fullscreen .side-rail {
  display: none;
}

.app-shell.workspace-fullscreen .split-resizer {
  display: none;
}

.app-shell.workspace-fullscreen .workspace-shell {
  border-radius: 0;
  border: 0;
}

.side-rail,
.workspace-shell,
.site-window {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(18px);
}

.side-rail {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  border-radius: 18px;
}

.split-resizer {
  align-self: stretch;
  width: 12px;
  min-width: 12px;
  border: 1px solid rgba(34, 211, 238, 0.18);
  border-radius: 999px;
  background:
    linear-gradient(180deg, transparent, rgba(34, 211, 238, 0.24), transparent),
    rgba(15, 23, 42, 0.5);
  cursor: col-resize;
  touch-action: none;
}

.split-resizer:hover,
.split-resizer:focus-visible {
  border-color: rgba(34, 211, 238, 0.62);
  box-shadow: 0 0 20px rgba(34, 211, 238, 0.2);
  outline: none;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border: 1px solid rgba(34, 211, 238, 0.38);
  border-radius: 14px;
  color: #a5f3fc;
  font-weight: 800;
  background: linear-gradient(145deg, rgba(34, 211, 238, 0.22), rgba(168, 85, 247, 0.16));
}

h1,
h2,
p {
  margin: 0;
}

.brand-block h1 {
  font-size: 18px;
  letter-spacing: 0;
}

.brand-block p,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
}

.site-nav {
  display: grid;
  gap: 10px;
}

.site-button,
.rail-actions button,
.window-actions button,
.fullscreen-toggle {
  cursor: pointer;
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(15, 23, 42, 0.62);
}

.site-button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 62px;
  padding: 10px;
  border-radius: 14px;
  text-align: left;
  overflow: hidden;
}

.site-button::after {
  content: "";
  position: absolute;
  inset: auto -20% 0 20%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.72;
}

.site-button:hover,
.site-button.is-active {
  border-color: color-mix(in srgb, var(--accent), white 14%);
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent), transparent 82%), rgba(15, 23, 42, 0.78));
}

.site-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 18px var(--accent);
}

.site-button strong,
.site-button small {
  display: block;
  letter-spacing: 0;
}

.site-button small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.rail-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: auto;
}

.rail-actions button,
.window-actions button,
.fullscreen-toggle {
  min-height: 38px;
  border-radius: 10px;
}

.workspace-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  border-radius: 20px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-height: 50px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(3, 7, 18, 0.36);
}

.workspace {
  position: relative;
  overflow: hidden;
  min-height: 0;
  background:
    linear-gradient(rgba(34, 211, 238, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 211, 238, 0.05) 1px, transparent 1px);
  background-size: 32px 32px;
}

.workspace::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 0%, rgba(34, 211, 238, 0.08) 48%, transparent 56%);
  transform: translateX(-70%);
  animation: scan 8s ease-in-out infinite;
}

.empty-state {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  gap: 8px;
  width: min(420px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  padding: 28px;
  border: 1px dashed rgba(125, 211, 252, 0.36);
  border-radius: 18px;
  text-align: center;
  color: var(--muted);
  background: rgba(15, 23, 42, 0.36);
}

.empty-state strong {
  color: var(--text);
  font-size: 20px;
}

.site-window {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  grid-template-rows: 48px 1fr;
  min-width: 280px;
  min-height: 240px;
  border-radius: 16px;
  overflow: hidden;
  transition: box-shadow 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.site-window:hover {
  border-color: color-mix(in srgb, var(--accent), white 10%);
}

.site-window.is-maximized {
  width: calc(100% - 20px) !important;
  height: calc(100% - 20px) !important;
  transform: translate(10px, 10px) !important;
}

.site-window.is-minimized {
  height: 48px !important;
  min-height: 48px;
}

.site-window.is-minimized .site-frame,
.site-window.is-minimized .resize-handle {
  display: none;
}

.window-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--accent), transparent 82%), rgba(15, 23, 42, 0.88));
}

.drag-handle {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
  gap: 9px;
  height: 34px;
  border: 0;
  color: var(--text);
  background: transparent;
  text-align: left;
  cursor: grab;
}

.drag-handle:active {
  cursor: grabbing;
}

.window-light {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  box-shadow: 0 0 16px currentColor;
}

.window-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  letter-spacing: 0;
}

.window-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.window-actions button {
  min-width: 44px;
  min-height: 32px;
  padding: 0 8px;
  font-size: 12px;
}

.frame-wrap {
  position: relative;
  min-height: 0;
}

.site-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: white;
}

.activation-shield {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  border: 0;
  color: transparent;
  background: rgba(2, 6, 23, 0.01);
  cursor: pointer;
}

.activation-shield:hover {
  color: rgba(226, 232, 240, 0.86);
  background: rgba(2, 6, 23, 0.26);
}

.site-window.is-active .activation-shield {
  display: none;
}

.resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 22px;
  height: 22px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 45%, color-mix(in srgb, var(--accent), white 20%) 46%, transparent 54%);
}

.topbar-actions {
  display: flex;
  justify-content: flex-end;
  width: 100%;
}

.mobile-window-tabs {
  display: none;
}

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

.account-actions a,
.account-actions button,
.auth-links a {
  min-height: 30px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 999px;
  padding: 6px 10px;
  color: #dff7ff;
  background: rgba(15, 23, 42, 0.56);
  font-size: 12px;
  text-decoration: none;
}

.fullscreen-toggle {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
}

.auth-body {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  overflow: auto;
  padding: 18px;
}

.auth-panel,
.log-panel {
  width: min(480px, 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  background: var(--panel-strong);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(18px);
}

.account-layout {
  display: grid;
  grid-template-columns: minmax(320px, 480px) minmax(320px, 560px);
  align-items: start;
  gap: 16px;
  width: min(1080px, 100%);
}

.account-layout.single {
  grid-template-columns: minmax(320px, 720px);
  justify-content: center;
}

.sites-layout {
  width: min(1180px, 100%);
}

.sites-form {
  display: grid;
  gap: 14px;
}

.sites-table {
  display: grid;
  gap: 8px;
  overflow-x: auto;
}

.sites-head,
.site-edit-row {
  display: grid;
  grid-template-columns: 58px 82px minmax(120px, 1fr) minmax(140px, 1.2fr) minmax(220px, 1.4fr);
  gap: 8px;
  align-items: center;
  min-width: 760px;
}

.sites-head {
  color: var(--muted);
  font-size: 12px;
  padding: 0 10px;
}

.site-edit-row {
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 12px;
  padding: 10px;
  background: rgba(15, 23, 42, 0.48);
}

.site-edit-row input[type="text"],
.site-edit-row input:not([type]) {
  width: 100%;
  min-height: 38px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 10px;
  padding: 0 10px;
  color: var(--text);
  background: rgba(2, 6, 23, 0.38);
}

.site-edit-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
}

.site-url {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-brand {
  margin-bottom: 20px;
}

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

.auth-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.auth-form input {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(148, 163, 184, 0.26);
  border-radius: 12px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(15, 23, 42, 0.72);
  outline: none;
}

.auth-form input:focus {
  border-color: rgba(34, 211, 238, 0.72);
  box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.12);
}

.secret-box {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.secret-box textarea {
  width: 100%;
  resize: vertical;
  color: #e0f2fe;
  border: 1px solid rgba(125, 211, 252, 0.28);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.72);
  padding: 12px;
  font: 13px ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.captcha-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 10px;
}

.captcha-row strong {
  display: grid;
  place-items: center;
  min-height: 44px;
  border: 1px solid rgba(34, 211, 238, 0.32);
  border-radius: 12px;
  color: #a5f3fc;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.18), rgba(168, 85, 247, 0.16));
  font-size: 22px;
  letter-spacing: 4px;
}

.primary-auth {
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  color: #03131f;
  background: linear-gradient(90deg, #22d3ee, #34d399);
  font-weight: 800;
  cursor: pointer;
}

.auth-alert {
  margin-bottom: 14px;
  border-radius: 12px;
  padding: 10px 12px;
}

.auth-alert.error {
  color: #fecaca;
  background: rgba(127, 29, 29, 0.42);
  border: 1px solid rgba(248, 113, 113, 0.26);
}

.auth-alert.ok {
  color: #bbf7d0;
  background: rgba(20, 83, 45, 0.42);
  border: 1px solid rgba(74, 222, 128, 0.26);
}

.auth-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.log-panel h2 {
  margin: 0 0 14px;
}

.log-list {
  display: grid;
  gap: 8px;
}

.log-row {
  display: grid;
  gap: 4px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-left: 3px solid #f87171;
  border-radius: 12px;
  padding: 10px;
  background: rgba(15, 23, 42, 0.52);
  color: var(--muted);
  font-size: 12px;
}

.log-row.ok {
  border-left-color: #34d399;
}

.log-row strong {
  color: var(--text);
}

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

@keyframes gridDrift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(38px, 38px, 0); }
}

@keyframes scan {
  0%, 20% { transform: translateX(-80%); opacity: 0; }
  45%, 65% { opacity: 1; }
  100% { transform: translateX(80%); opacity: 0; }
}

@media (max-width: 820px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: 100dvh;
    min-height: 100dvh;
    padding: 8px;
    gap: 8px;
  }

  .side-rail {
    position: relative;
    z-index: 1000;
    gap: 10px;
    padding: 10px;
    border-radius: 14px;
    overflow: hidden;
  }

  .split-resizer {
    display: none;
  }

  .brand-block {
    align-items: center;
  }

  .brand-block h1 {
    font-size: 15px;
  }

  .brand-block p {
    display: none;
  }

  .site-nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .site-button {
    width: auto;
    min-width: 76px;
    min-height: 44px;
    justify-content: center;
    padding: 8px 10px;
    border-radius: 12px;
    text-align: center;
  }

  .site-button small {
    display: none;
  }

  .site-dot {
    display: none;
  }

  .rail-actions {
    display: flex;
    margin-top: 0;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .rail-actions button {
    min-width: max-content;
    min-height: 34px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 12px;
  }

  .workspace-shell {
    grid-template-rows: auto auto 1fr;
    min-height: 0;
    border-radius: 14px;
  }

  .topbar {
    align-items: center;
    min-height: 44px;
    padding: 8px;
  }

  .topbar-actions {
    justify-content: flex-start;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .account-actions {
    flex-wrap: nowrap;
    min-width: max-content;
  }

  .mobile-window-tabs {
    display: flex;
    gap: 8px;
    min-height: 42px;
    padding: 6px 8px;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
    background: rgba(3, 7, 18, 0.3);
    -webkit-overflow-scrolling: touch;
  }

  .mobile-window-tabs[hidden] {
    display: none;
  }

  .mobile-window-tabs button {
    min-width: max-content;
    min-height: 30px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 999px;
    padding: 0 10px;
    color: var(--text);
    background: rgba(15, 23, 42, 0.62);
  }

  .mobile-window-tabs button.is-active {
    border-color: color-mix(in srgb, var(--accent), white 16%);
    background: color-mix(in srgb, var(--accent), rgba(15, 23, 42, 0.82) 76%);
  }

  .workspace {
    min-height: 0;
  }

  .site-window {
    inset: 8px auto auto 8px;
    width: calc(100% - 16px) !important;
    height: calc(100% - 16px) !important;
    min-width: 0;
    min-height: 0;
    transform: none !important;
    border-radius: 14px;
  }

  .site-window.is-mobile-hidden {
    display: none;
  }

  .site-window.is-mobile-hidden.is-active {
    display: grid;
  }

  .site-window.is-maximized {
    width: calc(100% - 16px) !important;
    height: calc(100% - 16px) !important;
    transform: none !important;
  }

  .site-window.is-minimized {
    height: 48px !important;
  }

  .drag-handle {
    min-width: 72px;
  }

  .window-actions {
    gap: 4px;
    max-width: 68%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .window-actions button {
    min-width: 38px;
    min-height: 30px;
    padding: 0 7px;
    border-radius: 999px;
    font-size: 12px;
  }

  .resize-handle {
    display: none;
  }

  .account-layout {
    grid-template-columns: 1fr;
  }

  .sites-layout {
    width: 100%;
  }

  .captcha-row {
    grid-template-columns: 1fr;
  }
}

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