/* ==========================================================================
   FREEDOM SCUM SERVER — Dark Tactical / Military Gaming theme
   ใช้ร่วมกันทั้งหน้า login และ dashboard
   ========================================================================== */

:root {
  --bg: #08090c;
  --bg-grid: rgba(255, 255, 255, .035);
  --panel: #0e1116;
  --panel-soft: rgba(255, 255, 255, .02);
  --border: #1d222b;
  --border-strong: #2a3140;
  --input-bg: #0b0d11;
  --red-deep: #b51220;
  --red-deep-2: #7c0c16;
  --btn-grad-1: #b51220;
  --btn-grad-2: #7c0c16;
  --red-neon: #ff2a3c;
  --red-glow: rgba(255, 42, 60, .5);
  --red-glow-soft: rgba(255, 42, 60, .2);
  --accent-wash: rgba(181, 18, 32, .18);
  --accent-wash-border: rgba(255, 42, 60, .4);
  --silver: #cbd1da;
  --silver-dim: #838b97;
  --ink: #eef0f3;
  --ink-dim: #8a929e;
  --navy: #0b1424;
  --navy-border: #17233a;
  --green: #35e07f;
  --green-glow: rgba(53, 224, 127, .55);
  --radius: 10px;
  --radius-lg: 16px;
  --font: "Chakra Petch", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background-color: var(--bg);
  color: var(--ink);
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px),
    radial-gradient(ellipse 900px 480px at 50% -8%, rgba(181, 18, 32, .18), transparent 65%);
  background-size: 34px 34px, 34px 34px, 100% 100%;
  background-attachment: fixed, fixed, fixed;
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

::selection { background: var(--red-deep); color: #fff; }

:focus-visible {
  outline: 2px solid var(--red-neon);
  outline-offset: 2px;
}

@keyframes pulseLine {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}

@keyframes dotPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: .6; }
}

@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}

/* ---------- layout ---------- */
.wrap { max-width: 840px; margin: 0 auto; padding: 1.6rem 1.1rem 3rem; }

/* ---------- brand / logo ---------- */
.brand { display: flex; gap: .8rem; align-items: center; }
.brand-mark {
  width: 52px; height: 52px; flex-shrink: 0; border-radius: 12px;
  background: linear-gradient(160deg, var(--red-deep), var(--red-deep-2));
  border: 1px solid var(--red-neon);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 18px -4px var(--red-glow);
}
.brand-mark svg { width: 26px; height: 26px; }
.brand-name { font-size: 1.3rem; font-weight: 700; letter-spacing: .04em; line-height: 1.15; color: var(--ink); }
.brand-sub { font-size: .68rem; letter-spacing: .16em; color: var(--red-neon); font-weight: 600; }

/* ---------- header (dashboard) ---------- */
.app-header {
  position: relative;
  display: flex; justify-content: space-between; align-items: flex-start;
  flex-wrap: wrap; gap: 1rem; padding-bottom: 1.2rem; margin-bottom: 1.4rem;
}
.app-header::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: linear-gradient(90deg, var(--red-neon), transparent 75%);
  box-shadow: 0 0 14px 1px var(--red-glow);
  animation: pulseLine 3.4s ease-in-out infinite;
}
.app-header .brand-page { font-size: .92rem; color: var(--silver-dim); margin-top: .35rem; }
.header-actions { display: flex; flex-direction: column; align-items: flex-end; gap: .55rem; }
@media (max-width: 560px) {
  .app-header { flex-direction: column; }
  .header-actions { align-items: flex-start; width: 100%; flex-direction: row; justify-content: space-between; }
}

/* ---------- badges / status ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .45rem; padding: .38rem .8rem;
  border-radius: 999px; font-size: .74rem; letter-spacing: .04em; border: 1px solid; white-space: nowrap;
}
.badge-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 6px 2px var(--green-glow); animation: dotPulse 1.8s ease-in-out infinite;
}
.badge-green { color: #8ffcb9; background: rgba(53, 224, 127, .08); border-color: rgba(53, 224, 127, .35); }

/* ---------- panels ---------- */
.panel {
  position: relative; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.15rem 1.3rem; margin: 1rem 0;
}
.panel-title {
  display: flex; align-items: center; gap: .6rem; font-size: .96rem; font-weight: 600;
  margin: 0 0 1rem; color: var(--ink);
}
.panel-title::before {
  content: ""; width: 3px; height: 16px; background: var(--red-neon); border-radius: 2px;
  box-shadow: 0 0 6px var(--red-glow); flex-shrink: 0;
}
.panel-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .9rem; }

/* ---------- stats ---------- */
.stat-row { display: flex; gap: 1.8rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.stat-label { display: block; font-size: .68rem; letter-spacing: .07em; color: var(--silver-dim); margin-bottom: .3rem; }
.stat-value { font-size: 1.35rem; font-weight: 700; color: var(--ink); }
.stat.accent .stat-value { color: var(--red-neon); text-shadow: 0 0 14px var(--red-glow); }

/* ---------- flash messages ---------- */
.flash { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; font-size: .88rem; border: 1px solid; }
.flash.error { background: rgba(181, 18, 32, .14); border-color: rgba(255, 42, 60, .4); color: #ffb3ba; }
.flash.success { background: rgba(53, 224, 127, .1); border-color: rgba(53, 224, 127, .35); color: #9ff5c0; }
.flash.warning { background: rgba(231, 185, 63, .12); border-color: rgba(231, 185, 63, .4); color: #f0cf7a; }

/* ---------- buttons ---------- */
.btn {
  display: inline-block; font-family: var(--font); font-weight: 600; letter-spacing: .02em; border-radius: 8px;
  cursor: pointer; padding: .68rem 1.15rem; font-size: .92rem; border: 1px solid transparent;
  text-decoration: none; text-align: center;
  transition: box-shadow .15s ease, border-color .15s ease, background .15s ease, color .15s ease, filter .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none !important; box-shadow: none !important; }

.btn-primary {
  width: 100%; color: #fff;
  background: linear-gradient(180deg, var(--btn-grad-1), var(--btn-grad-2));
  border-color: var(--red-neon);
  box-shadow: 0 0 0 1px rgba(255, 42, 60, .15) inset, 0 4px 22px -4px var(--red-glow);
}
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
  box-shadow: 0 0 0 1px rgba(255, 42, 60, .25) inset, 0 6px 30px -2px var(--red-glow);
}

.btn-ghost { background: var(--panel-soft); border-color: var(--border); color: var(--silver); }
.btn-ghost:hover {
  border-color: var(--red-neon); color: #fff; background: rgba(255, 42, 60, .07);
  box-shadow: 0 0 16px -4px var(--red-glow);
}

.btn-silver { background: rgba(203, 209, 218, .06); border-color: rgba(203, 209, 218, .3); color: var(--silver); }
.btn-silver:hover { border-color: #e3e7ec; color: #fff; background: rgba(203, 209, 218, .14); }

.btn-danger { background: transparent; border-color: rgba(181, 18, 32, .55); color: #ff8792; }
.btn-danger:hover {
  background: rgba(181, 18, 32, .2); border-color: var(--red-neon); color: #fff;
  box-shadow: 0 0 16px -4px var(--red-glow);
}

.btn-sm { padding: .45rem .8rem; font-size: .82rem; }

/* ---------- form fields ---------- */
.field { display: block; margin-bottom: 1rem; }
.field label { display: block; font-size: .78rem; color: var(--silver-dim); letter-spacing: .03em; margin-bottom: .4rem; }
.input {
  width: 100%; padding: .72rem .85rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--input-bg); color: var(--ink); font-family: var(--font); font-size: .95rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder { color: #545c69; }
.input:focus {
  outline: none; border-color: var(--red-neon);
  box-shadow: 0 0 0 3px rgba(255, 42, 60, .16), 0 0 18px -2px var(--red-glow);
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
@media (max-width: 480px) { .row2 { grid-template-columns: 1fr; } }
.pwfield { position: relative; }
.pwfield .toggle {
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--silver-dim); cursor: pointer;
  font-size: .75rem; padding: .3rem .5rem; font-family: var(--font);
}
.pwfield .toggle:hover { color: var(--silver); }
.hint { color: var(--ink-dim); font-size: .78rem; margin-top: .5rem; }

/* ---------- search + table ---------- */
.searchbar { display: flex; gap: .6rem; margin-bottom: .9rem; flex-wrap: wrap; }
.searchbar .input { flex: 1; min-width: 160px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem .5rem; font-size: .88rem; border-bottom: 1px solid var(--border); }
th { color: var(--silver-dim); font-weight: 600; font-size: .72rem; letter-spacing: .05em; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: rgba(255, 255, 255, .025); }
td.name { color: var(--ink); overflow-wrap: anywhere; }
td.size { color: var(--silver-dim); white-space: nowrap; }
td.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
@media (max-width: 600px) {
  td.actions { flex-direction: column; align-items: flex-start; }
  td.actions .btn { width: 100%; }
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th.sortable .arrow { opacity: .45; font-size: .68rem; margin-left: .25rem; }

/* ---------- upload dropzone ---------- */
.dropzone {
  position: relative; border: 2px dashed var(--border-strong); border-radius: var(--radius);
  padding: 1.7rem 1rem; text-align: center; transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
  cursor: pointer; margin-bottom: 1rem;
}
.dropzone:hover, .dropzone.drag {
  border-color: var(--red-neon); background: rgba(255, 42, 60, .045);
  box-shadow: 0 0 26px -6px var(--red-glow) inset;
}
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.upload-icon {
  width: 48px; height: 48px; margin: 0 auto .8rem; border-radius: 10px;
  background: var(--accent-wash); border: 1px solid var(--accent-wash-border);
  display: flex; align-items: center; justify-content: center; color: var(--red-neon);
}
.upload-icon svg { width: 22px; height: 22px; }
.dz-title { font-size: .95rem; color: var(--ink); margin-bottom: .3rem; }
.dz-sub { font-size: .78rem; color: var(--silver-dim); }
.dz-choose {
  display: inline-block; margin-top: .9rem; pointer-events: none;
  padding: .5rem 1.1rem; border-radius: 7px; border: 1px solid var(--border-strong);
  color: var(--silver); font-size: .82rem; font-weight: 600;
}
.file-chip-list { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .9rem; }
.file-chip {
  font-size: .75rem; padding: .32rem .6rem; border-radius: 6px;
  background: rgba(203, 209, 218, .08); border: 1px solid rgba(203, 209, 218, .22); color: var(--silver);
}
.file-chip .sz { color: var(--silver-dim); margin-left: .35rem; }
.progress {
  height: 6px; border-radius: 4px; background: rgba(255, 255, 255, .07);
  overflow: hidden; margin: 1rem 0 0; display: none; position: relative;
}
.progress.active { display: block; }
.progress-bar {
  position: absolute; top: 0; bottom: 0; left: 0; width: 0%;
  background: linear-gradient(90deg, var(--red-deep), var(--red-neon));
  border-radius: 4px; box-shadow: 0 0 10px var(--red-glow);
  transition: width .15s linear;
}
.upload-stats {
  display: none; margin-top: .5rem; font-size: .78rem; color: var(--silver-dim);
  font-variant-numeric: tabular-nums;
}
.upload-stats.active { display: block; }
.upload-stats.error { color: #ff8792; }

/* ---------- collapsible sections ---------- */
details.collapsible summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: .55rem;
  font-weight: 600; font-size: .92rem; color: var(--ink);
}
details.collapsible summary::-webkit-details-marker { display: none; }
details.collapsible summary .chevron { transition: transform .18s ease; color: var(--silver-dim); font-size: .8rem; }
details.collapsible[open] summary .chevron { transform: rotate(90deg); color: var(--red-neon); }
details.collapsible form { margin-top: 1.1rem; }

/* ---------- login page ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem 1rem; }
.auth-card {
  position: relative; width: 380px; max-width: 100%;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 2.3rem 1.9rem 1.9rem; box-shadow: 0 24px 70px -24px rgba(0, 0, 0, .65);
}
.auth-card::before {
  content: ""; position: absolute; top: 0; left: 10%; right: 10%; height: 2px;
  background: linear-gradient(90deg, transparent, var(--red-neon), transparent);
  box-shadow: 0 0 16px 2px var(--red-glow);
  animation: pulseLine 3.2s ease-in-out infinite;
}
.auth-card::after {
  content: ""; position: absolute; top: 16px; right: 16px; width: 20px; height: 20px;
  border-top: 2px solid var(--red-neon); border-right: 2px solid var(--red-neon); opacity: .7;
}
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: .55rem; margin-bottom: 1.6rem; text-align: center; }
.auth-logo .brand-mark { width: 62px; height: 62px; }
.auth-logo .brand-mark svg { width: 30px; height: 30px; }
.auth-title { font-size: .92rem; color: var(--silver-dim); margin: .9rem 0 1.6rem; text-align: center; }
.auth-footnote {
  text-align: center; font-size: .7rem; color: var(--ink-dim); letter-spacing: .05em;
  margin-top: 1.4rem; padding-top: 1.2rem; border-top: 1px solid var(--border);
}
.auth-page-footer { text-align: center; font-size: .7rem; color: #3c4350; margin-top: 1.4rem; letter-spacing: .08em; }

/* ---------- เครดิตมุมล่างซ้าย ---------- */
.site-credit {
  position: fixed; left: 12px; bottom: 10px; z-index: 5; pointer-events: none;
  font-size: .68rem; letter-spacing: .08em; color: var(--silver-dim); opacity: .55;
  font-family: var(--font);
}

/* ---------- แผงเลือก/ปรับแต่งธีม ---------- */
.theme-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: .7rem; margin-bottom: 1.3rem;
}
.theme-swatch {
  display: block; width: 100%; text-align: left; cursor: pointer; font-family: var(--font);
  border-radius: var(--radius); border: 1px solid var(--border); background: var(--panel-soft);
  padding: 0; overflow: hidden; transition: border-color .15s ease, box-shadow .15s ease, transform .1s ease;
}
.theme-swatch:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.theme-swatch.active {
  border-color: var(--red-neon); box-shadow: 0 0 0 1px var(--red-neon) inset, 0 0 16px -4px var(--red-glow);
}
.theme-swatch .swatch-preview { display: flex; height: 40px; }
.theme-swatch .swatch-preview span { flex: 1; }
.theme-swatch .swatch-label {
  display: flex; align-items: center; justify-content: space-between; gap: .4rem;
  padding: .5rem .65rem; font-size: .72rem; font-weight: 600; letter-spacing: .03em; color: var(--silver);
}
.theme-swatch .swatch-check { color: var(--red-neon); font-size: .85rem; visibility: hidden; }
.theme-swatch.active .swatch-check { visibility: visible; }

.color-picker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1rem;
}
.color-field { display: flex; flex-direction: column; gap: .4rem; }
.color-field label { font-size: .74rem; color: var(--silver-dim); letter-spacing: .03em; }
.color-field .color-row {
  display: flex; align-items: center; gap: .55rem; border: 1px solid var(--border); border-radius: 8px;
  padding: .4rem .55rem; background: var(--input-bg);
}
.color-field input[type=color] {
  width: 32px; height: 32px; padding: 0; border: none; border-radius: 6px; cursor: pointer;
  background: none; flex-shrink: 0;
}
.color-field input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.color-field input[type=color]::-webkit-color-swatch { border: 1px solid var(--border-strong); border-radius: 6px; }
.color-field .color-hex { font-size: .78rem; color: var(--ink-dim); letter-spacing: .03em; }

.custom-theme-list { display: flex; flex-direction: column; gap: .55rem; margin-top: .9rem; }
.custom-theme-row {
  display: flex; align-items: center; justify-content: space-between; gap: .7rem; flex-wrap: wrap;
  border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; background: var(--panel-soft);
}
.custom-theme-row .ct-name { display: flex; align-items: center; gap: .55rem; font-size: .88rem; color: var(--ink); }
.custom-theme-row .ct-dot {
  width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--border-strong); flex-shrink: 0;
}
.custom-theme-row .ct-actions { display: flex; gap: .5rem; }
.theme-active-note {
  font-size: .78rem; color: var(--silver-dim); margin-bottom: 1rem;
}
.theme-active-note b { color: var(--red-neon); font-weight: 600; }

/* ---------- ประวัติการทำงาน (Activity Log) ---------- */
.activity-list { max-height: 360px; overflow-y: auto; }
.activity-row {
  display: flex; gap: .9rem; padding: .55rem 0; border-bottom: 1px solid var(--border);
  font-size: .85rem; align-items: baseline;
}
.activity-row:last-child { border-bottom: none; }
.activity-time { color: var(--silver-dim); white-space: nowrap; font-size: .74rem; flex-shrink: 0; min-width: 142px; }
.activity-msg { color: var(--ink); }
@media (max-width: 480px) {
  .activity-row { flex-direction: column; gap: .2rem; }
  .activity-time { min-width: 0; }
}

/* ---------- เมนูแท็บสำหรับจอคอม (Desktop Tab Navigation) ----------
   มือถือ: .tabs-nav ซ่อนอยู่ ทุกหัวข้อยังคงเป็น accordion <details> แบบเดิมทุกประการ (ไม่แตะต้อง)
   จอคอม (กว้างกว่า 880px): แสดงแถบเมนูแนวนอนด้านบนแทน แล้วสลับว่าหัวข้อไหนแสดงด้วย JS/CSS
   โดยไม่ยุ่งกับ attribute open/closed ของ <details> ที่เป็นกลไกของมือถือ */
.tabs-nav { display: none; }

@media (min-width: 880px) {
  /* ขยายพื้นที่เนื้อหาให้กว้างเต็มจอมากขึ้น (กล่องสถิติ/ตาราง mod/แท็บ) แทนที่จะจำกัดแคบไว้กลางจอ */
  .wrap { max-width: 1600px; padding: 1.8rem 2.4rem 3rem; }

  .tabs-nav {
    display: flex; flex-wrap: wrap; gap: .6rem;
    margin: 1.5rem 0 1.2rem; padding-bottom: 1.1rem;
    border-bottom: 1px solid var(--border);
  }
  .tabs-nav .tab-btn {
    font-family: var(--font); font-weight: 600; font-size: .83rem; letter-spacing: .01em;
    color: var(--ink-dim); background: var(--panel-soft); border: 1px solid var(--border);
    border-radius: 8px; padding: .62rem 1.15rem; cursor: pointer; white-space: nowrap;
    transition: border-color .15s ease, color .15s ease, background .15s ease, box-shadow .15s ease;
  }
  .tabs-nav .tab-btn:hover { color: var(--ink); border-color: var(--border-strong); }
  .tabs-nav .tab-btn.active {
    color: #fff; background: var(--accent-wash); border-color: var(--red-neon);
    box-shadow: 0 0 16px -4px var(--red-glow);
  }

  .tabs-container .tab-panel { display: none; }
  .tabs-container .tab-panel.active-tab { display: block; }

  /* บนจอคอม JS จะบังคับให้ <details> ของทุกแท็บเป็น open อยู่แล้วเสมอ (ดูสคริปต์ด้านล่างของหน้า)
     เหลือแค่ซ่อนหัวลูกศร summary เพราะเปลี่ยนหัวข้อด้วยแท็บด้านบนแทนการกดเปิด/ปิดเอง */
  .tabs-container .tab-panel details.collapsible > summary { display: none; }
}
