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

:root {
  --bg-base: #0d1117;
  --bg-sidebar: #161b22;
  --bg-card: #1c2128;
  --bg-card-hover: #21262d;
  --bg-input: #161b22;
  --bg-table-row: #1c2128;
  --bg-table-alt: #21262d;
  --border: #30363d;
  --border-light: #21262d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --blue: #58a6ff;
  --blue-bg: rgba(88, 166, 255, .12);
  --green: #3fb950;
  --green-bg: rgba(63, 185, 80, .12);
  --red: #f85149;
  --red-bg: rgba(248, 81, 73, .12);
  --yellow: #d29922;
  --yellow-bg: rgba(210, 153, 34, .12);
  --purple: #bc8cff;
  --purple-bg: rgba(188, 140, 255, .12);
  --cyan: #56d4dd;
  --cyan-bg: rgba(86, 212, 221, .12);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-w: 220px;
  --topbar-h: 56px;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
}

body { overflow: hidden; }
a { color: inherit; text-decoration: none; }

.login-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top, rgba(88, 166, 255, .18), transparent 36%),
    rgba(13, 17, 23, .92);
  backdrop-filter: blur(8px);
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

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

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 18;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(13, 17, 23, .72);
  backdrop-filter: blur(6px);
}

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

.modal-panel {
  width: min(100%, 560px);
  background: linear-gradient(180deg, rgba(28, 33, 40, .98), rgba(22, 27, 34, .98));
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .42);
  overflow: hidden;
}

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

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: var(--bg-card-hover);
}

.modal-body {
  padding: 20px;
}

.login-panel {
  width: min(100%, 420px);
  background: linear-gradient(180deg, rgba(28, 33, 40, .98), rgba(22, 27, 34, .98));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .45);
}

.login-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--blue-bg);
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .3px;
  margin-bottom: 14px;
}

.login-panel h1 {
  font-size: 26px;
  line-height: 1.2;
  margin-bottom: 8px;
}

.login-panel p {
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: rgba(88, 166, 255, .55);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, .14);
}

.field input[readonly] {
  opacity: .82;
}

.login-error {
  min-height: 22px;
  margin-top: 12px;
  color: #ff9b9b;
  font-size: 12.5px;
}

.app-layout { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--blue-bg);
  border: 1px solid rgba(88, 166, 255, .3);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue);
  flex-shrink: 0;
}

.logo-text { font-size: 15px; font-weight: 700; letter-spacing: .3px; }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid transparent;
}

.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-item.active {
  background: var(--blue-bg);
  color: var(--blue);
  border-color: rgba(88, 166, 255, .2);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.version-badge { font-size: 11px; color: var(--text-muted); }

.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.status-indicator { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); }

.admin-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.admin-chip-label {
  color: var(--text-secondary);
  font-size: 12px;
}

.admin-chip-name {
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 700;
}

.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-green { background: var(--green); box-shadow: 0 0 6px var(--green); }

.page-content { flex: 1; overflow-y: auto; padding: 24px; }

.stats-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 24px; }

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon-blue { background: var(--blue-bg); color: var(--blue); }
.stat-icon-green { background: var(--green-bg); color: var(--green); }
.stat-icon-yellow { background: var(--yellow-bg); color: var(--yellow); }
.stat-icon-purple { background: var(--purple-bg); color: var(--purple); }
.stat-icon-cyan { background: var(--cyan-bg); color: var(--cyan); }

.stat-value { font-size: 28px; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 20px;
}

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

.card-title { font-size: 14.5px; font-weight: 600; }
.card-body { padding: 20px; }
.meta-row { display: flex; align-items: center; gap: 12px; color: var(--text-secondary); font-size: 12.5px; }
.card-header-wrap { align-items: flex-start; }
.card-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, .9fr);
  gap: 20px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.detail-item {
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.detail-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.detail-value { font-size: 14px; color: var(--text-primary); word-break: break-word; }

.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.data-table th {
  padding: 10px 16px;
  text-align: left;
  color: var(--text-secondary);
  font-weight: 600;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.data-table tbody tr:nth-child(odd) { background: var(--bg-table-row); }
.data-table tbody tr:nth-child(even) { background: var(--bg-table-alt); }
.data-table tbody tr.bookmark-row-active {
  background: rgba(88, 166, 255, .12);
}

.empty-cell { text-align: center; color: var(--text-secondary); padding: 24px 16px; }

.bookmark-url-cell {
  max-width: 0;
  word-break: break-all;
}

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

.notice {
  margin-top: 4px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(88, 166, 255, .2);
  background: rgba(88, 166, 255, .08);
  color: var(--text-primary);
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr);
  gap: 16px;
}

.editor-panel {
  min-width: 0;
}

.json-editor {
  width: 100%;
  min-height: 420px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font: 12px/1.6 Consolas, 'Courier New', monospace;
  resize: vertical;
  outline: none;
}

.json-editor:focus {
  border-color: rgba(88, 166, 255, .55);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, .14);
}

.editor-hint {
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 12px;
}

.bookmark-preview-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 540px;
  overflow-y: auto;
}

.bookmark-preview-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.bookmark-preview-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .08);
  object-fit: contain;
  padding: 4px;
}

.bookmark-preview-fallback {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--bg-card-hover);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
}

.bookmark-preview-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.bookmark-preview-url {
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 12px;
  word-break: break-all;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-green { background: var(--green-bg); color: var(--green); }
.badge-muted { background: var(--bg-input); color: var(--text-secondary); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-primary);
}

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

.btn-primary {
  background: linear-gradient(180deg, #2f81f7, #1f6feb);
  border-color: rgba(88, 166, 255, .35);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }

.btn-secondary {
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) { background: var(--bg-card-hover); }

.btn-block { width: 100%; }
.btn-xs {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.bookmark-help-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bookmark-help-item {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

.checkbox-field {
  justify-content: flex-end;
}

.checkbox-field input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  padding: 0;
}

.mono {
  font-family: Consolas, 'Courier New', monospace;
}

@media (max-width: 1080px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .editor-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  body { overflow: auto; }
  .app-layout { display: block; height: auto; }
  .sidebar {
    width: 100%;
    min-width: 0;
  }
  .topbar {
    height: auto;
    min-height: 0;
    padding: 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }
  .page-content { padding: 16px; }
  .stats-grid,
  .detail-grid { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: 1fr; }
  .modal-overlay {
    padding: 12px;
  }
  .modal-panel {
    width: 100%;
  }
}

.btn-primary { background: var(--blue); color: #fff; }
.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border);
}

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app-layout { display: block; height: auto; }
  .sidebar { width: auto; min-width: 0; }
  .topbar {
    height: auto;
    min-height: 0;
    padding: 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .page-content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr; }
}
