:root {
  --bg: #0f1114;
  --panel: #171a1f;
  --border: #2a3038;
  --text: #e8eaed;
  --muted: #8b939e;
  --accent: #3dd68c;
  --danger: #e85d5d;
  --radius: 10px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card, .panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  max-width: 420px;
  width: 100%;
}

.auth-card h1 { margin: 0 0 8px; font-size: 1.35rem; font-weight: 600; }
.muted { color: var(--muted); font-size: 0.9rem; margin: 0 0 20px; }
.error { color: var(--danger); margin: 0 0 12px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
input[type="text"], input[type="password"], input[type="url"], input[type="number"], textarea, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c0e11;
  color: var(--text);
  font: inherit;
}
select { cursor: pointer; }
textarea { min-height: 100px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.btn.primary {
  background: rgba(61, 214, 140, 0.15);
  border-color: rgba(61, 214, 140, 0.45);
  color: var(--accent);
}
.btn.danger {
  border-color: rgba(232, 93, 93, 0.5);
  color: var(--danger);
}
.btn.small { padding: 6px 12px; font-size: 0.85rem; }

.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  background: #12151a;
}
.sidebar .brand {
  font-weight: 600;
  margin-bottom: 24px;
  padding: 0 8px;
  font-size: 0.95rem;
}
.sidebar-slot {
  margin-bottom: 20px;
  padding: 0 8px;
}
.sidebar-slot-form {
  margin: 0;
}
.sidebar-slot-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}
.sidebar-slot-select {
  width: 100%;
  font-size: 0.82rem;
  padding: 8px 10px;
}
.sidebar-api-block {
  margin-top: 12px;
  font-size: 0.7rem;
  line-height: 1.35;
}
.sidebar-api-title {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--muted);
}
.sidebar-api-url {
  margin-top: 6px;
  padding: 6px 8px;
  font-size: 0.65rem;
  word-break: break-all;
  line-height: 1.35;
}
.sidebar-api-url a {
  color: var(--accent);
}
.nav a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
}
.nav a:hover { background: rgba(255,255,255,0.04); color: var(--text); text-decoration: none; }
.nav a.active { background: rgba(61, 214, 140, 0.12); color: var(--accent); }

main { padding: 28px 32px 48px; max-width: 960px; }
main h1 { margin: 0 0 20px; font-size: 1.35rem; font-weight: 600; }

.section-title {
  font-size: 0.85rem;
  text-transform: none;
  letter-spacing: 0.02em;
  color: var(--muted);
  margin: 24px 0 12px;
}
.section-title:first-child { margin-top: 0; }

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
@media (max-width: 900px) {
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
}

.card-form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-form h3 { margin: 0 0 12px; font-size: 1rem; font-weight: 600; }

.links-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 700px) {
  .links-grid { grid-template-columns: 1fr; }
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
th { color: var(--muted); font-weight: 500; }

.hint { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }

.upload-widget {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.upload-hint {
  font-size: 0.8rem;
  color: var(--muted);
  flex: 1 1 100%;
  margin-top: -4px;
}
.upload-file-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}
.upload-widget .btn.upload-trigger {
  background: rgba(61, 214, 140, 0.12);
  border-color: rgba(61, 214, 140, 0.4);
  color: var(--accent);
}
.upload-widget .btn.upload-trigger:hover {
  background: rgba(61, 214, 140, 0.2);
}
.upload-widget-label {
  flex: 1 1 100%;
  font-size: 0.9rem;
  margin-bottom: -2px;
}

.api-box {
  background: #0c0e11;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  word-break: break-all;
  margin-top: 8px;
}

.cat-section {
  margin-top: 28px;
}
.cat-section:first-of-type {
  margin-top: 20px;
}
.cat-section-title {
  margin: 0 0 10px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
}

/* 应用编辑：宽屏三列 + 紧凑间距，便于一屏内完成编辑 */
main:has(.app-edit-form) {
  padding-top: 18px;
  padding-bottom: 72px;
}
main:has(.app-edit-form) .topbar {
  margin-bottom: 4px;
}
main:has(.app-edit-form) h1 {
  margin-bottom: 8px;
}

.app-edit-block-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  margin: 0 0 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.app-edit-col > .app-edit-block-title:first-child {
  margin-top: 0;
}

.app-edit-toast {
  max-width: 1100px;
  min-height: 0;
  margin: 0 0 8px;
  padding: 0 4px;
  font-size: 0.9rem;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.app-edit-toast.app-edit-toast--visible {
  opacity: 1;
}
.app-edit-toast.app-edit-toast--error {
  color: var(--danger);
}

.app-edit-sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 20;
  margin: 12px -32px 0;
  padding: 12px 32px calc(12px + env(safe-area-inset-bottom, 0));
  background: linear-gradient(to top, var(--bg) 70%, rgba(15, 17, 20, 0.92));
  border-top: 1px solid var(--border);
}
.app-edit-sticky-inner {
  max-width: 1100px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}
@media (max-width: 900px) {
  .app-edit-sticky-actions {
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
  }
}

.upload-progress-wrap {
  flex: 1 1 100%;
  margin-top: 8px;
}
.upload-progress-wrap[hidden] {
  display: none !important;
}
.upload-progress-track {
  height: 4px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 4px;
}
.upload-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.12s ease-out;
}
.upload-progress-text {
  font-size: 0.75rem;
}
.app-edit-form {
  max-width: 1100px;
}
.app-edit-form .panel.app-edit-panel {
  max-width: none;
  width: 100%;
  padding: 12px 14px;
}
.app-edit-form.stack {
  gap: 8px;
}
.app-edit-form input[type="text"],
.app-edit-form input[type="url"],
.app-edit-form input[type="number"],
.app-edit-form select,
.app-edit-form textarea {
  padding: 7px 10px;
}
.app-edit-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px 18px;
  align-items: start;
}
.app-edit-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.app-edit-col label {
  gap: 3px;
  font-size: 0.85rem;
}
.app-edit-row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  align-items: start;
}
.app-edit-section-title {
  margin: 0 0 2px;
}
.app-edit-upload {
  margin-bottom: 0;
}
.app-edit-upload .upload-hint {
  margin-top: -6px;
}
.app-edit-col-text textarea {
  min-height: 3.75rem;
  resize: vertical;
  line-height: 1.45;
}
@media (max-width: 1024px) {
  .app-edit-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .app-edit-col-text {
    grid-column: 1 / -1;
  }
}
@media (max-width: 720px) {
  .app-edit-grid {
    grid-template-columns: 1fr;
  }
  .app-edit-row2 {
    grid-template-columns: 1fr;
  }
}

/* 应用状态标签 */
.app-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid transparent;
}
.app-status--ok {
  color: #3dd68c;
  background: rgba(61, 214, 140, 0.14);
  border-color: rgba(61, 214, 140, 0.45);
}
.app-status--maint {
  color: #e8c547;
  background: rgba(232, 197, 71, 0.12);
  border-color: rgba(232, 197, 71, 0.5);
}
.app-status--off {
  color: #e85d5d;
  background: rgba(232, 93, 93, 0.12);
  border-color: rgba(232, 93, 93, 0.5);
}
