/* ===== Tokens ===== */
:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --sidebar: #ffffff;
  --text: #161a23;
  --text-2: #4a5263;
  --muted: #8089a0;
  --border: #e5e8ef;
  --border-strong: #d3d8e3;
  --accent: #5b5bf0;
  --accent-2: #8b5cf6;
  --accent-soft: #eeeefe;
  --accent-text: #ffffff;
  --ok: #16a36a;
  --ok-soft: #e6f6ee;
  --danger: #e0394a;
  --danger-soft: #fdecee;
  --warn: #d98a06;
  --shadow-sm: 0 1px 2px rgba(20, 24, 40, .06);
  --shadow: 0 1px 2px rgba(20, 24, 40, .05), 0 4px 16px rgba(20, 24, 40, .06);
  --shadow-lg: 0 12px 40px rgba(20, 24, 40, .18);
  --radius: 14px;
  --radius-sm: 9px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1017;
    --surface: #151922;
    --surface-2: #1a1f2a;
    --sidebar: #11141c;
    --text: #e8ebf2;
    --text-2: #b4bccb;
    --muted: #7b8496;
    --border: #252b37;
    --border-strong: #323a49;
    --accent: #7c7cff;
    --accent-2: #a78bfa;
    --accent-soft: #23234a;
    --accent-text: #0b0d18;
    --ok: #34d399;
    --ok-soft: #10291f;
    --danger: #ff6b7a;
    --danger-soft: #3a1820;
    --warn: #fbbf24;
    --shadow-sm: none;
    --shadow: 0 1px 0 rgba(255, 255, 255, .02);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

/* ===== Base ===== */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Sarabun", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
button { font: inherit; color: inherit; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); font-size: 13px; }

/* ===== Buttons & inputs ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 15px; border-radius: 10px; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 550; transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary {
  border-color: transparent; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--accent), var(--accent-2)); filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger.armed { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; gap: 5px; }
.btn-sm svg.i { width: 15px; height: 15px; }
.btn-block { width: 100%; height: 44px; font-size: 15px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: transparent; border: 0; color: var(--muted); cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.field { display: grid; gap: 6px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
input, select {
  font: inherit; height: 40px; padding: 0 12px; border-radius: 10px; width: 100%;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, .btn:focus-visible, .icon-btn:focus-visible, .nav-item:focus-visible, .dropzone:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.form-error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 13px; }

/* ===== Logo ===== */
.logo {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #fff; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent);
}
.logo svg.i { width: 20px; height: 20px; stroke-width: 2.1; }
.logo-lg { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 18px; }
.logo-lg svg.i { width: 30px; height: 30px; }

/* ===== Login ===== */
.login {
  min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(900px 500px at 15% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
    radial-gradient(700px 500px at 110% 110%, color-mix(in srgb, var(--accent-2) 16%, transparent), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; padding: 34px 30px 30px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg);
}
.login-card h1 { margin: 0; font-size: 21px; letter-spacing: -.01em; }
.login-card .sub { margin: 6px 0 24px; color: var(--muted); }
.login-card form { display: grid; gap: 14px; text-align: left; }

/* ===== Shell ===== */
.shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100%; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px;
  padding: 18px 14px; background: var(--sidebar); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 6px 18px; }
.brand-name { font-weight: 700; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 2px; }
.nav-group { display: grid; gap: 2px; }
.nav-label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 9px;
  background: transparent; border: 0; cursor: pointer; text-align: left; color: var(--text-2); font-weight: 550;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item .nav-text { overflow: hidden; text-overflow: ellipsis; }
.me {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 700; color: var(--accent); background: var(--accent-soft); text-transform: uppercase;
}
.me-text { flex: 1; min-width: 0; }
.me-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-role { font-size: 12px; color: var(--muted); }

.main { padding: 26px 32px 120px; min-width: 0; max-width: 1180px; width: 100%; }

/* ===== Page head & breadcrumbs ===== */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-title { min-width: 0; }
.eyebrow { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.crumbs button {
  background: none; border: 0; padding: 2px 6px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-weight: inherit;
}
.crumbs button:hover { background: var(--surface); color: var(--text); }
.crumbs button:last-child { color: var(--text); }
.crumbs .sep { color: var(--border-strong); font-weight: 400; }

.inline-form {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px;
  padding: 12px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius);
}
.inline-form input { flex: 1 1 220px; width: auto; }
.hint { font-size: 12.5px; color: var(--muted); }

/* ===== Dropzone ===== */
.dropzone {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap; cursor: pointer;
  padding: 20px 22px; margin-bottom: 18px; border-radius: var(--radius);
  border: 1.5px dashed var(--border-strong);
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 5%, var(--surface)), var(--surface));
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon {
  width: 48px; height: 48px; border-radius: 13px; display: grid; place-items: center; flex: none;
  color: var(--accent); background: var(--accent-soft);
}
.dz-icon svg.i { width: 26px; height: 26px; }
.dz-text { flex: 1 1 260px; min-width: 0; }
.dz-title { font-weight: 650; font-size: 15px; }
.dz-sub { color: var(--muted); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.link { color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  font-size: 11.5px; font-weight: 600; padding: 3px 8px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}

/* ===== Panels & tables ===== */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden;
}
.panel-head { display: flex; align-items: baseline; gap: 10px; padding: 16px 20px 6px; }
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-foot { padding: 0 20px; }
.panel-foot .btn { margin: 12px 0 16px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 10px 20px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 10px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text-2); }
.table .date { color: var(--text-2); white-space: nowrap; font-size: 13px; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions > * + * { margin-left: 6px; }
.row-actions { opacity: .45; transition: opacity .12s; }
.table tr:hover .row-actions, .row-actions:focus-within { opacity: 1; }
/* destructive buttons only appear on the row you're pointing at */
@media (hover: hover) { .row-actions .btn-danger { visibility: hidden; } .table tr:hover .row-actions .btn-danger, .row-actions .btn-danger:focus-visible, .row-actions .btn-danger.armed { visibility: visible; } }
@media (hover: none) { .row-actions { opacity: 1; } }

.name-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.name-cell .nm { font-weight: 550; overflow-wrap: anywhere; }
.name-btn { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; display: flex; align-items: center; gap: 12px; color: inherit; }
.name-btn:hover .nm { color: var(--accent); }
.ficon {
  width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; flex: none;
  font-size: 10px; font-weight: 800; letter-spacing: .02em; color: #fff;
}
.ficon svg.i { width: 19px; height: 19px; }
.ficon.folder { background: color-mix(in srgb, #f5a524 18%, var(--surface)); color: #e3940f; }
.ficon.up { background: var(--surface-2); color: var(--muted); }
.ft-zip { background: #6366f1; } .ft-apk, .ft-aab { background: #16a34a; } .ft-ipa { background: #0ea5e9; }
.ft-exe { background: #2563eb; } .ft-dmg { background: #64748b; } .ft-tgz { background: #a855f7; }
.ft-unity { background: #334155; } .ft-other { background: #94a3b8; }
.ft-img { background: #ec4899; } .ft-vid { background: #ef4444; } .ft-aud { background: #f59e0b; } .ft-code { background: #0f766e; }

.empty { text-align: center; padding: 44px 20px !important; color: var(--muted); }
.empty svg.i { width: 34px; height: 34px; display: block; margin: 0 auto 10px; opacity: .6; }
.skeleton td { padding: 16px 20px; }
.skeleton .bar-sk { height: 12px; border-radius: 6px; background: var(--surface-2); width: 60%; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* ===== Users ===== */
.user-form { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; padding: 10px 20px 20px; }
.user-form .field { flex: 1 1 200px; }
.user-form .field-sm { flex: 0 1 150px; }
.user-form .field-grow { flex: 3 1 300px; }
.toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.toggle { position: relative; }
.toggle input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle span {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 99px;
  border: 1px solid var(--border-strong); color: var(--text-2); font-size: 13px; font-weight: 550; white-space: nowrap;
  transition: all .12s;
}
.toggle span::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.toggle input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.toggle input:checked + span::before { background: var(--accent); }
.toggle input:focus-visible + span { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.users-table select { width: auto; height: 32px; padding: 0 8px; font-size: 13px; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.you { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }

.secret {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 20px 20px; padding: 14px 16px;
  border-radius: 12px; border: 1px solid color-mix(in srgb, var(--ok) 40%, var(--border)); background: var(--ok-soft);
}
.secret-text { flex: 1 1 220px; }
.secret-title { font-weight: 650; }
.secret-sub { font-size: 12.5px; color: var(--text-2); }
.secret code {
  font-size: 15px; padding: 7px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border);
  user-select: all; overflow-wrap: anywhere;
}

/* ===== Transfers panel ===== */
.transfers {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 40;
  width: min(440px, calc(100vw - 32px)); max-height: min(70vh, 620px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg);
  overflow: hidden; animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
.tr-head { display: flex; align-items: center; gap: 8px; padding: 12px 10px 10px 16px; }
.tr-title { flex: 1; min-width: 0; display: grid; }
#tr-title-text { font-weight: 700; }
.tr-summary { font-size: 12px; color: var(--muted); }
.tr-overall { height: 3px; background: var(--surface-2); }
.tr-overall > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }
.transfers.collapsed .tr-list { display: none; }
.transfers.collapsed [data-icon="chevron"] svg { transform: rotate(180deg); }
.tr-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; }
.tr-item { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 10px; border-radius: 11px; }
.tr-item + .tr-item { border-top: 1px solid var(--border); border-radius: 0; }
.tr-item .ficon { grid-row: span 2; }
.tr-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tr-path { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tr-btns { grid-row: span 2; display: flex; gap: 2px; }
.tr-bar { grid-column: 2 / 4; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.tr-bar > div {
  height: 100%; width: 0; border-radius: 99px; transition: width .25s;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  background-size: 200% 100%;
}
.tr-item.running .tr-bar > div { animation: shimmer 1.6s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.tr-meta { grid-column: 2 / 4; display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tr-meta .st { display: inline-flex; align-items: center; gap: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tr-meta .st svg.i { width: 14px; height: 14px; }
.tr-item.done .tr-bar > div { background: var(--ok); }
.tr-item.done .st { color: var(--ok); }
.tr-item.error .tr-bar > div { background: var(--danger); }
.tr-item.error .st { color: var(--danger); white-space: normal; }
.tr-item.cancelled .tr-bar > div { background: var(--muted); }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Drop overlay ===== */
.drop-overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px;
  background: color-mix(in srgb, var(--accent) 16%, rgba(10, 12, 24, .45));
  backdrop-filter: blur(4px); pointer-events: none;
}
.drop-card {
  display: grid; justify-items: center; gap: 10px; text-align: center; padding: 34px 44px; border-radius: 20px;
  background: var(--surface); border: 2px dashed var(--accent); box-shadow: var(--shadow-lg); max-width: 100%;
}
.drop-title { font-size: 19px; font-weight: 700; }
.drop-card code { color: var(--muted); overflow-wrap: anywhere; }

/* ===== Toasts ===== */
.toasts {
  position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  z-index: 80; display: grid; gap: 8px; width: min(460px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 12px; font-weight: 550;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: drop .2s ease-out;
}
.toast.ok svg.i { color: var(--ok); }
.toast.err svg.i { color: var(--danger); }
@keyframes drop { from { transform: translateY(-10px); opacity: 0; } }

/* ===== Responsive ===== */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; z-index: 30; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap;
    padding: 10px 16px calc(10px); padding-top: calc(10px + env(safe-area-inset-top, 0px)); gap: 10px;
    border-right: 0; border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0; flex: 1; }
  .brand-sub { display: none; }
  .me { order: 2; padding: 4px 4px 4px 8px; border: 0; background: none; }
  .me-text { display: none; }
  .nav { order: 3; flex: 1 1 100%; display: flex; overflow-x: auto; gap: 6px; padding-bottom: 2px; }
  .nav-group, #admin-nav { display: flex; gap: 6px; }
  .nav-label { display: none; }
  .nav-item { width: auto; flex: none; border: 1px solid var(--border); }
  .main { padding: 20px 16px 140px; }
  .crumbs { font-size: 19px; }
  .hide-sm { display: none; }
  .table th, .table td { padding-left: 14px; padding-right: 14px; }
  .transfers { right: 16px; left: 16px; width: auto; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
}
