/* DarkStoryM Admin - "Professional Modern Dark Fantasy": black and deep purple, gold accent. No external font or library. */
:root {
  --bg: #0b0910; --bg2: #120e1a; --panel: #18122300; --card: #1a1326; --card2: #221832; --line: #33264a; --line2: #4a3668;
  --text: #ece6f5; --muted: #a596bd; --dim: #786a8f;
  --gold: #d8b25a; --gold2: #f0d38a; --gold-dim: #8a7038;
  --purple: #7b4bc4; --purple2: #9d6fe6;
  --ok: #4fc08d; --warn: #e6a23c; --bad: #e0556a; --info: #6aa8e6;
  --radius: 10px; --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  --font: "Segoe UI", "Leelawadee UI", "Noto Sans Thai", Tahoma, system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: radial-gradient(1200px 600px at 80% -10%, #2a1748 0%, transparent 60%), radial-gradient(900px 500px at -10% 110%, #1d1030 0%, transparent 60%), var(--bg);
  color: var(--text); font: 14px/1.45 var(--font); overflow-x: hidden; }
a { color: var(--gold2); text-decoration: none; }
a:hover { text-decoration: underline; }
.en { color: var(--muted); font-size: .82em; margin-left: .35em; font-weight: 400; }
.boot { padding: 40px; color: var(--muted); }
h1, h2, h3 { margin: 0 0 .6em; font-weight: 600; letter-spacing: .01em; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.08rem; color: var(--gold2); } h3 { font-size: .98rem; }

/* ---------- layout */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: linear-gradient(180deg, #120c1c, #0d0914); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 18px 18px 14px; border-bottom: 1px solid var(--line); }
.brand .logo { font-size: 1.15rem; font-weight: 700; color: var(--gold); letter-spacing: .06em; }
.brand .sub { color: var(--dim); font-size: .78rem; text-transform: uppercase; letter-spacing: .14em; }
.nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text); border: 1px solid transparent; }
.nav a:hover { background: #1f1630; text-decoration: none; }
.nav a.on { background: linear-gradient(90deg, #2b1b45, #1f1532); border-color: var(--line2); box-shadow: inset 3px 0 0 var(--gold); }
.nav .ic { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 6px; background: #241935; color: var(--gold); font-size: 12px; flex: none; }
.nav .lbl { display: flex; flex-direction: column; line-height: 1.15; }
.nav .lbl .en { margin: 0; font-size: .74rem; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 12px 22px; border-bottom: 1px solid var(--line); background: rgba(14, 10, 22, .85); position: sticky; top: 0; z-index: 5; backdrop-filter: blur(6px); }
.top .title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .who { color: var(--muted); font-size: .86rem; }
.menu-btn { display: none; }
.content { padding: 22px; max-width: 1400px; width: 100%; }

/* ---------- components */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.cols { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.card { background: linear-gradient(180deg, var(--card2), var(--card)); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 16px; }
.cols .card + .card, .grid .card + .card { margin-top: 0; }
.stat .k { color: var(--muted); font-size: .8rem; }
.stat .v { font-size: 1.6rem; font-weight: 700; color: var(--gold2); margin-top: 4px; word-break: break-word; }
.stat .s { color: var(--dim); font-size: .78rem; margin-top: 2px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .76rem; border: 1px solid var(--line2); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: #2d6b51; background: #11261c; }
.badge.bad { color: var(--bad); border-color: #7a2d3a; background: #2a1016; }
.badge.warn { color: var(--warn); border-color: #7a5a22; background: #2a1f0e; }
.badge.gold { color: var(--gold2); border-color: var(--gold-dim); background: #2a2210; }
.badge.info { color: var(--info); border-color: #2d4f7a; background: #0f1d2c; }
.muted { color: var(--muted); } .dim { color: var(--dim); } .mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: .86em; word-break: break-all; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.table-wrap { width: 100%; overflow-x: auto; border-radius: 8px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #2a1f3d; vertical-align: top; }
th { background: #1d1530; color: var(--gold); font-weight: 600; font-size: .8rem; white-space: nowrap; position: sticky; top: 0; }
tr:hover td { background: #1c1429; }
tr.click { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: fit-content(45%) minmax(0, 1fr); gap: 6px 16px; }
.kv .k { color: var(--muted); }
.kv .v { font-variant-numeric: tabular-nums; word-break: break-word; }

/* ---------- forms */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: #100b18; border: 1px solid var(--line2); border-radius: 8px; padding: 8px 10px; min-width: 0; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--purple); outline-offset: 0; border-color: var(--purple2); }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: .84rem; min-width: 0; }
.form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.btn { background: #241935; border: 1px solid var(--line2); border-radius: 8px; padding: 8px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #2e2045; }
.btn.gold { background: linear-gradient(180deg, #e2bf6a, #b8913d); color: #1a1205; border-color: #e6c983; font-weight: 600; }
.btn.gold:hover { filter: brightness(1.06); }
.btn.danger { background: #3a121b; border-color: #7a2d3a; color: #ffb3bf; }
.btn.small { padding: 4px 9px; font-size: .82rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.search { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.search input { flex: 1 1 220px; }
.note { border-left: 3px solid var(--gold-dim); background: #19131f; padding: 8px 12px; border-radius: 6px; color: var(--muted); font-size: .86rem; margin: 10px 0; }
.err { color: var(--bad); }
.okc { color: var(--ok); }

/* ---------- items */
.icon { width: 40px; height: 40px; border-radius: 6px; background-color: #0e0a14; border: 1px solid var(--line); background-repeat: no-repeat; flex: none; image-rendering: auto; }
.icon.none { display: grid; place-items: center; color: var(--dim); font-size: 10px; }
.bag { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.slot { display: flex; gap: 8px; align-items: center; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: #140f1d; min-width: 0; }
.slot .t { min-width: 0; flex: 1; }
.slot .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .84rem; }
.slot .q { color: var(--gold2); font-size: .8rem; }
.itemlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.item { display: flex; gap: 10px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #140f1d; cursor: pointer; min-width: 0; }
.item:hover, .item.on { border-color: var(--gold-dim); background: #1d1528; }
.item .t { min-width: 0; }
.item .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- modal, toast, login */
.modal-bg { position: fixed; inset: 0; background: rgba(5, 3, 9, .72); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: min(560px, 100%); max-height: 90vh; overflow: auto; background: linear-gradient(180deg, #24183a, #171024); border: 1px solid var(--gold-dim); border-radius: 14px; padding: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
.diff td.b { color: var(--muted); } .diff td.a { color: var(--gold2); font-weight: 600; }
.toast { position: fixed; right: 16px; bottom: 16px; max-width: min(420px, calc(100vw - 32px)); background: #1d1530; border: 1px solid var(--line2); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); z-index: 60; }
.toast.ok { border-color: #2d6b51; } .toast.bad { border-color: #7a2d3a; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 26px; }
.login .logo { font-size: 1.5rem; font-weight: 700; color: var(--gold); letter-spacing: .08em; text-align: center; }
.login .sub { text-align: center; color: var(--dim); font-size: .8rem; letter-spacing: .16em; text-transform: uppercase; margin-bottom: 18px; }
.login form { display: grid; gap: 12px; }
.sep { height: 1px; background: linear-gradient(90deg, transparent, var(--gold-dim), transparent); margin: 14px 0; }

/* ---------- phone / tablet */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(280px, 82vw); transform: translateX(-100%); transition: transform .18s ease; z-index: 40; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .menu-btn { display: inline-block; }
  .content { padding: 14px 16px; }
  .top { padding: 10px 16px; }
  .cols { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .stat .v { font-size: 1.3rem; }
  .top .who { display: none; }
}
@media (max-width: 420px) { .bag { grid-template-columns: 1fr 1fr; } .form { grid-template-columns: 1fr 1fr; } }
