/* shadcn/ui-style design tokens (Zinc theme) — dung chung cho desktop + mobile */
:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 0 0% 98%;
  --success: 142 71% 45%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;
  --radius: 0.5rem;
}
:root[data-theme="dark"] {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;
  --card: 240 6% 7%;
  --card-foreground: 0 0% 98%;
  --popover: 240 6% 7%;
  --popover-foreground: 0 0% 98%;
  --primary: 0 0% 98%;
  --primary-foreground: 240 5.9% 10%;
  --secondary: 240 3.7% 15.9%;
  --secondary-foreground: 0 0% 98%;
  --muted: 240 3.7% 15.9%;
  --muted-foreground: 240 5% 64.9%;
  --accent: 240 3.7% 15.9%;
  --accent-foreground: 0 0% 98%;
  --destructive: 0 62.8% 40.6%;
  --destructive-foreground: 0 0% 98%;
  --success: 142 71% 45%;
  --border: 240 3.7% 15.9%;
  --input: 240 3.7% 15.9%;
  --ring: 240 4.9% 83.9%;
}
* { box-sizing: border-box; }
html, body {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body { margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap; border-radius: calc(var(--radius) - 2px);
  font-size: 13px; font-weight: 500; line-height: 1;
  padding: 8px 14px; border: 1px solid transparent; cursor: pointer;
  background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground));
  transition: background-color .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.btn:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover { background: hsl(var(--primary) / .9); color: hsl(var(--primary-foreground)); }
.btn-outline { background: transparent; border-color: hsl(var(--border)); color: hsl(var(--foreground)); }
.btn-outline:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.btn-ghost { background: transparent; color: hsl(var(--foreground)); }
.btn-ghost:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.btn-destructive { background: transparent; color: hsl(var(--destructive)); border-color: hsl(var(--destructive) / .4); }
.btn-destructive:hover { background: hsl(var(--destructive) / .1); color: hsl(var(--destructive)); }
.btn-icon { padding: 8px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; }

/* ---------- Inputs ---------- */
.input, input[type="text"], input[type="password"], input:not([type]), select {
  display: block; width: 100%; background: hsl(var(--background));
  border: 1px solid hsl(var(--input)); color: hsl(var(--foreground));
  padding: 8px 12px; border-radius: calc(var(--radius) - 2px); font-size: 13px;
  font-family: inherit; transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus, input:focus, select:focus {
  outline: none; border-color: hsl(var(--ring)); box-shadow: 0 0 0 3px hsl(var(--ring) / .15);
}
label, .label { font-size: 12.5px; font-weight: 500; color: hsl(var(--foreground)); }

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 1000px hsl(var(--background)) inset !important;
  -webkit-text-fill-color: hsl(var(--foreground)) !important;
  caret-color: hsl(var(--foreground));
  transition: background-color 9999s ease-in-out 0s;
}

/* ---------- Card ---------- */
.card {
  background: hsl(var(--card)); color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border)); border-radius: var(--radius);
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.04);
}
.card-header { padding: 14px 16px; border-bottom: 1px solid hsl(var(--border)); }
.card-body { padding: 14px 16px; }
.card-title { font-size: 14px; font-weight: 600; margin: 0; }
.card-desc { font-size: 12.5px; color: hsl(var(--muted-foreground)); margin: 2px 0 0; }

/* ---------- Data table ---------- */
.data-table-wrap { background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--radius); overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; padding: 10px 14px; color: hsl(var(--muted-foreground)); font-weight: 600;
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / .3);
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid hsl(var(--border)); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: hsl(var(--accent) / .5); }
.data-table .actions-cell { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Badge ---------- */
.badge {
  display: inline-flex; align-items: center; border-radius: 999px;
  padding: 2px 9px; font-size: 11px; font-weight: 500;
  background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground));
  border: 1px solid transparent;
}
.badge-outline { background: transparent; border-color: hsl(var(--border)); color: hsl(var(--foreground)); }
.badge-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.badge-success { background: hsl(var(--success) / .15); color: hsl(var(--success)); }

/* ---------- Error text ---------- */
.error-text { color: hsl(var(--destructive)); font-size: 12.5px; min-height: 18px; }
.success-text { color: hsl(var(--success)); font-size: 12.5px; }

/* ---------- Empty state ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: hsl(var(--muted-foreground)); font-size: 13px; text-align: center; padding: 40px 20px; }
.empty-state svg { opacity: .5; }

/* ---------- Icon ---------- */
.icon { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 32px; height: 32px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0); pointer-events: none;
  transition: background .2s ease; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop.open { background: rgba(0,0,0,.5); pointer-events: auto; }
.modal {
  background: hsl(var(--card)); color: hsl(var(--card-foreground)); border: 1px solid hsl(var(--border));
  border-radius: var(--radius); width: 400px; max-width: 100%; box-shadow: 0 20px 50px rgb(0 0 0 / .3);
  transform: scale(.96); opacity: 0; transition: transform .15s ease, opacity .15s ease;
}
.modal-backdrop.open .modal { transform: scale(1); opacity: 1; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid hsl(var(--border)); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-body .field { margin-bottom: 14px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid hsl(var(--border)); display: flex; justify-content: flex-end; gap: 10px; }
.modal.modal-lg { width: 640px; }
.modal.modal-lg .modal-body { max-height: 70vh; overflow-y: auto; }

/* ---------- Drawer (slide-in tu ben phai) ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0); pointer-events: none; transition: background .2s ease; z-index: 40; }
.drawer-backdrop.open { background: rgba(0,0,0,.4); pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 400px; max-width: 92vw;
  background: hsl(var(--card)); border-left: 1px solid hsl(var(--border));
  transform: translateX(100%); transition: transform .25s ease;
  z-index: 41; display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer.drawer-lg { width: 560px; }
.drawer.drawer-xl { width: 672px; }
.drawer-group { margin-top: 16px; }
.drawer-group:first-child { margin-top: 0; }
.drawer-group-header { display: flex; align-items: center; gap: 8px; padding: 8px 0; font-size: 13px; font-weight: 600; }
.drawer-group-header .icon { color: hsl(var(--muted-foreground)); width: 15px; height: 15px; }
.drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid hsl(var(--border)); }
.drawer-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.drawer-body { padding: 20px; overflow-y: auto; flex: 1; }
.drawer-body .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.drawer-footer { display: flex; flex-direction: column; gap: 8px; padding: 16px 20px; border-top: 1px solid hsl(var(--border)); flex-shrink: 0; }
.drawer-footer-buttons { display: flex; gap: 10px; }
.drawer-footer-buttons .btn { flex: 1; }

.folder-browser-nav { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.folder-browser-nav .btn-icon { flex-shrink: 0; padding: 7px; }
.folder-browser-path {
  flex: 1; min-width: 0; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px;
  color: hsl(var(--foreground)); padding: 7px 10px;
  background: hsl(var(--accent)); border: 1px solid transparent; border-radius: calc(var(--radius) - 4px);
}
.folder-browser-path:focus { outline: none; border-color: hsl(var(--primary)); background: hsl(var(--background)); }
.folder-browser-search {
  width: 100%; box-sizing: border-box; padding: 7px 10px; margin-bottom: 10px; font-size: 13px;
  color: hsl(var(--foreground)); background: hsl(var(--background));
  border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 4px);
}
.folder-browser-search:focus { outline: none; border-color: hsl(var(--primary)); }
.folder-browser-list { display: flex; flex-direction: column; gap: 1px; }
.folder-browser-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: calc(var(--radius) - 4px);
  font-size: 13px; color: hsl(var(--foreground));
}
.folder-browser-row .icon { color: hsl(var(--muted-foreground)); flex-shrink: 0; }
.folder-browser-row.is-dir { cursor: pointer; }
.folder-browser-row.is-dir:hover { background: hsl(var(--accent)); }
.folder-browser-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-browser-date {
  flex-shrink: 0; width: 112px; text-align: right; font-size: 11.5px; color: hsl(var(--muted-foreground));
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (max-width: 480px) {
  .folder-browser-date { display: none; }
}
.folder-browser-download-btn {
  flex-shrink: 0; display: flex; align-items: center; justify-content: center; width: 26px; height: 26px;
  border: none; border-radius: calc(var(--radius) - 4px); color: hsl(var(--muted-foreground)); background: transparent; cursor: pointer;
}
.folder-browser-download-btn:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.folder-browser-download-btn .icon { width: 15px; height: 15px; }
.folder-browser-download-btn:disabled { opacity: .5; cursor: not-allowed; }
@keyframes folder-row-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.folder-browser-row { animation: folder-row-in .2s ease both; }

.folder-browser-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 60px 20px; color: hsl(var(--muted-foreground)); font-size: 13px; }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid hsl(var(--border)); border-top-color: hsl(var(--primary)); animation: spinner-rotate .7s linear infinite; }
@keyframes spinner-rotate { to { transform: rotate(360deg); } }

.btn.copied, .close-btn.copied { color: hsl(142 71% 45%); }

.password-field-wrap { position: relative; display: flex; }
.password-field-wrap input { flex: 1; padding-right: 34px; }
.password-toggle-btn {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center; width: 28px; height: 28px;
  border: none; background: transparent; cursor: pointer; color: hsl(var(--muted-foreground)); border-radius: calc(var(--radius) - 4px);
}
.password-toggle-btn:hover { color: hsl(var(--foreground)); background: hsl(var(--accent)); }
.password-toggle-btn .icon { width: 16px; height: 16px; }

/* Chi 2 trang thai duy nhat: xanh (online) hoac do (offline) — khong co mau trung gian
   nao khac, kem ca luc dang cho ket qua check dau tien (mac dinh offline cho toi khi
   duoc xac nhan online). */
.auth-switch-link { text-align: center; margin-top: 16px; font-size: 13px; color: hsl(var(--muted-foreground)); }
.auth-switch-link a { color: hsl(var(--primary)); text-decoration: none; font-weight: 500; }
.auth-switch-link a:hover { text-decoration: underline; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: #ef4444; animation: status-dot-pulse 1.6s ease-in-out infinite; }
.status-dot.online { background: #22c55e; }
.status-dot.offline { background: #ef4444; }
@keyframes status-dot-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.nav-item-folder-btn {
  flex-shrink: 0; display: flex; align-items: center; justify-content: center; width: 26px; height: 26px;
  border-radius: calc(var(--radius) - 4px); color: hsl(var(--muted-foreground)); background: transparent; border: none; cursor: pointer;
}
.nav-item-folder-btn:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.nav-item-folder-btn .icon { width: 15px; height: 15px; }

.term-filter-bar {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px;
  border-bottom: 1px solid hsl(var(--border)); background: hsl(var(--muted) / .3);
}
.term-filter-bar .label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: hsl(var(--muted-foreground)); }
.term-filter-bar select {
  font-size: 13px; padding: 5px 8px; border-radius: calc(var(--radius) - 4px); border: 1px solid hsl(var(--border));
  background: hsl(var(--background)); color: hsl(var(--foreground));
}

/* ---------- Scrollbar (webkit) ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: hsl(var(--border)); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground) / .4); }
