:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #1b1f24; --muted: #5d6673; --border: #e1e4e8;
  --primary: #2459d4; --primary-text: #ffffff; --danger: #c62828; --ok: #1e7d3a; --warn: #a15c00;
  --track: #e8ebf0; --code: #f0f2f5; --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418; --surface: #1a1e24; --text: #e6e9ee; --muted: #9aa3ae; --border: #2c323b;
    --primary: #5b8cff; --primary-text: #0b0e12; --danger: #ff6b6b; --ok: #4cc777; --warn: #f0a640;
    --track: #2a3038; --code: #222831;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #111418; --surface: #1a1e24; --text: #e6e9ee; --muted: #9aa3ae; --border: #2c323b;
    --primary: #5b8cff; --primary-text: #0b0e12; --danger: #ff6b6b; --ok: #4cc777; --warn: #f0a640;
    --track: #2a3038; --code: #222831;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--primary); }
header { background: var(--surface); border-bottom: 1px solid var(--border); }
.bar { max-width: 1280px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; text-decoration: none; color: var(--text); }
.nav { margin-left: auto; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.nav .who { color: var(--muted); }
main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 48px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.card h2 { margin: 0 0 12px; font-size: 17px; }
.narrow { max-width: 420px; margin: 8vh auto 0; }
label { display: block; font-weight: 600; margin: 10px 0 4px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
input[type=text], input[type=password], input[type=file] {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit;
}
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
button, .btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap;
}
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
button.danger { color: var(--danger); }
button:disabled { opacity: .55; cursor: default; }
.btn.small, button.small { padding: 4px 9px; font-size: 13px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > .grow { flex: 1 1 260px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.msg { margin: 10px 0 0; padding: 9px 12px; border-radius: 8px; display: none; }
.msg.show { display: block; }
.msg.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.msg.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
tr.selected td { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid currentColor; }
.badge.queued { color: var(--muted); } .badge.running { color: var(--primary); }
.badge.done { color: var(--ok); } .badge.failed { color: var(--danger); } .badge.cancelled { color: var(--warn); }
.progress { height: 8px; background: var(--track); border-radius: 999px; overflow: hidden; min-width: 120px; }
.progress > span { display: block; height: 100%; background: var(--primary); width: 0; transition: width .4s; }
.stats { display: flex; gap: 18px; flex-wrap: wrap; margin: 10px 0; }
.stat b { display: block; font-size: 20px; }
.stat span { color: var(--muted); font-size: 13px; }
.log { background: var(--code); border-radius: 8px; padding: 10px 12px; max-height: 320px; overflow: auto;
  font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; margin: 0; }
.secret { font: 15px ui-monospace, Menlo, monospace; background: var(--code); padding: 10px 12px; border-radius: 8px;
  user-select: all; word-break: break-all; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
@media (max-width: 640px) { th.opt, td.opt { display: none; } }

/* Form upload: 2 ô + nút thẳng hàng theo đáy, xuống dòng trên mobile */
.upload-grid { display: grid; grid-template-columns: 1.3fr 1fr 1fr auto; gap: 12px 16px; align-items: end; }
.upload-grid .field label { margin-top: 0; }
.upload-grid button { height: 42px; }
.upload-grid input[type=text], .upload-grid input[type=file], .upload-grid select { height: 42px; }
input[type=file] { padding: 5px 6px; cursor: pointer; }
input[type=file]::file-selector-button {
  margin-right: 10px; padding: 5px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.template-box { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; margin-bottom: 16px; border: 1px dashed var(--border); border-radius: 8px; font-size: 14px; }
.card .hint { margin-top: 8px; }
@media (max-width: 760px) { .upload-grid { grid-template-columns: 1fr; } .upload-grid button { width: 100%; justify-content: center; } }

.theme-toggle { min-width: 92px; justify-content: center; }
.theme-corner { position: fixed; top: 12px; right: 16px; }

/* Bảng job: badge, thời gian, nút không xuống dòng; tên file dài tự xuống dòng */
.badge, td.nowrap, .actions .btn, .actions button { white-space: nowrap; }
td.file { min-width: 180px; max-width: 360px; overflow-wrap: anywhere; }
/* Tên file dài: tối đa 2 dòng rồi "…", tên đầy đủ ở tooltip */
td.file a { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
td .actions { flex-wrap: nowrap; }
@media (max-width: 900px) { td .actions { flex-wrap: wrap; } }

select { width: 100%; padding: 0 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  color: var(--text); font: inherit; cursor: pointer; }
select:disabled { opacity: .6; cursor: default; }
.preview-line { min-height: 1.4em; }
.preview-line b { color: var(--text); }
@media (max-width: 1000px) and (min-width: 761px) { .upload-grid { grid-template-columns: 1fr 1fr; } }

/* Kéo file vào bất kỳ đâu trên trang */
.drop-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(2px); pointer-events: none; }
.drop-box { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 48px 64px;
  border: 3px dashed var(--primary); border-radius: 16px; background: var(--surface); color: var(--text); }
.drop-box b { font-size: 1.3rem; color: var(--primary); }
.drop-box span { color: var(--muted); font-size: .9rem; }
td.expiring, td.expiring .hint { color: var(--warn); }
#cleanup-days { width: 120px; }
