:root {
  --bg: #0e1013;
  --panel: #15181d;
  --panel-2: #1b1f26;
  --line: #262b34;
  --text: #e7e9ee;
  --muted: #8b93a3;
  --accent: #ff7a3d;
  --accent-soft: rgba(255, 122, 61, .14);
  --ok: #3ecf8e;
  --warn: #f5b84a;
  --bad: #ff5d6c;
  --info: #6aa8ff;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  background: var(--panel-2); padding: 7px 12px; border-radius: 8px; white-space: nowrap;
}
.btn:hover { border-color: #3a4150; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a0d05; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label { display: block; font-size: 12.5px; color: var(--muted); margin: 10px 0 4px; }

/* layout */
.app { display: grid; grid-template-columns: 1fr 400px; height: 100vh; }
.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 12px 22px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .2px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #ffb36b);
  display: grid; place-items: center; color: #1a0d05; font-weight: 800;
}
.stats { display: flex; gap: 18px; margin-left: 12px; }
.stat { font-size: 12.5px; color: var(--muted); }
.stat b { color: var(--text); font-weight: 600; margin-right: 4px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(62, 207, 142, .15); }
.dot.busy { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 10px; color: var(--muted); }

.tabs { display: flex; gap: 2px; padding: 0 22px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab {
  background: none; border: 0; padding: 12px 14px; color: var(--muted); border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab .count { background: var(--panel-2); border-radius: 10px; padding: 1px 7px; font-size: 11.5px; margin-left: 6px; }
.tab .count.alert { background: var(--accent); color: #1a0d05; }
.content { flex: 1; overflow: auto; padding: 20px 22px 40px; }
.section-head { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; flex-wrap: wrap; }
.section-head h2 { font-size: 16px; margin: 0; }
.section-head .filters { display: flex; gap: 8px; margin-left: auto; }
.section-head select, .section-head input { width: auto; min-width: 160px; padding: 6px 10px; }

/* now rendering strip */
.now { padding: 14px 22px; border-bottom: 1px solid var(--line); background: var(--panel); }
.now-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin-bottom: 10px; }
.now-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 10px; }
.now-empty { color: var(--muted); font-size: 13px; }
.job-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 13px; }
.job-card .row { display: flex; align-items: baseline; gap: 8px; }
.job-card .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-card .timer { margin-left: auto; font-family: var(--mono); font-size: 15px; color: var(--accent); }
.job-card .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bar { height: 5px; background: var(--bg); border-radius: 3px; overflow: hidden; margin: 9px 0 6px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #ffb36b); transition: width .6s; }
.bar.queued > i { background: var(--line); }

/* render grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.tile .thumb {
  aspect-ratio: 16/10; background: #0a0b0d center/cover no-repeat; display: grid; place-items: center;
  color: var(--muted); font-size: 12px; font-family: var(--mono); cursor: pointer; border: 0; width: 100%;
}
.tile .body { padding: 9px 11px 11px; display: flex; flex-direction: column; gap: 2px; }
.tile .title { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .sub { font-size: 12px; color: var(--muted); }
.tile .actions { display: flex; gap: 6px; margin-top: 8px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:hover td { background: rgba(255, 255, 255, .015); }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; text-transform: capitalize; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status.running::before, .status.assigned::before { background: var(--accent); }
.status.done::before { background: var(--ok); }
.status.failed::before, .status.rejected::before { background: var(--bad); }
.status.pending_approval::before { background: var(--warn); }
.status.queued::before { background: var(--info); }
.mini-bar { width: 110px; height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 8px; }
.mini-bar > i { display: block; height: 100%; background: var(--accent); }

/* dropzone */
.drop {
  border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted);
  margin-bottom: 16px; transition: .15s;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.drop .row { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.drop input[type=text] { width: 200px; }
.upload-progress { font-size: 12px; margin-top: 8px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h3 { margin: 0 0 10px; font-size: 14px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.copy-box { display: flex; gap: 8px; margin-top: 10px; }
.copy-box input { font-family: var(--mono); font-size: 12px; }
.empty { color: var(--muted); padding: 30px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

/* chat */
.chat { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, #2b313c, #1b1f26); display: grid; place-items: center; font-weight: 700; color: var(--accent); border: 1px solid var(--line); flex: none; }
.chat-head .who { line-height: 1.2; }
.chat-head .who small { color: var(--muted); font-size: 12px; }
.chat-head select { width: auto; max-width: 150px; margin-left: auto; padding: 5px 8px; font-size: 12.5px; }
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent-soft); border: 1px solid rgba(255, 122, 61, .25); border-bottom-right-radius: 4px; }
.msg.kobe { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.system { align-self: center; background: none; color: var(--muted); font-size: 12px; text-align: center; padding: 2px 8px; max-width: 95%; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin: 0; }
.msg ul, .msg ol { margin: 4px 0 6px; padding-left: 18px; }
.msg code { overflow-wrap: anywhere; font-family: var(--mono); font-size: 12.5px; background: rgba(0, 0, 0, .3); padding: 1px 4px; border-radius: 4px; }
.msg pre { background: rgba(0, 0, 0, .35); padding: 8px; border-radius: 6px; overflow-x: auto; }
.msg .time { font-size: 11px; color: var(--muted); margin-top: 4px; }
.attach { display: flex; align-items: center; gap: 8px; margin-top: 7px; padding: 7px 9px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font-size: 12.5px; }
.attach img { width: 44px; height: 30px; object-fit: cover; border-radius: 4px; }
.attach .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.typing { padding: 0 14px 6px; font-size: 12px; color: var(--muted); min-height: 20px; }
.typing .dots::after { content: ""; animation: dots 1.4s infinite steps(4); }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.composer { border-top: 1px solid var(--line); padding: 10px; }
.composer .pending-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.composer .row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 40px; max-height: 160px; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); padding: 20px; }
.chat-empty .suggest { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.chat-toggle { display: none; }

/* lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .86); display: grid; place-items: center; z-index: 50; padding: 30px; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 82vh; border-radius: 6px; }
.lightbox .cap { color: var(--muted); margin-top: 10px; text-align: center; }
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal .card { width: min(520px, 100%); max-height: 90vh; overflow: auto; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); padding: 9px 14px; border-radius: 8px; z-index: 60; }

/* login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px; }
.auth h1 { font-size: 18px; margin: 14px 0 4px; }
.auth .err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }
.auth .btn { width: 100%; justify-content: center; margin-top: 16px; padding: 10px; }

@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; }
  .chat { position: fixed; inset: 0; z-index: 30; border: 0; }
  .chat.closed { display: none; }
  .chat-toggle { display: inline-flex; position: fixed; right: 16px; bottom: 16px; z-index: 31; border-radius: 30px; padding: 11px 16px; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); }
  .chat-close { display: inline-flex !important; }
  .chat-toggle.chat-open { display: none; }
  .stats { display: none; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .topbar, .tabs, .content, .now { padding-left: 16px; padding-right: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .section-head .filters { margin-left: 0; width: 100%; }
  .section-head select, .section-head input { min-width: 0; flex: 1; }
}
