/* ============================================================
   Qian Nuo Partner Portal — new UI design system
   Ported from the BERUN distribution console (shadcn/ui tokens)
   ============================================================ */

:root {
  --background: #ffffff;
  --foreground: #171717;
  --card: #ffffff;
  --card-foreground: #171717;
  --popover: #ffffff;
  --popover-foreground: #171717;
  --primary: #171717;
  --primary-foreground: #fafafa;
  --secondary: #f5f5f5;
  --secondary-foreground: #171717;
  --muted: #f5f5f5;
  --muted-foreground: #707070;
  --accent: #f5f5f5;
  --accent-foreground: #171717;
  --destructive: #c92020;
  --destructive-foreground: #fafafa;
  --success: #1a7f37;
  --success-foreground: #ffffff;
  --warning: #d97706;
  --warning-foreground: #ffffff;
  --border: #e6e6e6;
  --input: #dedede;
  --ring: #171717;
  --sidebar-background: #fafafa;
  --sidebar-foreground: #424242;
  --sidebar-primary: #171717;
  --sidebar-primary-foreground: #fafafa;
  --sidebar-accent: #ededed;
  --sidebar-accent-foreground: #171717;
  --sidebar-border: #e8e8e8;
  --sidebar-ring: #171717;
  --radius: 0.5rem;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* { box-sizing: border-box; border: 0 solid var(--border); }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
  font-feature-settings: "rlig" 1, "calt" 1, "cv11" 1, "ss01" 1;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 0.9rem; color: var(--foreground); }
code, kbd, samp, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }

/* ---------- layout shell ---------- */
.app-shell { display: flex; height: 100vh; flex-direction: column; overflow: hidden; background: var(--background); }
.app-body { display: flex; flex: 1; min-height: 0; }

/* ---------- sidebar ---------- */
.sidebar {
  display: flex; flex-direction: column;
  width: 256px; flex-shrink: 0;
  background: var(--sidebar-background);
  border-right: 1px solid var(--sidebar-border);
  transition: width 0.2s ease;
  overflow: hidden;
}
.sidebar.collapsed { width: 56px; }
.sidebar-header {
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 16px;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-logo { font-size: 0.95rem; font-weight: 600; white-space: nowrap; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px; scrollbar-width: thin; }
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 9999px; }
.nav-group-label {
  padding: 8px 12px 4px; font-size: 0.72rem; font-weight: 500;
  color: var(--muted-foreground); text-transform: uppercase; letter-spacing: 0.05em;
  white-space: nowrap; overflow: hidden;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 12px; margin-bottom: 2px;
  border-radius: 6px; font-size: 0.875rem; font-weight: 500;
  color: var(--sidebar-foreground);
  background: transparent; text-align: left; white-space: nowrap;
}
.nav-item:hover { background: var(--sidebar-accent); color: var(--sidebar-accent-foreground); }
.nav-item.active { background: var(--sidebar-accent); color: var(--sidebar-accent-foreground); font-weight: 600; }
.nav-item .nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar.collapsed .nav-item span.nav-text { display: none; }
.sidebar.collapsed .nav-group-label { display: none; }
.sidebar.collapsed .sidebar-logo { display: none; }
.sidebar-footer { border-top: 1px solid var(--sidebar-border); padding: 12px; }
.sidebar-footer .nav-text { font-size: 0.8rem; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: rgb(255 255 255 / 0.95);
  backdrop-filter: blur(8px);
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  border-radius: 6px; background: transparent; color: var(--foreground);
}
.icon-btn:hover { background: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 0.875rem; min-width: 0; }
.breadcrumb .crumb { color: var(--muted-foreground); white-space: nowrap; }
.breadcrumb .crumb.active { color: var(--foreground); font-weight: 500; }
.breadcrumb .sep { color: var(--muted-foreground); opacity: 0.6; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.lang-select {
  height: 32px; padding: 0 8px; border-radius: 6px;
  background: var(--secondary); border: 1px solid transparent;
  color: var(--foreground); font-size: 0.85rem;
}
.lang-select:hover { background: var(--accent); }
.avatar-btn {
  display: flex; align-items: center; gap: 8px;
  margin-left: 4px; padding: 4px; border-radius: 6px; background: transparent;
}
.avatar-btn:hover { background: var(--accent); }
.avatar {
  width: 32px; height: 32px; border-radius: 9999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 600; color: #fff; flex-shrink: 0;
}
.avatar-name { font-size: 0.875rem; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.avatar-caret { width: 14px; height: 14px; opacity: 0.6; }

/* dropdown */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  min-width: 224px; padding: 6px;
  background: var(--popover); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow-md);
}
.dropdown-label { padding: 8px 8px 6px; }
.dropdown-label .name { font-size: 0.875rem; font-weight: 500; }
.dropdown-label .sub { font-size: 0.75rem; color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis; }
.dropdown-sep { height: 1px; background: var(--border); margin: 6px 0; }
.dropdown-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px; border-radius: 6px; font-size: 0.875rem;
  color: var(--foreground); background: transparent; text-align: left;
}
.dropdown-item:hover { background: var(--accent); }
.dropdown-item svg { width: 16px; height: 16px; }

/* ---------- main ---------- */
.main { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; }
.main::-webkit-scrollbar { width: 6px; height: 6px; }
.main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 9999px; }
.main-inner { margin: 0 auto; max-width: 1600px; padding: 16px; }
@media (min-width: 768px) { .main-inner { padding: 24px; } }
.page-content { display: flex; flex-direction: column; gap: 24px; }
.app-footer {
  flex-shrink: 0; border-top: 1px solid var(--border);
  background: var(--background); padding: 12px; text-align: center;
  font-size: 0.75rem; color: var(--muted-foreground);
}

/* ---------- page header ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.page-header h1 { margin: 0; font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; }
.page-header .sub { margin-top: 4px; font-size: 0.875rem; color: var(--muted-foreground); }
.page-header-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- cards ---------- */
.card {
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 24px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-title { font-size: 0.875rem; font-weight: 600; color: var(--primary); }
.card-muted { font-size: 0.875rem; color: var(--muted-foreground); }
.space-y > * + * { margin-top: 24px; }

/* stat cards */
.stat-grid { display: grid; gap: 20px; }
@media (min-width: 768px) { .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.stat-card { min-height: 150px; padding: 24px; }
.stat-label { font-size: 0.875rem; color: var(--muted-foreground); }
.stat-value { margin-top: 12px; font-size: 1.875rem; font-weight: 600; letter-spacing: -0.02em; }
.stat-value.accent { color: var(--primary); }
.stat-detail { margin-top: 8px; font-size: 0.875rem; color: var(--muted-foreground); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 16px;
  border-radius: 6px; font-size: 0.875rem; font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap; user-select: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-default { background: var(--primary); color: var(--primary-foreground); }
.btn-default:hover:not(:disabled) { background: #000; }
.btn-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.btn-secondary:hover:not(:disabled) { background: var(--accent); }
.btn-outline { background: transparent; color: var(--foreground); border: 1px solid var(--border); }
.btn-outline:hover:not(:disabled) { background: var(--accent); }
.btn-ghost { background: transparent; color: var(--foreground); }
.btn-ghost:hover:not(:disabled) { background: var(--accent); }
.btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.btn-destructive:hover:not(:disabled) { background: #b01c1c; }
.btn-destructive-ghost { background: transparent; color: var(--destructive); }
.btn-destructive-ghost:hover:not(:disabled) { background: rgb(201 32 32 / 0.08); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 0.8rem; }
.btn-icon { width: 30px; height: 30px; padding: 0; }
.btn-icon svg { width: 15px; height: 15px; }
.btn-block { width: 100%; }
.btn-link {
  background: none; padding: 0; height: auto; font-size: inherit;
  font-weight: 500; color: var(--primary); text-decoration: underline; text-underline-offset: 4px;
}
.btn-link:hover { text-decoration: underline; }

/* ---------- form controls ---------- */
.label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 6px; }
.input {
  display: block; width: 100%; height: 40px; padding: 0 12px;
  background: var(--background);
  border: 1px solid var(--input); border-radius: 6px;
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 1px var(--ring); }
.input::placeholder { color: var(--muted-foreground); }
.input:disabled { opacity: 0.5; cursor: not-allowed; }
input[type="date"].input { padding: 0 10px; }
.field { margin-bottom: 16px; }
.field-hint { font-size: 0.75rem; color: var(--muted-foreground); margin-top: 4px; }

/* ---------- alert / flash ---------- */
.alert {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 12px 16px; border-radius: 8px; font-size: 0.875rem;
  border: 1px solid;
}
.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; }
.alert-error { background: rgb(201 32 32 / 0.06); border-color: rgb(201 32 32 / 0.3); color: var(--destructive); }
.alert-success { background: rgb(26 127 55 / 0.06); border-color: rgb(26 127 55 / 0.3); color: var(--success); }

/* ---------- toast ---------- */
.toast-wrap {
  position: fixed; top: 16px; right: 16px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  display: flex; align-items: center; gap: 8px;
  min-width: 240px; max-width: 360px; padding: 12px 16px;
  background: #171717; color: #fff;
  border-radius: 8px; font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.2s ease;
}
.toast svg { width: 16px; height: 16px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- tables ---------- */
.table-card { overflow: hidden; border-radius: 10px; border: 1px solid var(--border); background: var(--card); box-shadow: var(--shadow-sm); }
.table-title { border-bottom: 1px solid var(--border); padding: 16px 24px; font-size: 0.875rem; color: var(--muted-foreground); }
.table-title.bold { font-size: 1rem; font-weight: 600; color: var(--foreground); }
.table-scroll { overflow-x: auto; }
table.tbl { width: 100%; min-width: 700px; border-collapse: collapse; text-align: left; font-size: 0.875rem; }
table.tbl thead { background: rgb(245 245 245 / 0.5); color: var(--muted-foreground); }
table.tbl th { padding: 16px 24px; font-weight: 500; white-space: nowrap; }
table.tbl td { padding: 16px 24px; border-top: 1px solid var(--border); }
table.tbl tbody tr:hover { background: var(--muted); }
.tbl-empty { padding: 64px 24px; text-align: center; color: var(--muted-foreground); }

/* grid table (accounts) */
.grid-table { display: grid; min-width: 1000px; }
.grid-table .gt-head, .grid-table .gt-row { display: grid; grid-template-columns: minmax(210px, 2fr) repeat(7, minmax(0, 1fr)); }
.grid-table .gt-head { background: rgb(245 245 245 / 0.4); color: var(--muted-foreground); font-size: 0.875rem; }
.grid-table .gt-head > div { padding: 16px 20px; font-weight: 500; white-space: nowrap; }
.grid-table .gt-row { border-top: 1px solid var(--border); font-size: 0.875rem; }
.grid-table .gt-row > div { padding: 16px 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid-table .gt-row > div.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 500; white-space: normal; overflow-wrap: anywhere; word-break: break-all; text-overflow: clip; }
.grid-table .gt-row .reward { color: var(--primary); font-weight: 500; }

/* pagination */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--border); }
.pager-info { font-size: 0.875rem; color: var(--muted-foreground); }
.pager-controls { display: flex; align-items: center; gap: 8px; }
.pager-controls .page-num { font-size: 0.875rem; color: var(--muted-foreground); }

/* ---------- badge ---------- */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px; border-radius: 9999px;
  font-size: 0.75rem; font-weight: 500;
}
.badge-green { background: rgb(26 127 55 / 0.1); color: var(--success); }
.badge-muted { background: var(--secondary); color: var(--muted-foreground); }

/* TOTP setup dialog */
.totp-qr {
  width: 168px; height: 168px;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: #fff;
  padding: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.totp-qr svg { display: block; }
.totp-secret {
  font-family: var(--font-mono);
  font-size: 12.5px;
  word-break: break-all;
  background: var(--accent);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 8px 10px;
  display: block;
  line-height: 1.5;
  user-select: all;
}

/* ---------- dialog ---------- */
.dialog-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgb(0 0 0 / 0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px; overflow-y: auto;
}
.dialog {
  background: var(--popover); color: var(--popover-foreground);
  border-radius: 10px; box-shadow: var(--shadow-md);
  width: 100%; max-width: 460px; margin-top: 8vh;
  animation: dialog-in 0.15s ease;
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 0; }
.dialog-head h3 { margin: 0; font-size: 1.125rem; font-weight: 600; letter-spacing: -0.01em; }
.dialog-body { padding: 16px 24px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 24px 24px; }
.dialog-close {
  width: 28px; height: 28px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--muted-foreground);
}
.dialog-close:hover { background: var(--accent); color: var(--foreground); }
.dialog-close svg { width: 16px; height: 16px; }

/* ---------- details (FAQ) ---------- */
details.faq { border-top: 1px solid var(--border); }
details.faq:last-child { border-bottom: 1px solid var(--border); }
details.faq summary {
  cursor: pointer; list-style: none; padding: 16px 24px;
  font-weight: 500; font-size: 0.95rem; display: flex; align-items: center; justify-content: space-between;
}
details.faq summary::-webkit-details-marker { display: none; }
details.faq summary .plus { color: var(--muted-foreground); transition: transform 0.2s; font-size: 1.1rem; line-height: 1; }
details.faq[open] summary .plus { transform: rotate(45deg); }
details.faq .faq-body { padding: 0 24px 20px; max-width: 720px; font-size: 0.875rem; line-height: 1.75; color: var(--muted-foreground); }

/* ---------- misc ---------- */
.divide-y > * + * { border-top: 1px solid var(--border); }
.row-between { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.row-between h2 { font-size: 0.95rem; font-weight: 500; margin: 0; }
.row-between p { margin: 4px 0 0; font-size: 0.875rem; color: var(--muted-foreground); }
.flex { display: flex; }
.flex-1 { flex: 1; min-width: 0; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--muted-foreground); }
.font-medium { font-weight: 500; }
.break-all { word-break: break-all; }
.underline { text-decoration: underline; text-underline-offset: 4px; }

/* ---------- auth layout ---------- */
.auth-bg { min-height: 100vh; display: flex; flex-direction: column; background: rgb(245 245 245 / 0.6); }
.auth-top { display: flex; align-items: center; justify-content: flex-end; gap: 4px; padding: 12px; }
.auth-main { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 16px 16px 40px; }
@media (min-width: 640px) { .auth-main { align-items: center; padding-top: 0; } }
.auth-card-wrap { width: 100%; max-width: 384px; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 24px; }
.auth-logo img { height: 48px; object-fit: contain; }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-md); padding: 24px; }
.auth-card h1 { margin: 0 0 16px; font-size: 1.25rem; font-weight: 600; text-align: center; }
.auth-footer { flex-shrink: 0; padding: 16px; text-align: center; font-size: 0.75rem; color: var(--muted-foreground); }
