/* downloadmanager — standalone staff app for the Studily download portal.
 * Same Studily white/black modern language as apply-admin. */

:root {
  --bg: #FFFFFF;
  --card: #FFFFFF;
  --card-sub: #FAFAFA;
  --border: #E5E5E5;
  --ink: #0A0A0A;
  --ink-secondary: #404040;
  --muted: #737373;
  --subtle: #F5F5F5;
  --danger: #DC2626;
  --danger-bg: #FEF2F2;
  --warn: #B45309;
  --warn-bg: #FFFBEB;
  --ok: #15803D;
  --ok-bg: #F0FDF4;
  --info: #0369A1;
  --info-bg: #F0F9FF;
  --radius: 16px;
  --radius-full: 9999px;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

#app { max-width: 860px; margin: 0 auto; padding: 14px 16px 90px; }
@media (min-width: 1100px) { #app { max-width: 1080px; } }

.loading-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 60vh; gap: 12px;
  color: var(--muted); font-size: 14px; font-weight: 500;
}

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; position: sticky; top: 10px; z-index: 20;
  background: #FFF; border: 1px solid var(--border);
  border-radius: var(--radius-full); box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.topbar img.mark { width: 24px; height: 24px; border-radius: 6px; }
.topbar h1 { font-size: 15.5px; font-weight: 700; letter-spacing: -0.2px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar a.site-link { font-size: 12.5px; font-weight: 700; color: var(--info); text-decoration: none; }
.top-actions { display: flex; align-items: center; gap: 6px; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  margin-bottom: 14px; box-shadow: var(--shadow);
}
.card-title { font-size: 15px; font-weight: 800; letter-spacing: -0.2px; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.card-sub { color: var(--muted); font-size: 13px; margin-bottom: 10px; }

.field { margin-bottom: 12px; }
.field label {
  display: block; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--muted); margin-bottom: 6px;
}
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 14px; font-size: 14px; font-family: inherit;
  background: #FFF; color: var(--ink); outline: none;
  transition: border-color 0.12s ease;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: #000; }
.field textarea { resize: vertical; min-height: 80px; }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.frow { display: flex; gap: 10px; flex-wrap: wrap; }
.frow .field { flex: 1; min-width: 140px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); border-radius: var(--radius-full);
  padding: 11px 20px; font-size: 14px; font-weight: 700;
  font-family: inherit; cursor: pointer; background: #FFF; color: var(--ink);
  transition: all 0.12s ease; text-decoration: none;
}
.btn.primary { background: #0A0A0A; color: #FFF; border-color: #0A0A0A; }
.btn.ghost:hover { background: var(--subtle); }
.btn.danger { color: var(--danger); border-color: rgba(220,38,38,0.3); background: var(--danger-bg); }
.btn.ok { color: var(--ok); border-color: rgba(21,128,61,0.3); background: var(--ok-bg); }
.btn.info { color: var(--info); border-color: rgba(3,105,161,0.3); background: var(--info-bg); }
.btn.sm { padding: 8px 16px; font-size: 13px; }
.btn.xs { padding: 5px 12px; font-size: 12px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn.block { width: 100%; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px; border-radius: var(--radius-full);
  font-size: 11.5px; font-weight: 700;
  background: var(--subtle); border: 1px solid var(--border); color: var(--ink-secondary);
}
.pill.live { background: var(--ok-bg); color: var(--ok); border-color: rgba(21,128,61,0.25); }
.pill.draft { background: var(--warn-bg); color: var(--warn); border-color: rgba(180,83,9,0.25); }
.pill.off { background: var(--subtle); color: var(--muted); }
.pill.role { background: #0A0A0A; color: #FFF; border-color: #0A0A0A; }
.pill.current { background: var(--info-bg); color: var(--info); border-color: rgba(3,105,161,0.3); }

.summary-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.summary-chip {
  flex: 1; min-width: 100px; border: 1px solid var(--border);
  border-radius: 14px; padding: 12px 16px; background: #FFF;
}
.summary-chip .v { font-size: 22px; font-weight: 800; }
.summary-chip .k { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }

.row-card {
  display: flex; gap: 14px; align-items: center;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; background: #FFF;
  box-shadow: var(--shadow);
}
.row-card .info { flex: 1; min-width: 0; }
.row-card .name { font-weight: 700; font-size: 14.5px; word-break: break-word; }
.row-card .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; word-break: break-all; }
.row-card .row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.pgroup {
  font-size: 11.5px; font-weight: 800; letter-spacing: 0.6px; text-transform: uppercase;
  color: var(--muted); margin: 18px 0 8px;
}

.kv { display: flex; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.kv:last-child { border-bottom: 0; }
.kv .k { width: 120px; flex: none; color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.3px; }
.kv .v { flex: 1; min-width: 0; word-break: break-word; }

.actions-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.tab {
  flex: none; padding: 7px 15px; border-radius: var(--radius-full);
  background: var(--subtle); border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 700; color: var(--muted); cursor: pointer;
}
.tab.on { color: #FFF; border-color: #0A0A0A; background: #0A0A0A; }

.back-btn {
  background: var(--subtle); border: 1px solid var(--border);
  border-radius: var(--radius-full); color: var(--ink);
  font-weight: 700; font-size: 13.5px; cursor: pointer; padding: 6px 14px;
}
.back-btn:hover { background: #E5E5E5; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #0A0A0A; border: 1px solid #262626; color: #FFF;
  padding: 10px 20px; border-radius: var(--radius-full);
  font-size: 13px; font-weight: 600; z-index: 1000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25); white-space: nowrap;
  max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
.err { color: var(--danger); font-size: 12.5px; font-weight: 600; margin-top: 6px; }
.center { text-align: center; }
.login-wrap { max-width: 380px; margin: 8vh auto 0; }
.login-logo { width: 110px; display: block; margin: 0 auto 14px; }
.owner-tag { font-size: 11px; font-weight: 800; letter-spacing: 0.6px; color: #FFF; background: #0A0A0A; border-radius: var(--radius-full); padding: 3px 10px; }
img.emj { vertical-align: -3px; }

/* ─── Side menu (wide = pinned rail, narrow = slide-over drawer) ──────────── */
.gwrap { position: relative; }
.gmain { min-width: 0; }
.gside { display: none; }
.gside-head {
  font-weight: 800; font-size: 11.5px; letter-spacing: 0.6px;
  text-transform: uppercase; color: var(--muted); padding: 6px 10px 12px;
}
.gside-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px;
  font-size: 13.5px; font-weight: 600; color: var(--ink-secondary);
  cursor: pointer; transition: all 0.12s ease; margin-bottom: 2px;
}
.gside-item:hover { background: var(--subtle); color: var(--ink); }
.gside-item.on { background: #0A0A0A; color: #FFF; }
.gside-item .gi { width: 20px; text-align: center; flex: none; display: inline-flex; justify-content: center; }
.gside-backdrop { display: none; }
.menu-fab {
  position: fixed; left: 14px; bottom: 18px; z-index: 40;
  background: #0A0A0A; color: #FFF; border: 0;
  border-radius: var(--radius-full); padding: 11px 18px;
  font-weight: 700; font-size: 13px; font-family: inherit;
  box-shadow: 0 6px 20px rgba(0,0,0,0.28); cursor: pointer;
}
.menu-fab:active { transform: scale(0.96); }

@media (min-width: 900px) {
  .gwrap { display: flex; gap: 16px; align-items: flex-start; }
  .gside {
    display: block; width: 220px; flex: none;
    position: sticky; top: 80px;
    background: #FFF; border: 1px solid var(--border);
    border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow);
  }
  .gmain { flex: 1; min-width: 0; }
  .menu-fab { display: none; }
}

@media (max-width: 899px) {
  .gside {
    display: block; position: fixed; top: 0; left: 0; bottom: 0;
    width: 256px; z-index: 60; background: #FFF;
    border-right: 1px solid var(--border); padding: 18px 12px;
    overflow-y: auto; transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .gside.open { transform: none; box-shadow: 10px 0 40px rgba(0,0,0,0.18); }
  .gside-backdrop.open {
    display: block; position: fixed; inset: 0;
    background: rgba(0,0,0,0.32); z-index: 55;
  }
}

/* ─── Rich text editor ──────────────────────────────────────────────────── */
.editor { border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.editor-bar {
  display: flex; gap: 4px; flex-wrap: wrap;
  padding: 8px; background: var(--card-sub); border-bottom: 1px solid var(--border);
}
.editor-bar button {
  border: 1px solid transparent; background: transparent; border-radius: 8px;
  min-width: 32px; height: 32px; padding: 0 9px;
  font-size: 13px; font-weight: 700; font-family: inherit;
  cursor: pointer; color: var(--ink-secondary);
}
.editor-bar button:hover { background: #ECECEC; color: var(--ink); }
.editor-bar button.on { background: #0A0A0A; color: #FFF; }
.editor-bar .sep { width: 1px; background: var(--border); margin: 4px 4px; }
.editor-body {
  min-height: 220px; padding: 16px; font-size: 14.5px; line-height: 1.65;
  outline: none; background: #FFF;
}
.editor-body:empty::before { content: attr(data-ph); color: #B0B0B0; }
.editor-body h2 { font-size: 20px; margin: 14px 0 6px; }
.editor-body h3 { font-size: 16.5px; margin: 12px 0 4px; }
.editor-body p { margin: 8px 0; }
.editor-body blockquote { border-left: 3px solid var(--border); padding-left: 14px; color: var(--ink-secondary); margin: 10px 0; }
.editor-body pre, .editor-body code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--subtle); border-radius: 6px; }
.editor-body code { padding: 1px 6px; font-size: 13px; }
.editor-body pre { padding: 12px 14px; overflow-x: auto; font-size: 13px; }
.editor-body pre code { padding: 0; background: none; }
.editor-body ul, .editor-body ol { padding-left: 22px; margin: 8px 0; }
.editor-body img { max-width: 100%; border-radius: 10px; }
.editor-src {
  width: 100%; min-height: 220px; border: 0; padding: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
  outline: none; resize: vertical; background: #FFF; color: var(--ink);
}
.preview-box {
  border: 1px dashed var(--border); border-radius: 14px; padding: 18px;
  margin-top: 12px; background: var(--card-sub); font-size: 14.5px; line-height: 1.65;
}
.preview-box h2 { font-size: 20px; margin: 14px 0 6px; }
.preview-box h3 { font-size: 16.5px; margin: 12px 0 4px; }
.preview-box blockquote { border-left: 3px solid var(--border); padding-left: 14px; color: var(--ink-secondary); margin: 10px 0; }
.preview-box pre, .preview-box code { font-family: ui-monospace, monospace; background: #EFEFEF; border-radius: 6px; }
.preview-box code { padding: 1px 6px; font-size: 13px; }
.preview-box pre { padding: 12px 14px; overflow-x: auto; }
.preview-box pre code { padding: 0; background: none; }
.preview-box img { max-width: 100%; border-radius: 10px; }

/* ─── Upload drop zone ──────────────────────────────────────────────────── */
.upl {
  border: 2px dashed var(--border); border-radius: 14px; padding: 18px;
  text-align: center; color: var(--muted); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.12s ease; margin-bottom: 10px;
}
.upl:hover, .upl.over { border-color: #0A0A0A; color: var(--ink); background: var(--card-sub); }
.upl .big { font-size: 22px; margin-bottom: 4px; }
.upl-prog { height: 6px; border-radius: 99px; background: var(--subtle); overflow: hidden; margin-top: 10px; }
.upl-prog i { display: block; height: 100%; background: #0A0A0A; border-radius: 99px; transition: width 0.2s ease; }

/* ─── History feed ──────────────────────────────────────────────────────── */
.evt {
  display: flex; gap: 12px; padding: 11px 4px;
  border-bottom: 1px solid var(--border); font-size: 13.5px;
}
.evt:last-child { border-bottom: 0; }
.evt .dot {
  width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex: none;
  background: var(--muted);
}
.evt .dot.CREATE { background: var(--ok); }
.evt .dot.UPDATE { background: var(--info); }
.evt .dot.DELETE { background: var(--danger); }
.evt .dot.PUBLISH { background: var(--ok); }
.evt .dot.UNPUBLISH { background: var(--warn); }
.evt .dot.SET_CURRENT { background: #0A0A0A; }
.evt .body { flex: 1; min-width: 0; }
.evt .what { font-weight: 600; }
.evt .what .act { font-size: 10.5px; font-weight: 800; letter-spacing: 0.5px; color: var(--muted); text-transform: uppercase; margin-right: 6px; }
.evt .who { color: var(--muted); font-size: 12px; margin-top: 2px; }

.icon { display: inline-flex; vertical-align: -4px; }
.icon svg { display: block; }
