/* NimbusJoy Portal — dark, fast, phone-first */
:root {
  --page: #0d0d0f;
  --surface: #17171b;
  --surface-2: #1f1f25;
  --line: #2b2b33;
  --ink: #ffffff;
  --ink-2: #c3c2c9;
  --ink-3: #8a8891;
  --accent: #38c8e8;
  --accent-ink: #082830;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --radius: 16px;
  --sab: env(safe-area-inset-bottom, 0px);
  --sat: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 22px; height: 22px; display: block; }

/* ---------------- login ---------------- */
.login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 90% at 50% 0%, #14202b 0%, var(--page) 60%);
  padding: 24px; z-index: 50;
}
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-logo { width: 76px; height: 76px; border-radius: 20px; margin-bottom: 14px; }
.login h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -0.02em; }
.login-sub { margin: 0 0 26px; color: var(--ink-3); }
.login input {
  width: 100%; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 16px; outline: none; margin-bottom: 12px;
}
.login input:focus { border-color: var(--accent); }
.login-err { color: var(--serious); min-height: 20px; margin: 12px 0 0; font-size: 13px; }

.btn-primary, .btn-secondary {
  width: 100%; padding: 14px 16px; border-radius: 14px; font-size: 16px; font-weight: 600;
  transition: transform .08s ease, opacity .15s;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.btn-primary:active, .btn-secondary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .5; }

/* ---------------- shell ---------------- */
.app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.view { position: absolute; inset: 0 0 calc(60px + var(--sab)); display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--sat)) 14px 10px;
  background: rgba(13,13,15,.86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line); z-index: 5;
}
.topbar-col { flex-direction: column; align-items: stretch; gap: 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; flex: 1; min-width: 0; }
.brand img { width: 24px; height: 24px; border-radius: 7px; }
.icon-btn {
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  border-radius: 12px; color: var(--ink-2); flex: none;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.dim { color: var(--ink-3); }
.icon-btn.on { color: var(--accent); }

/* ---------------- tab bar ---------------- */
.tabbar {
  position: absolute; left: 0; right: 0; bottom: 0; height: calc(60px + var(--sab));
  padding-bottom: var(--sab);
  display: flex; background: rgba(16,16,20,.92); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); z-index: 10;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-3); font-size: 11px; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }

/* ---------------- chat ---------------- */
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  padding: 6px 12px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2);
  font-size: 12.5px; font-weight: 600; white-space: nowrap; border: 1px solid var(--line);
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.chat-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.chat-list { display: flex; flex-direction: column; gap: 10px; padding: 16px 14px 10px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px; }
.msg.bot  { align-self: flex-start; background: var(--surface-2); color: var(--ink); border-bottom-left-radius: 5px; }
.msg.err  { align-self: flex-start; background: rgba(208,59,59,.14); border: 1px solid rgba(208,59,59,.4); color: #f1b7b7; border-bottom-left-radius: 5px; }
.msg .meta { display: block; margin-top: 6px; font-size: 11px; color: var(--ink-3); }
.msg.user .meta { color: rgba(8,40,48,.65); }
.msg pre {
  background: rgba(0,0,0,.35); padding: 10px; border-radius: 10px; overflow-x: auto;
  font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; margin: 8px 0; white-space: pre;
}
.msg code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: rgba(0,0,0,.3); padding: 1px 5px; border-radius: 5px; }
.msg a { color: inherit; text-decoration: underline; }
.msg .att { display: inline-flex; align-items: center; gap: 6px; background: rgba(0,0,0,.18); border-radius: 9px; padding: 4px 9px; margin: 2px 4px 2px 0; font-size: 12.5px; }

.typing { align-self: flex-start; display: flex; gap: 5px; padding: 14px 16px; background: var(--surface-2); border-radius: 18px; border-bottom-left-radius: 5px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .25 } 40% { opacity: 1 } }

.chat-input-bar {
  padding: 8px 10px calc(10px); background: rgba(13,13,15,.9); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.chat-input-row { display: flex; align-items: flex-end; gap: 8px; }
#chatText {
  flex: 1; resize: none; max-height: 120px; padding: 11px 14px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 16px/1.4 inherit; outline: none;
}
#chatText:focus { border-color: var(--accent); }
.send-btn {
  width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; flex: none; transition: transform .08s;
}
.send-btn:active { transform: scale(.92); }
.send-btn svg { width: 20px; height: 20px; }
.attach-preview { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 4px 8px; }
.attach-pill { display: flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; font-size: 12.5px; color: var(--ink-2); }
.attach-pill b { color: var(--ink); font-weight: 600; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-pill button { color: var(--ink-3); font-size: 15px; line-height: 1; }

/* ---------------- files ---------------- */
.files-top .crumb {
  flex: 1; min-width: 0; font-weight: 600; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left;
}
.quickrow { display: flex; gap: 8px; padding: 10px 14px 4px; overflow-x: auto; scrollbar-width: none; }
.quickrow::-webkit-scrollbar { display: none; }
.qchip { padding: 7px 13px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.qchip:active { background: var(--surface-2); }

.files-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 10px 90px; }
.file-list { display: flex; flex-direction: column; gap: 2px; }
.frow {
  display: flex; align-items: center; gap: 12px; padding: 9px 8px; border-radius: 12px; width: 100%; text-align: left;
}
.frow:active { background: var(--surface); }
.ficon {
  width: 42px; height: 42px; border-radius: 10px; flex: none; display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--ink-3); overflow: hidden;
}
.ficon.folder { color: var(--accent); }
.ficon img { width: 100%; height: 100%; object-fit: cover; }
.fmeta { flex: 1; min-width: 0; }
.fname { font-weight: 500; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fsub { font-size: 12px; color: var(--ink-3); margin-top: 1px; }
.fmore { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; color: var(--ink-3); border-radius: 10px; flex: none; }
.fmore:active { background: var(--surface-2); }
.empty { text-align: center; color: var(--ink-3); padding: 60px 20px; font-size: 14px; }
.skeleton { height: 52px; border-radius: 12px; background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.1s infinite; margin-bottom: 6px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.fab {
  position: absolute; right: 18px; bottom: calc(78px + var(--sab)); width: 56px; height: 56px; border-radius: 18px;
  background: var(--accent); color: var(--accent-ink); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(56,200,232,.35); transition: transform .1s; z-index: 6;
}
.fab:active { transform: scale(.92); }
.fab svg { width: 24px; height: 24px; }
.fab.off { opacity: .35; pointer-events: none; box-shadow: none; }

/* ---------------- sheets ---------------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; opacity: 1; transition: opacity .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  background: var(--surface); border-radius: 20px 20px 0 0; border-top: 1px solid var(--line);
  padding: 10px 16px calc(20px + var(--sab));
  transform: translateY(0); transition: transform .22s ease;
  max-height: 80vh; overflow-y: auto;
}
.sheet .grab { width: 40px; height: 4px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.sheet h3 { margin: 0 0 2px; font-size: 16px; word-break: break-all; }
.sheet .sub { color: var(--ink-3); font-size: 12.5px; margin-bottom: 14px; }
.sheet-act {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 6px; border-radius: 12px;
  font-size: 15px; font-weight: 500; text-align: left;
}
.sheet-act:active { background: var(--surface-2); }
.sheet-act svg { color: var(--ink-3); }
.sheet-act.danger { color: #f1a1a1; }
.sheet-act.danger svg { color: var(--critical); }
.sheet-img { width: 100%; max-height: 260px; object-fit: contain; border-radius: 12px; margin-bottom: 12px; background: var(--page); }
.sheet pre { background: var(--page); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font: 12px/1.45 ui-monospace, Menlo, monospace; overflow: auto; max-height: 320px; white-space: pre-wrap; word-break: break-word; }

/* ---------------- send tab ---------------- */
.send-scroll { flex: 1; overflow-y: auto; padding: 16px 14px 40px; display: flex; flex-direction: column; gap: 14px; }
.send-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.send-card-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.send-emoji { font-size: 26px; line-height: 1.2; }
.send-card h2 { margin: 0; font-size: 16.5px; }
.send-card p { margin: 3px 0 0; color: var(--ink-3); font-size: 13px; }
.dest-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.dest-chip { padding: 8px 13px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); font-size: 13px; font-weight: 600; }
.dest-chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.upload-log { display: flex; flex-direction: column; gap: 8px; }
.up-item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.up-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.up-bar { height: 4px; border-radius: 3px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.up-bar i { display: block; height: 100%; width: 0%; background: var(--accent); border-radius: 3px; transition: width .15s; }
.up-item.done .up-bar i { background: var(--good); }
.up-item.fail .up-bar i { background: var(--critical); width: 100% !important; }

/* ---------------- status ---------------- */
.status-scroll { flex: 1; overflow-y: auto; padding: 16px 14px 40px; }
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat.wide { grid-column: 1 / -1; }
.stat .label { font-size: 12px; color: var(--ink-3); font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 5px; letter-spacing: -0.02em; }
.stat .sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.meter { height: 6px; border-radius: 4px; background: var(--surface-2); margin-top: 10px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.meter i.warn { background: var(--warning); }
.meter i.crit { background: var(--critical); }
.badge { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 600; margin-top: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.good { background: var(--good); } .dot.bad { background: var(--critical); } .dot.unk { background: var(--ink-3); }
.plat-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.plat { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center; }

/* ---------------- push card ---------------- */
.push-card { margin-bottom: 10px; }
.push-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.push-row .value { font-size: 17px; font-weight: 700; margin: 0; flex: 1; }
.push-btn {
  padding: 9px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  background: var(--accent); color: var(--accent-ink); flex: none;
}
.push-btn.ghost { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.push-btn:active { transform: scale(.95); }
.push-btn:disabled { opacity: .45; }
.push-note { font-size: 12.5px; color: var(--ink-3); margin-top: 9px; line-height: 1.5; }

/* ---------------- misc ---------------- */
.img-viewer { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.95); display: flex; align-items: center; justify-content: center; }
.img-viewer img { max-width: 100%; max-height: 100%; }
.img-close { position: absolute; top: calc(14px + var(--sat)); right: 14px; width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.12); color: #fff; font-size: 17px; }
.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--sab)); transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink);
  padding: 10px 18px; border-radius: 999px; font-size: 13.5px; font-weight: 500; z-index: 40;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: 88vw; text-align: center;
}
@media (min-width: 760px) {
  .chat-list, .send-scroll, .status-scroll { max-width: 720px; margin: 0 auto; width: 100%; }
  .files-scroll .file-list { max-width: 720px; margin: 0 auto; }
}
