@font-face {
  font-family: 'Noto Sans Thai';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/assets/noto-sans-thai-thai.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'Noto Sans Thai';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/assets/noto-sans-thai-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Noto Sans Thai';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/assets/noto-sans-thai-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --sidebar: #1e232b;
  --sidebar-text: #cfd6de;
  --sidebar-active: #2c343f;
  --border: #e0e4ea;
  --text: #1b1f24;
  --muted: #6b7280;
  --accent: #2f6fe0;
  --accent-text: #ffffff;
  --ok: #17794d;
  --warn: #9a5b00;
  --err: #c23b30;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --surface: #1b1f25;
    --surface-2: #232830;
    --sidebar: #101317;
    --sidebar-text: #b9c2cc;
    --sidebar-active: #262d36;
    --border: #2d333c;
    --text: #e7eaee;
    --muted: #97a1ad;
    --accent: #5d95f2;
    --accent-text: #0d1116;
    --ok: #4fca8b;
    --warn: #e0a44c;
    --err: #f2776c;
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
h2 { font-size: 16px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 12px; }
code { font-family: ui-monospace, Menlo, monospace; font-size: 0.88em; }

.screen { min-height: 100vh; }

/* ───────── auth ───────── */
.auth-screen { display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
}
.auth-brand { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; }
.auth-brand .logo { font-size: 26px; }
.auth-lead { color: var(--muted); font-size: 14px; margin: 6px 0 20px; }
.block { width: 100%; justify-content: center; }

/* ───────── shell ───────── */
.app-shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 20px;
}
.sidebar .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: #fff; padding: 0 8px; }
.sidebar .logo { font-size: 22px; }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.55; padding: 0 8px 6px; }
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.nav-item:hover { background: var(--sidebar-active); }
.nav-item.is-active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-icon { width: 18px; text-align: center; }
.nav-item .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.me { min-width: 0; flex: 1; }
.me-name { font-size: 13px; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-role { font-size: 11px; opacity: 0.6; }

.main { min-width: 0; padding: 18px 22px 40px; }
.view { display: none; }
.view.is-active { display: block; }

.topbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; min-height: 34px; }
.spacer { flex: 1; }

/* ───────── crumbs ───────── */
.crumbs { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; font-size: 14px; min-width: 0; }
.crumb {
  border: 0;
  background: none;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 6px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crumb:hover { background: var(--surface-2); }
.crumb.current { color: var(--text); font-weight: 600; cursor: default; }
.crumb.current:hover { background: none; }
.crumb-sep { color: var(--muted); }

/* ───────── controls ───────── */
.btn {
  font: inherit;
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.file-btn { cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field.grow { flex: 1; min-width: 190px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  width: 100%;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0 12px; font-size: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row.end { justify-content: flex-end; margin-top: 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }

.status { font-size: 14px; margin: 8px 0; min-height: 20px; }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }
.status.warn { color: var(--warn); }
.status.busy { color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.empty { color: var(--muted); padding: 40px; text-align: center; }

.tabs { display: flex; gap: 4px; }
.tab {
  border: 0;
  background: none;
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.is-active { background: var(--surface); border: 1px solid var(--border); color: var(--text); font-weight: 600; }
.admin-panel { display: none; }
.admin-panel.is-active { display: block; }

/* ───────── file table ───────── */
.selectbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 14px;
  flex-wrap: wrap;
}
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; position: relative; }
.table-wrap.dragging { outline: 2px dashed var(--accent); outline-offset: -6px; }
table.files { width: 100%; border-collapse: collapse; }
table.files th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
table.files td { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
table.files tr:last-child td { border-bottom: 0; }
table.files tbody tr:hover { background: var(--surface-2); }
.col-check { width: 38px; }
.col-size { width: 110px; text-align: right; }
.col-time { width: 170px; }
td.col-size { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
td.col-time { color: var(--muted); font-size: 13px; }
.entry { display: flex; align-items: center; gap: 8px; min-width: 0; }
.entry .icon { flex: none; }
.entry .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry.dir .name { color: var(--accent); cursor: pointer; }
.entry.dir .name:hover { text-decoration: underline; }
.drop-hint {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-weight: 600;
  color: var(--accent);
  pointer-events: none;
}
.table-wrap.dragging .drop-hint { display: grid; }
.foot-note { color: var(--muted); font-size: 13px; margin-top: 10px; }

/* ───────── jobs ───────── */
.job { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.job-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.job-title { font-weight: 600; }
.job-meta { color: var(--muted); font-size: 13px; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border); }
.pill.running { color: var(--accent); border-color: var(--accent); }
.pill.done { color: var(--ok); border-color: var(--ok); }
.pill.error, .pill.partial { color: var(--err); border-color: var(--err); }
.pill.canceled, .pill.queued { color: var(--muted); }
.bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 10px 0; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width 0.25s ease; }
.job-files { font-size: 13px; margin-top: 6px; }
.job-file { display: flex; gap: 10px; padding: 3px 0; }
.job-file .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-file .st { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.job-file .st.done { color: var(--ok); }
.job-file .st.error { color: var(--err); }

/* ───────── rows (conn / user / audit) ───────── */
.rowcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.rowcard .info { min-width: 0; flex: 1; }
.rowcard .name { font-weight: 600; }
.rowcard .sub { color: var(--muted); font-size: 13px; word-break: break-all; }
.rowcard .actions { display: flex; gap: 6px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.tag.admin { color: var(--accent); border-color: var(--accent); }
.tag.off { color: var(--err); border-color: var(--err); }

.audit-row { display: flex; gap: 10px; font-size: 13px; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.audit-row .at { color: var(--muted); width: 150px; flex: none; }
.audit-row .who { width: 190px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-row .what { font-weight: 600; width: 160px; flex: none; }
.audit-row .detail { color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ───────── modal ───────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  width: min(560px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
}
.picker-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 8px 0;
  overflow-y: auto;
  flex: 1;
  min-height: 200px;
}
.picker-item {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  color: inherit;
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.picker-item:hover { background: var(--surface-2); }
.picker-item:last-child { border-bottom: 0; }

/* ───────── toast ───────── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--sidebar);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
}
.toast.err { background: var(--err); }

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; }
  .sidebar .nav-section { flex: 1; min-width: 160px; }
  .col-time { display: none; }
}

/* ───────── ไอคอน Tabler ───────── */
.tbi { width: 18px; height: 18px; flex: none; stroke-width: 2; }
.btn .tbi { width: 16px; height: 16px; }
.btn.small .tbi { width: 15px; height: 15px; }
.btn.icon-only { padding: 7px 9px; }
.btn.small.icon-only { padding: 5px 7px; }
.tab .tbi { width: 15px; height: 15px; margin-right: 5px; vertical-align: -2px; }
.tab { display: inline-flex; align-items: center; }
.logo .tbi { width: 24px; height: 24px; stroke-width: 1.8; color: var(--accent); }
.auth-brand .logo .tbi { width: 28px; height: 28px; }
.nav-icon .tbi { width: 18px; height: 18px; }
.nav-icon, .logo { display: inline-flex; align-items: center; }
.entry .icon .tbi { width: 17px; height: 17px; }
.entry.dir .icon { color: var(--accent); }
.entry.file .icon { color: var(--muted); }

/* ───────── รายการเส้นทางเข้าถึง NAS ───────── */
.endpoints { display: flex; flex-direction: column; gap: 6px; }
.endpoint-row { display: flex; align-items: center; gap: 8px; }
.endpoint-row input { flex: 1; min-width: 0; }
.endpoint-row .order {
  width: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  flex: none;
}
.endpoint-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
  flex: none;
  min-width: 108px;
  text-align: center;
}
.endpoint-tag.LAN, .endpoint-tag.vpn { color: var(--ok); border-color: var(--ok); }
.endpoint-tag.relay { color: var(--warn); border-color: var(--warn); }
.endpoint-tag.direct { color: var(--accent); border-color: var(--accent); }
.self-start { align-self: flex-start; margin-top: 4px; }
.route-note { display: inline-flex; align-items: center; gap: 5px; }

/* ───────── ฐานราก: เวอร์ชัน / ถังขยะ / สิทธิ์ ───────── */
.modal.wide { max-width: 720px; }

.version-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden auto;
  max-height: 46vh;
  margin: 12px 0;
}
.vrow {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  flex-wrap: wrap;
}
.vrow-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.vrow-main { font-weight: 600; font-size: 14.5px; word-break: break-word; }
.vrow-sub { color: var(--muted); font-size: 12.5px; word-break: break-word; }
.vrow-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.vrow-actions .btn { display: inline-flex; align-items: center; gap: 5px; text-decoration: none; }
.version-list .empty { background: var(--surface); border: 0; }

.grant-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.grant-form .field { margin-bottom: 0; }
.grant-form .btn { display: inline-flex; align-items: center; gap: 6px; }

.member-picks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 2px 16px;
  margin: 10px 0;
  max-height: 200px;
  overflow-y: auto;
}

.lock-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid var(--warn);
  color: var(--warn);
  white-space: nowrap;
}
.lock-badge.mine { border-color: var(--ok); color: var(--ok); }
.lock-badge .tbi { width: 12px; height: 12px; }

/* ───────── ค้นหา ───────── */
.searchbox { position: relative; display: flex; align-items: center; min-width: 260px; }
.searchbox .search-icon {
  position: absolute; left: 10px; display: inline-flex; color: var(--muted); pointer-events: none;
}
.searchbox .search-icon .tbi { width: 16px; height: 16px; }
.searchbox input {
  width: 100%;
  padding: 7px 12px 7px 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.searchbox input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: min(520px, 90vw);
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.28);
  z-index: 40;
  padding: 4px;
}
.search-hit {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.search-hit:hover, .search-hit:focus-visible { background: var(--surface-2); }
.search-hit .tbi { flex: none; color: var(--muted); }
.hit-text { min-width: 0; flex: 1; }
.hit-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hit-path { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hit-size { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.search-empty { padding: 14px; color: var(--muted); font-size: 14px; text-align: center; }

.backup-card .row { align-items: center; gap: 10px; }
.backup-card .btn { display: inline-flex; align-items: center; gap: 5px; }
