* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #0f1115; --bg2: #171a21; --fg: #e8eaf0; --dim: #8b90a0;
  --accent: #c7a24a; --border: #262a35;
  --tabbar-h: 58px;
}
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

/* ---- login ---- */
.login-body { display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 16px;
  padding: 40px 32px; width: min(360px, 90vw); text-align: center;
}
.login-logo { font-size: 48px; }
.login-card h1 { margin: 8px 0 24px; font-size: 28px; letter-spacing: 1px; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); font-size: 16px; margin-bottom: 12px;
}
.login-card button {
  width: 100%; padding: 12px; border-radius: 10px; border: none;
  background: var(--accent); color: #14120a; font-size: 16px; font-weight: 600; cursor: pointer;
}
.login-err { color: #e05c5c; margin-top: 10px; min-height: 1.2em; }

/* ---- shell ---- */
#app { display: flex; flex-direction: column; position: fixed; inset: 0; }
#panels { flex: 1; position: relative; min-height: 0; }
.panel { position: absolute; inset: 0; display: none; }
.panel.active { display: block; }
.panel iframe { width: 100%; height: 100%; border: 0; display: block; background: #000; }

#tabbar {
  order: 2; display: flex; height: var(--tabbar-h);
  background: var(--bg2); border-top: 1px solid var(--border);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; background: none; border: none; color: var(--dim); cursor: pointer; font-size: 11px;
}
.tab .ti { font-size: 20px; line-height: 1; }
.tab .ti-img { width: 21px; height: 21px; border-radius: 5px; object-fit: cover; opacity: 0.55; }
.tab.active .ti-img { opacity: 1; }
.tab .ti-img.fire, .card .ci.fire { border-radius: 50%; }
.card .ci { width: 26px; height: 26px; border-radius: 6px; object-fit: cover; }
.tab.active { color: var(--accent); }

/* desktop: side rail */
@media (min-width: 900px) {
  #app { flex-direction: row; }
  #tabbar {
    order: 0; flex-direction: column; height: auto; width: 88px;
    border-top: none; border-right: 1px solid var(--border); padding: 12px 0;
  }
  .tab { flex: 0 0 64px; font-size: 12px; gap: 4px; }
  .tab .ti { font-size: 24px; }
}

/* ---- home ---- */
.home-wrap { max-width: 720px; margin: 0 auto; padding: 24px 16px; height: 100%; overflow-y: auto; }
.home-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.home-wrap h1 { font-size: 26px; }
.ver {
  background: var(--bg2); border: 1px solid var(--border); color: var(--accent);
  border-radius: 999px; padding: 4px 12px; font-size: 12px; cursor: pointer;
}
.changelog {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 16px; font-size: 13px;
}
.clentry { margin-bottom: 10px; }
.clentry:last-child { margin-bottom: 0; }
.clentry strong { color: var(--accent); }
.clentry span { color: var(--dim); font-size: 11px; margin-left: 6px; }
.clentry ul { margin: 4px 0 0 18px; color: var(--dim); }
.greet { color: var(--dim); font-size: 13px; margin-bottom: 18px; }
.stats-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 2px 8px; }
.stats-head > span:first-child { font-size: 13px; font-weight: 600; color: var(--dim); text-transform: uppercase; letter-spacing: 0.5px; }
.stats-updated { font-size: 11px; color: var(--dim); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
@media (max-width: 480px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 9px 11px; min-width: 0; text-align: left; color: var(--fg); cursor: pointer; }
.stat:hover { border-color: var(--accent); }
.stat.skel { height: 74px; background: linear-gradient(90deg, var(--bg2) 0%, #1e222b 50%, var(--bg2) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.stat-top { display: flex; align-items: baseline; justify-content: space-between; }
.stat-top span { font-size: 15px; }
.stat-top b { font-size: 19px; font-variant-numeric: tabular-nums; }
.stat-top { margin-bottom: 6px; }
.stat small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .stat-label { color: var(--fg); font-size: 11px; font-weight: 600; }
.stat .stat-sub { color: var(--dim); font-size: 10.5px; margin-top: 1px; }
.sync {
  width: 100%; background: var(--bg2); border: 1px solid var(--border); color: var(--fg);
  border-radius: 12px; padding: 11px; font-size: 14px; font-weight: 600; cursor: pointer;
  margin-bottom: 10px;
}
.sync:hover { border-color: var(--accent); }
.sync:disabled { opacity: 0.6; }
.sync-result { color: var(--dim); font-size: 12px; margin-bottom: 12px; line-height: 1.5; }
.recent { margin-top: 6px; }
.recent-strip { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.recent-strip::-webkit-scrollbar { display: none; }
.rcard {
  flex: 0 0 96px; background: none; border: none; padding: 0; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px; color: var(--fg); text-align: left;
}
.rcard img { width: 96px; height: 144px; object-fit: cover; border-radius: 10px; background: var(--bg2); border: 1px solid var(--border); }
.rtitle { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rsub { font-size: 11px; color: var(--dim); }
/* service-down dot on tab */
.tab.svc-down { position: relative; }
.tab.svc-down::after {
  content: ''; position: absolute; top: 6px; right: 50%; transform: translateX(14px);
  width: 7px; height: 7px; border-radius: 50%; background: #e05c5c;
}
.home-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 8px; color: var(--fg); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 13px; font-weight: 600;
}
.card span { font-size: 24px; }
.card:hover { border-color: var(--accent); }
.home-foot { margin-top: 24px; }
.ghost {
  background: none; border: 1px solid var(--border); color: var(--dim);
  padding: 8px 18px; border-radius: 10px; cursor: pointer;
}

/* ---- panes (files/torrents) ---- */
.pane-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--bg2);
}
.pane-actions button {
  background: var(--bg); border: 1px solid var(--border); color: var(--fg);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 15px; margin-left: 6px;
}
#panel-files, #panel-bot { display: none; flex-direction: column; }
#panel-files.active, #panel-bot.active { display: flex; }
.scroll { flex: 1; overflow-y: auto; min-height: 0; }
#crumbs { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; min-width: 0; }
#crumbs select {
  background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 6px; max-width: 40vw;
}
.crumb { background: none; border: none; color: var(--accent); cursor: pointer; padding: 4px 2px; font-size: 14px; }
.file-search { padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--bg2); }
.file-search input {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--fg);
  border-radius: 8px; padding: 7px 10px; font-size: 14px;
}
.frow {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.fico { font-size: 18px; }
.fname { flex: 1; cursor: pointer; overflow-wrap: anywhere; min-width: 0; }
.fmeta { color: var(--dim); font-size: 12px; white-space: nowrap; display: flex; flex-direction: column; align-items: flex-end; }
.fmeta i { font-style: normal; font-size: 10px; opacity: 0.7; }
.facts { display: flex; gap: 2px; }
.facts button { background: none; border: none; color: var(--dim); font-size: 15px; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.facts button:hover { background: var(--bg); color: var(--fg); }
.empty { color: var(--dim); text-align: center; padding: 40px; }
#jobBar {
  padding: 8px 14px; background: var(--bg2); border-top: 1px solid var(--border);
  color: var(--accent); font-size: 13px;
}
.hidden { display: none !important; }

/* torrents */
.trow { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.ttop { display: flex; gap: 8px; align-items: baseline; }
.tname { overflow-wrap: anywhere; font-weight: 600; font-size: 14px; }
.tbar { height: 5px; background: var(--bg2); border-radius: 3px; margin: 8px 0 6px; overflow: hidden; }
.tfill { height: 100%; background: var(--accent); }
.tmeta { color: var(--dim); font-size: 12px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px; }
.tacts button { background: none; border: 1px solid var(--border); color: var(--fg); border-radius: 6px; cursor: pointer; padding: 2px 8px; margin-left: 4px; }

/* bot */
.bot-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--bg2); font-weight: 600; }
.ghost.mini { padding: 4px 12px; font-size: 12px; }
.bot-chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px; border-bottom: 1px solid var(--border); scrollbar-width: none; }
.bot-chips::-webkit-scrollbar { display: none; }
.bot-chips button {
  flex: 0 0 auto; background: var(--bg2); border: 1px solid var(--border); color: var(--fg);
  border-radius: 999px; padding: 6px 12px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.bot-chips button:hover { border-color: var(--accent); }
#botSend.stop { background: #e05c5c; color: #fff; }
#botLog { padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.bmsg { max-width: 85%; padding: 9px 13px; border-radius: 12px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.bmsg.user { align-self: flex-end; background: var(--accent); color: #14120a; }
.bmsg.bot { align-self: flex-start; background: var(--bg2); border: 1px solid var(--border); }
.bmsg.tool { align-self: flex-start; color: var(--dim); font-size: 12px; padding: 2px 6px; }
.bmsg.toolr { align-self: flex-start; color: var(--dim); font-size: 11px; padding: 0 6px 4px 18px; max-height: 5.5em; overflow: hidden; }
.bmsg.err { align-self: flex-start; color: #e05c5c; }
.bmsg.sys { align-self: flex-start; color: var(--dim); }
#botForm {
  display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--bg2);
}
#botForm input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--fg);
  border-radius: 10px; padding: 10px 12px; font-size: 15px;
}
#botForm button {
  background: var(--accent); border: none; color: #14120a; font-weight: 600;
  border-radius: 10px; padding: 0 18px; cursor: pointer;
}

/* ---- placeholders ---- */
.placeholder {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; color: var(--dim);
}
.placeholder span { font-size: 52px; }
.placeholder h2 { color: var(--fg); margin: 12px 0 8px; }
.placeholder p { max-width: 440px; line-height: 1.5; }
