/* ===========================================================================
   Wormhole Drive — Google Material-inspired UI.
   All styling lives here (no inline styles) so the strict CSP
   `style-src 'self'` holds without an unsafe-inline escape hatch.
   =========================================================================== */
:root {
  --primary: #1a73e8;
  --primary-d: #1558b0;
  --primary-soft: #e8f0fe;
  --bg: #f6f8fc;
  --surface: #ffffff;
  --ink: #202124;
  --muted: #5f6368;
  --line: #dadce0;
  --ok: #188038;
  --ok-soft: #e6f4ea;
  --warn: #b06000;
  --warn-soft: #fef7e0;
  --bad: #d93025;
  --bad-soft: #fce8e6;
  --radius: 12px;
  --e1: 0 1px 2px rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15);
  --e2: 0 1px 3px rgba(60,64,67,.3), 0 4px 8px 3px rgba(60,64,67,.15);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Google Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.icon { width: 20px; height: 20px; fill: currentColor; flex: 0 0 auto; vertical-align: middle; }
.icon-lg { width: 24px; height: 24px; }
.hidden { display: none !important; }

/* ---- app bar ------------------------------------------------------------ */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  height: 64px;
}
.appbar-inner {
  max-width: 1120px; margin: 0 auto; height: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
}
.brand { display: flex; align-items: center; gap: 12px; font-size: 20px; font-weight: 500; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-logo {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, #1a73e8, #34a0e0 40%, #00bcd4);
  display: grid; place-items: center; color: #fff;
}
.brand-logo .icon { width: 18px; height: 18px; }

/* user menu */
.usermenu { position: relative; }
.usermenu-btn {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 5px 12px 5px 5px; cursor: pointer;
  font: inherit; color: var(--ink);
}
.usermenu-btn:hover { background: #f1f3f4; box-shadow: var(--e1); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: 14px;
  text-transform: uppercase;
}
.usermenu-name { font-weight: 500; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usermenu-btn .icon { color: var(--muted); }

.menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--surface); border-radius: 12px; box-shadow: var(--e2);
  min-width: 220px; padding: 8px; opacity: 0; transform: translateY(-6px);
  pointer-events: none; transition: opacity .14s ease, transform .14s ease;
}
.menu.open { opacity: 1; transform: translateY(0); pointer-events: auto; }
.menu-head { padding: 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu-head .n { font-weight: 600; }
.menu-head .r { color: var(--muted); font-size: 12px; }
.menu-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  color: var(--ink); font-size: 14px;
}
.menu-item:hover { background: #f1f3f4; text-decoration: none; }
.menu-item .icon { color: var(--muted); }

/* ---- layout ------------------------------------------------------------- */
.container { max-width: 1120px; margin: 0 auto; padding: 24px; }
.page-title { font-size: 22px; font-weight: 500; margin: 4px 0 20px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--e1);
}
.card + .card { margin-top: 20px; }
.card-title { margin: 0 0 16px; font-size: 16px; font-weight: 500; display: flex; align-items: center; gap: 10px; }
.card-title .icon { color: var(--primary); }
.muted { color: var(--muted); font-size: 13px; }

/* ---- buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 18px; border: none; border-radius: 999px;
  font: 500 14px inherit; cursor: pointer; background: var(--primary); color: #fff;
  transition: background .12s, box-shadow .12s;
}
.btn:hover { background: var(--primary-d); box-shadow: var(--e1); text-decoration: none; }
.btn .icon { width: 18px; height: 18px; }
.btn-block { width: 100%; }
.btn-tonal { background: var(--primary-soft); color: var(--primary-d); }
.btn-tonal:hover { background: #d2e3fc; }
.btn-text { background: transparent; color: var(--primary); padding: 0 12px; }
.btn-text:hover { background: rgba(26,115,232,.08); box-shadow: none; }
.btn-danger { background: transparent; color: var(--bad); padding: 0 12px; }
.btn-danger:hover { background: var(--bad-soft); box-shadow: none; }
.btn-sm { height: 32px; font-size: 13px; padding: 0 14px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none; cursor: pointer;
  background: transparent; color: var(--muted); display: grid; place-items: center;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: rgba(60,64,67,.08); color: var(--ink); }
.icon-btn.danger:hover { background: var(--bad-soft); color: var(--bad); }
.icon-btn.open .icon { transform: rotate(180deg); }
.icon-btn .icon { transition: transform .18s; }

/* ---- forms -------------------------------------------------------------- */
.field { margin-top: 16px; }
.field > label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
input, select {
  width: 100%; height: 44px; padding: 0 14px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; background: var(--surface); color: var(--ink);
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.checkbox-row { display: flex; align-items: center; gap: 10px; margin-top: 16px; color: var(--muted); cursor: pointer; user-select: none; }
.checkbox-row input[type="checkbox"] { width: 18px; height: 18px; margin: 0; flex: 0 0 auto; accent-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; align-items: end; }
.form-grid .field { margin-top: 0; }

/* ---- auth --------------------------------------------------------------- */
.auth-wrap { max-width: 440px; margin: 8vh auto; padding: 24px; }
.auth-card { background: var(--surface); border-radius: 16px; box-shadow: var(--e2); padding: 32px; }
.auth-card h1 { font-size: 22px; font-weight: 500; margin: 0 0 4px; }
.tabs { display: flex; border-bottom: 1px solid var(--line); margin: 18px 0 6px; }
.tab {
  flex: 1; text-align: center; padding: 12px 0; cursor: pointer;
  color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---- dropzone ----------------------------------------------------------- */
.dropzone {
  border: 2px dashed #c6d4ea; border-radius: var(--radius); background: #fafbfe;
  padding: 32px; text-align: center; color: var(--muted);
  transition: background .14s, border-color .14s;
}
.dropzone.drag { background: var(--primary-soft); border-color: var(--primary); }
.dropzone .drop-icon { color: var(--primary); width: 40px; height: 40px; }
.dropzone p { margin: 8px 0 0; }

/* ---- stats -------------------------------------------------------------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.stat-card .v { font-size: 26px; font-weight: 500; letter-spacing: -.02em; }
.stat-card .l { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ---- chips & badges ----------------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
}
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-bad { background: var(--bad-soft); color: var(--bad); }
.chip-muted { background: #f1f3f4; color: var(--muted); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; background: #f1f3f4; color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

/* ---- file list ---------------------------------------------------------- */
.file-list { display: flex; flex-direction: column; }
.file-item { border-bottom: 1px solid var(--line); }
.file-item:last-child { border-bottom: none; }
.file-row { display: flex; align-items: center; gap: 14px; padding: 14px 4px; }
.file-thumb {
  width: 40px; height: 40px; border-radius: 10px; background: var(--primary-soft);
  color: var(--primary); display: grid; place-items: center; flex: 0 0 auto;
}
.file-info { min-width: 0; flex: 1; }
.file-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-sub { display: flex; align-items: center; gap: 10px; margin-top: 3px; }
.file-sub .size { color: var(--muted); font-size: 12px; }
.file-actions { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }

.file-detail { max-height: 0; overflow: hidden; transition: max-height .2s ease; }
.file-detail.open { max-height: 520px; }
.file-detail-inner { padding: 4px 4px 18px 58px; }
.url-box { display: flex; align-items: center; gap: 8px; background: #f6f8fc; border: 1px solid var(--line); border-radius: 8px; padding: 6px 6px 6px 12px; }
.url-box code { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px 24px; margin: 14px 0; }
.detail-grid .k { font-size: 12px; color: var(--muted); }
.detail-grid .v { font-weight: 500; margin-top: 2px; word-break: break-all; }
.detail-actions { display: flex; gap: 8px; margin-top: 8px; }
.empty { text-align: center; color: var(--muted); padding: 36px 0; }

/* ---- tables (admin) ----------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: #f8f9fb; }
td .sub { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }

/* ---- admin shell -------------------------------------------------------- */
.admin-layout { max-width: 1180px; margin: 0 auto; display: flex; gap: 0; align-items: flex-start; }
.sidebar { width: 248px; flex: 0 0 auto; padding: 20px 12px; position: sticky; top: 64px; }
.nav-item {
  display: flex; align-items: center; gap: 16px;
  height: 48px; padding: 0 18px; border-radius: 999px; cursor: pointer;
  color: var(--ink); font-weight: 500; margin-bottom: 4px;
}
.nav-item:hover { background: rgba(60,64,67,.08); text-decoration: none; }
.nav-item.active { background: var(--primary-soft); color: var(--primary-d); }
.nav-item .icon { color: var(--muted); }
.nav-item.active .icon { color: var(--primary-d); }
.content { flex: 1; min-width: 0; padding: 24px; }
.panel-title { font-size: 22px; font-weight: 500; margin: 0 0 18px; }

@media (max-width: 760px) {
  .admin-layout { flex-direction: column; }
  .sidebar { width: 100%; position: static; display: flex; gap: 8px; overflow-x: auto; padding: 12px; }
  .nav-item { margin-bottom: 0; }
  .nav-item span.label { white-space: nowrap; }
}

/* ---- toast -------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: -90px; transform: translateX(-50%);
  background: #323639; color: #fff; padding: 13px 20px; border-radius: 8px;
  font-size: 14px; box-shadow: var(--e2); z-index: 50; transition: bottom .22s ease; max-width: 90vw;
}
.toast.show { bottom: 28px; }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }

.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 28px; }
