/*
  Deploy Portal v1.5.0 (2026-10-19)
  - v1.5.0: ปุ่มแถวที่สองในการ์ด (.actions-danger: ล้างไฟล์ / ลบโฟลเดอร์), .btn.danger-soft
  - v1.4.0: ช่องกรอกที่ผิดตอนล็อกอิน (input.invalid)
  - v1.3.0: ปุ่มหยุด (.btn.warn), ฟอร์มสร้างโฟลเดอร์ (.page-head, .new-folder), .sr-only
  - v1.2.0: โลโก้ลูกศรอัปโหลดใน .brand, รายการไฟล์แบบพับได้ (.files, .file-item), แผงถังขยะ, .warn-note
  - v1.1.0: สไตล์รายการไฟล์ที่อัปโหลด (.uploads, .upload-item) และเวอร์ชันที่ topbar (.version)
  - v1.0.0: เวอร์ชันแรก
*/
:root {
  --bg-top: #f5f3ff;
  --bg-bottom: #ffffff;
  --card: #ffffff;
  --tile: #f1edfd;
  --field: #f6f3ff;
  --line: #e4dcf7;

  --ink: #2e1065;
  --ink-2: #4c1d95;
  --muted: #6b6488;

  --grad: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  --violet: #7c3aed;
  --indigo: #4338ca;
  --focus: #8b5cf6;

  --green: #16a34a;
  --green-bg: #dcfce7;
  --green-ink: #15803d;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --red-ink: #b91c1c;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --amber-ink: #b45309;

  --icon-upload: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 15V3M7 8l5-5 5 5M4 15v3a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-3'/%3E%3C/svg%3E");
  --shadow: 0 1px 2px rgba(76, 29, 149, .06), 0 8px 22px rgba(76, 29, 149, .07);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Sarabun", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  background: linear-gradient(180deg, var(--bg-top) 0, #fbfaff 480px, var(--bg-bottom) 100%) fixed;
}

h1, h2 { margin: 0; font-weight: 700; }
h2 { font-size: 15px; }
code { font-family: var(--mono); background: var(--tile); color: var(--ink-2); padding: 1px 6px; border-radius: 6px; }
p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red-ink); background: var(--red-bg); padding: 8px 12px; border-radius: 10px; font-size: 14px; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

/* ---------- brand mark ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.brand::before {
  content: "";
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--icon-upload) center / 20px no-repeat, var(--grad);
  box-shadow: 0 4px 12px rgba(99, 102, 241, .35);
}

/* ---------- buttons / fields ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-2);
  cursor: pointer;
  transition: background .12s, box-shadow .12s, filter .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: var(--tile); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible, .dropzone:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.btn.pill { border-radius: 999px; }
.btn.small { padding: 4px 12px; font-size: 13px; }

.btn.primary {
  color: #fff;
  border-color: transparent;
  background: var(--grad);
  box-shadow: 0 4px 12px rgba(99, 102, 241, .35);
}
.btn.primary:hover:not(:disabled) { background: var(--grad); filter: brightness(1.07); }
.btn.primary:disabled { box-shadow: none; }

.btn.danger {
  color: var(--red-ink);
  background: var(--red-bg);
  border-color: transparent;
}
.btn.danger:hover:not(:disabled) { background: #fecaca; }

.btn.danger-soft { color: var(--red-ink); background: #fff; border-color: #fecaca; }
.btn.danger-soft:hover:not(:disabled) { background: var(--red-bg); }

.btn.ghost { background: transparent; }

.btn.warn {
  color: var(--amber-ink);
  background: var(--amber-bg);
  border-color: transparent;
}
.btn.warn:hover:not(:disabled) { background: #fde68a; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

input[type="text"], input[type="password"], select {
  width: 100%;
  font: inherit;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
}
input.invalid { border-color: var(--red); background: var(--red-bg); }
input[type="checkbox"] { accent-color: var(--violet); width: 16px; height: 16px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.topbar-right { display: flex; align-items: center; gap: 10px; }

.chip {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.chip.ok { background: var(--green-bg); color: var(--green-ink); }
.version { font: 12px var(--mono); color: var(--muted); }

/* ---------- page ---------- */
.content { max-width: 1040px; margin: 0 auto; padding: 24px 16px 56px; display: grid; gap: 16px; }
.page-title { font-size: 26px; color: var(--ink-2); }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px 16px; }
.new-folder { display: flex; gap: 8px; flex: 0 1 420px; }
.new-folder input { flex: 1; min-width: 0; font-family: var(--mono); }
.new-folder .btn { white-space: nowrap; }

.toolbar { padding: 12px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; }
.toolbar select { width: auto; max-width: 100%; }
.toolbar p { flex-basis: 100%; }
.inline { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.inline.check { gap: 8px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }

/* ---------- folder cards ---------- */
.card {
  --accent: #c4b5fd;
  padding: 16px;
  display: grid;
  gap: 12px;
  align-content: start;
  border-left: 5px solid var(--accent);
  border-radius: 14px;
}
.card.s-run { --accent: var(--green); }
.card.s-stop { --accent: var(--red); }
.card.s-warn { --accent: var(--amber); }

.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card .name { font-size: 18px; color: var(--ink-2); overflow-wrap: anywhere; }
.card .meta { color: var(--muted); font-size: 13px; }

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 11px;
  border-radius: 999px;
  white-space: nowrap;
  background: var(--tile);
  color: var(--muted);
}
.badge.run { background: var(--green-bg); color: var(--green-ink); }
.badge.stop { background: var(--red-bg); color: var(--red-ink); }
.badge.warn { background: var(--amber-bg); color: var(--amber-ink); }

.dropzone {
  border: 1.5px dashed #c4b5fd;
  border-radius: 12px;
  padding: 18px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  background: #faf8ff;
  cursor: pointer;
  transition: border-color .12s, background .12s, color .12s;
}
.dropzone:hover, .dropzone.over { border-color: var(--violet); background: var(--tile); color: var(--ink-2); }
.card.busy .dropzone { pointer-events: none; opacity: .5; }

.progress { height: 8px; background: var(--tile); border-radius: 999px; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--grad); border-radius: 999px; transition: width .1s linear; }
.progress.indeterminate .bar { width: 40% !important; animation: slide 1s ease-in-out infinite alternate; }
@keyframes slide { from { margin-left: 0; } to { margin-left: 60%; } }
.ptxt { font-size: 13px; color: var(--muted); }

.actions { display: flex; gap: 8px; }
.actions .btn.primary { flex: 1; }
.actions-danger { margin-top: -4px; }
.actions-danger .btn { flex: 1; }

/* ---------- file lists: server files, uploaded zips, trash ---------- */
.files { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 8px; }
.files-head {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
}
.files-head::-webkit-details-marker { display: none; }
.files-head::before { content: "▸"; color: var(--muted); transition: transform .12s; }
.files[open] > .files-head::before { transform: rotate(90deg); }
.files-head .count { font-size: 12px; padding: 0 8px; border-radius: 999px; background: var(--tile); color: var(--muted); }
.files-head:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.files-path { font: 12px var(--mono); color: var(--muted); overflow-wrap: anywhere; }

.file-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 232px; overflow: auto; scrollbar-width: thin; }
.file-list.tall { max-height: 360px; }
.file-item { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 10px; border-radius: 10px; background: var(--tile); }
.file-info { flex: 1; min-width: 0; display: grid; }
.file-name { font-size: 13px; font-weight: 600; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 12px; color: var(--muted); }

.file-icon { flex: none; width: 18px; height: 18px; background: var(--muted); -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat; }
.file-icon.file { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 3v5h5'/%3E%3C/svg%3E"); }
.file-icon.dir { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z'/%3E%3C/svg%3E"); background: var(--amber); }
.file-icon.zip { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M11 5h2M11 9h2M11 13h2v3h-2z'/%3E%3C/svg%3E"); background: var(--violet); }

.trash-panel { padding: 14px 16px 16px; display: grid; gap: 4px; }
.head-actions { display: flex; gap: 8px; flex: none; }
.warn-note { color: var(--amber-ink); background: var(--amber-bg); padding: 8px 12px; border-radius: 10px; font-size: 13px; }

/* ---------- output log ---------- */
.log-panel { padding: 14px 16px 16px; }
.log-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 12px; margin-bottom: 10px; }
.log-head > div:first-child { flex: 1 1 260px; min-width: 0; overflow-wrap: anywhere; }
.log-head h2 { color: var(--ink-2); }
#log {
  margin: 0;
  min-height: 120px;
  max-height: 360px;
  overflow: auto;
  padding: 10px 12px;
  border-radius: 12px;
  background: #faf8ff;
  border: 1px solid var(--line);
  font: 13px/1.55 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #3b3358;
  scrollbar-width: thin;
  scrollbar-color: #c4b5fd transparent;
}
#log .ok { color: var(--green-ink); }
#log .err { color: var(--red-ink); }
#log .info { color: var(--indigo); }
#log .ts { color: var(--muted); }

/* ---------- dialog ---------- */
dialog {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(46, 16, 101, .25);
  padding: 0;
  max-width: 440px;
  width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(46, 16, 101, .35); }
.dialog-body { padding: 22px; display: grid; gap: 12px; }
.dialog-body h2 { font-size: 18px; color: var(--ink-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

@media (max-width: 520px) {
  .topbar { padding: 10px 14px; }
  .page-title { font-size: 22px; }
  .toolbar select { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .progress.indeterminate .bar { animation: none; }
  * { transition: none !important; }
}