:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-muted: #fafaf8;
  --surface-hover: #f1f1ec;
  --border: #e5e5df;
  --border-strong: #cfcfc7;
  --text: #161618;
  --text-secondary: #5a5a63;
  --text-muted: #8a8a93;
  --primary: #18181b;
  --primary-hover: #2d2d34;
  --primary-fg: #ffffff;
  --accent: #1d4ed8;
  --accent-bg: #eff6ff;
  --accent-border: #bfdbfe;
  --zip-color: #b45309;
  --zip-bg: #fef3c7;
  --success: #047857;
  --success-bg: #ecfdf5;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 16, 20, 0.04);
  --shadow-md: 0 8px 24px rgba(16, 16, 20, 0.07);
  --shadow-lg: 0 20px 50px rgba(16, 16, 20, 0.14);
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

a {
  color: inherit;
  text-decoration: none;
}

/* Login Page */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-md);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--primary);
  color: var(--primary-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.login-title {
  margin: 18px 0 6px;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.login-subtitle {
  margin: 0 0 22px;
  color: var(--text-secondary);
  font-size: 13px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input, .textarea, .select {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus, .textarea:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.08);
}

.input-password {
  padding-right: 42px;
}

.toggle-eye {
  position: absolute;
  right: 8px;
  width: 30px;
  height: 30px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.toggle-eye:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.error-banner {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecaca;
  font-size: 13px;
  display: none;
}

.error-banner.visible {
  display: block;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.08s ease;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(0.5px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 7px;
}

.btn-icon {
  width: 30px;
  height: 30px;
  padding: 0;
}

.btn-block {
  width: 100%;
  height: 40px;
}

/* App Layout */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(246, 246, 243, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.stats-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-secondary);
}

.stats-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

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

.main-container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}

/* Upload Zone */
.upload-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 22px;
}

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  padding: 22px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  cursor: pointer;
  transition: border-color 0.16s ease, background-color 0.16s ease;
}

.dropzone:hover, .dropzone.drag-active {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.dropzone-main {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.dropzone-icon {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  flex-shrink: 0;
}

.dropzone-title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 2px;
}

.dropzone-desc {
  font-size: 12.5px;
  color: var(--text-secondary);
}

.upload-options-toggle {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.link-btn {
  border: 0;
  background: transparent;
  padding: 2px 0;
  color: var(--text-secondary);
  font-size: 12.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.link-btn:hover {
  color: var(--text);
}

.upload-options {
  display: none;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.upload-options.open {
  display: grid;
}

.upload-progress {
  display: none;
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-sm);
}

.upload-progress.visible {
  display: block;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 6px;
}

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(29, 78, 216, 0.16);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s ease;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 220px;
  max-width: 380px;
}

.search-box svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-box .input {
  padding-left: 34px;
  height: 36px;
}

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.segmented button {
  border: 0;
  background: transparent;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
}

.segmented button.active {
  background: var(--primary);
  color: var(--primary-fg);
  font-weight: 550;
}

.select-compact {
  height: 36px;
  padding: 0 28px 0 10px;
  width: auto;
  font-size: 12.5px;
}

/* Sites Grid & List */
.sites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.sites-grid.list-view {
  grid-template-columns: 1fr;
  gap: 10px;
}

.site-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.site-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.site-card.highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.sites-grid.list-view .site-card {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  gap: 16px;
}

.site-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.site-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.site-title-link {
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.site-title-link:hover {
  color: var(--accent);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.badge-html {
  background: var(--accent-bg);
  color: var(--accent);
}

.badge-zip {
  background: var(--zip-bg);
  color: var(--zip-color);
}

.site-url-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.site-url {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.site-url:hover {
  border-color: var(--accent-border);
  color: var(--accent);
}

.site-desc {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.site-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.site-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid #f0f0eb;
}

.sites-grid.list-view .site-actions {
  border-top: 0;
  padding-top: 0;
  flex-shrink: 0;
}

.action-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Empty State */
.empty-state {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 56px 24px;
  text-align: center;
}

.empty-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.empty-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
}

.empty-desc {
  margin: 0 auto 18px;
  max-width: 380px;
  color: var(--text-secondary);
  font-size: 13px;
}

/* Global Drag Overlay */
.drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(24, 24, 27, 0.45);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.drag-overlay.visible {
  display: flex;
}

.drag-overlay-box {
  background: var(--surface);
  border: 2px dashed var(--accent);
  border-radius: 20px;
  padding: 42px 54px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.drag-overlay-box h3 {
  margin: 12px 0 4px;
  font-size: 18px;
}

.drag-overlay-box p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(24, 24, 27, 0.45);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-lg {
  max-width: 620px;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.url-preview {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}

.file-list li:last-child {
  border-bottom: 0;
}

.file-path {
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Toast */
.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}

.toast {
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.18s ease;
}

.toast.toast-error {
  background: var(--danger);
}

.toast.toast-success {
  background: #14532d;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 760px) {
  .topbar-inner {
    padding: 12px 16px;
  }
  .stats-pill {
    display: none;
  }
  .main-container {
    padding: 16px 16px 48px;
  }
  .dropzone {
    flex-direction: column;
    align-items: flex-start;
  }
  .upload-options {
    grid-template-columns: 1fr;
  }
  .sites-grid {
    grid-template-columns: 1fr;
  }
  .sites-grid.list-view .site-card {
    flex-direction: column;
    align-items: stretch;
  }
}
