:root {
  --bg: #0f1420;
  --bg-2: #161d2e;
  --panel: #1b2436;
  --border: #2a3550;
  --text: #e8ecf4;
  --muted: #8b96ad;
  --accent: #4f8cff;
  --accent-2: #7aa7ff;
  --danger: #ff5c72;
  --ok: #35d07f;
  --radius: 12px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 600px at 80% -10%, #1a2540 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
}

.hidden { display: none !important; }

.view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Login ---------- */
.card {
  width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 30px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.logo-badge {
  width: 52px;
  height: 52px;
  margin: 0 auto;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  color: #fff;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-badge.small {
  width: 30px;
  height: 30px;
  font-size: 16px;
  border-radius: 8px;
  margin: 0;
}

.card h1 { margin: 0; font-size: 22px; }
.card .sub { margin: 0; color: var(--muted); font-size: 13px; }

input, select, button {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

input:focus, select:focus { border-color: var(--accent); }

button {
  background: linear-gradient(135deg, var(--accent), #6d6bff);
  border: none;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  transition: filter .15s, transform .05s;
}

button:hover { filter: brightness(1.1); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: not-allowed; }

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: auto;
  padding: 6px 12px;
}

/* ---------- App ---------- */
#app-view { display: block; align-items: stretch; justify-content: stretch; }
#app-view:not(.hidden) { display: block; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 26px;
  border-bottom: 1px solid var(--border);
  background: rgba(22, 29, 46, .7);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .3px; }
.user { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 14px; }

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.panel-head h2 { margin: 0; font-size: 17px; }
.hint { color: var(--muted); font-size: 12.5px; }
.hint code { color: var(--accent-2); }

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

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.row label { display: flex; flex-direction: column; gap: 6px; }
.row label > span { font-size: 12.5px; color: var(--muted); }

.file-label input[type="file"] {
  padding: 8px;
  background: var(--bg-2);
}

.submit-label button { min-height: 42px; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.tabs button {
  width: auto;
  padding: 7px 16px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 500;
}

.tabs button.active {
  background: linear-gradient(135deg, var(--accent), #6d6bff);
  color: #fff;
  border-color: transparent;
}

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

.tile {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  transition: border-color .15s;
}

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

.tile.dir { cursor: pointer; }
.tile.dir:hover { border-color: var(--accent); }

.back-btn {
  grid-column: 1 / -1;
  width: auto;
  justify-self: start;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--accent-2);
  font-weight: 500;
}

.tile .thumb {
  aspect-ratio: 4 / 3;
  background: #0b101b center/contain no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile .thumb img { max-width: 100%; max-height: 100%; }

.tile .icon {
  font-size: 30px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile .meta {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
}

.tile .meta .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.tile .meta a {
  color: var(--accent-2);
  text-decoration: none;
  font-weight: 600;
}

.tile .meta a:hover { text-decoration: underline; }

.msg {
  font-size: 13px;
  margin: 4px 0 0;
}

.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

@media (max-width: 620px) {
  .row { grid-template-columns: 1fr; }
  main { padding: 16px; }
}