:root {
  --bg: #060a12;
  --bg2: #0c1220;
  --surface: #111827;
  --surface2: #1a2332;
  --surface3: #222d3f;
  --border: #2a3548;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #6366f1;
  --accent2: #818cf8;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --success: #22c55e;
  --danger: #ef4444;
  --sidebar-w: 260px;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { min-height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(ellipse 120% 80% at 50% -20%, #1e1b4b 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent2); text-decoration: none; }

.shell {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: rgba(17, 24, 39, 0.95);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  backdrop-filter: blur(14px);
}

.sidebar-brand {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
}

.sidebar-brand p {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.nav-group {
  margin-bottom: 18px;
}

.nav-group-title {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 10px 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #cbd5e1;
  font-size: 0.92rem;
  margin-bottom: 4px;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
  background: var(--surface2);
  color: #fff;
}

.nav-link.is-active {
  background: var(--accent-soft);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.35);
}

.nav-icon {
  width: 18px;
  text-align: center;
  opacity: 0.85;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 3vw, 28px);
  border-bottom: 1px solid var(--border);
  background: rgba(6, 10, 18, 0.72);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h2 {
  font-size: clamp(1.1rem, 2vw, 1.35rem);
}

.topbar p {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

.main {
  flex: 1;
  padding: clamp(16px, 3vw, 28px);
  width: 100%;
  max-width: 1200px;
}

.alert {
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 0.925rem;
}

.alert-err {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fecaca;
}

.alert-ok {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #bbf7d0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 20px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(18px, 3vw, 24px);
  box-shadow: var(--shadow);
}

.card h3 {
  font-size: 1.05rem;
  margin-bottom: 6px;
}

.card .desc {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 18px;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 8px;
}

.field input[type=text],
.field input[type=password],
.field input[type=file],
.field input[type=number],
.field input[type=url],
.field select,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid rgba(99, 102, 241, 0.45);
  border-color: var(--accent);
}

.field textarea { min-height: 80px; resize: vertical; }

.filename {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 10px;
  background: var(--surface2);
  border-radius: 6px;
  font-size: 0.78rem;
  color: var(--accent2);
  font-family: ui-monospace, monospace;
}

.preview-box {
  margin-top: 12px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: var(--bg);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 12px;
}

.preview-box img {
  max-width: 100%;
  max-height: 160px;
  object-fit: contain;
  border-radius: 8px;
}

.preview-box.wide {
  min-height: 160px;
}

.preview-box.wide img {
  max-width: 100%;
  width: 100%;
  height: auto;
  max-height: none;
  object-fit: contain;
}

.preview-box.app img {
  max-height: 96px;
  width: 96px;
  border-radius: 16px;
}

.preview-empty { color: var(--muted); font-size: 0.85rem; }

.span-full { grid-column: 1 / -1; }

.actions {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, transform 0.15s;
}

.btn:hover {
  background: var(--accent2);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:hover { background: var(--surface2); }

.btn-block { width: 100%; }

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
}

.pill strong { color: var(--text); }

.api-box {
  margin-top: 8px;
  padding: 14px;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  word-break: break-all;
  color: #cbd5e1;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: linear-gradient(180deg, var(--surface2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.stat-card .label {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card .value {
  font-size: 1.4rem;
  font-weight: 700;
  margin-top: 6px;
}

.app-slot {
  position: relative;
}

.app-slot .slot-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
}

.effect-tag {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(129, 140, 248, 0.15);
  color: #c7d2fe;
  font-size: 0.75rem;
}

.package-readonly {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background: var(--bg);
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  color: #cbd5e1;
  word-break: break-all;
}

.detect-status {
  margin-top: 10px;
  font-size: 0.82rem;
  padding: 8px 12px;
  border-radius: 8px;
  display: none;
}

.detect-status.is-loading,
.detect-status.is-ok,
.detect-status.is-error {
  display: block;
}

.detect-status.is-loading {
  background: rgba(99, 102, 241, 0.12);
  color: #c7d2fe;
}

.detect-status.is-ok {
  background: rgba(34, 197, 94, 0.12);
  color: #bbf7d0;
}

.detect-status.is-error {
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}

.login-card h2 { margin-bottom: 8px; }

.login-card .hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 24px;
}

.menu-toggle {
  display: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar.is-open { transform: translateX(0); }

  .content { margin-left: 0; }

  .menu-toggle { display: inline-flex; }

  .grid-2 { grid-template-columns: 1fr; }
}
