/* =========================================================================
   Reusable UI components
   ========================================================================= */

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  height: 38px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--fg);
  font-weight: 600; font-size: 13.5px; transition: var(--transition); white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 31px; padding: 0 11px; font-size: 12.5px; }
.btn.lg { height: 46px; padding: 0 22px; font-size: 15px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; pointer-events: none; }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card.pad { padding: 18px; }
.card-title { font-weight: 700; font-size: 15px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.card-title .actions { margin-left: auto; display: flex; gap: 6px; }

/* ---- Stat tiles ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
  transition: var(--transition);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat .stat-ic {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  font-size: 19px; margin-bottom: 12px;
}
.stat .stat-label { font-size: 12.5px; color: var(--fg-muted); font-weight: 500; }
.stat .stat-value { font-size: 24px; font-weight: 800; margin-top: 2px; letter-spacing: -.02em; }
.stat .stat-sub { font-size: 11.5px; color: var(--fg-faint); margin-top: 3px; }
.tint-blue { background: var(--brand-soft); color: var(--brand); }
.tint-green { background: var(--success-soft); color: var(--success); }
.tint-amber { background: var(--warning-soft); color: var(--warning); }
.tint-red { background: var(--danger-soft); color: var(--danger); }
.tint-violet { background: #f3ecfe; color: #7c3aed; }
:root[data-theme="dark"] .tint-violet { background: #241a3a; color: #a78bfa; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); }
table.data th {
  background: var(--surface-2); font-weight: 600; color: var(--fg-muted);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; position: sticky; top: 0; z-index: 1;
}
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--fg-muted); }
.empty-state .big { font-size: 40px; margin-bottom: 10px; opacity: .6; }

/* ---- Badges ---- */
.badge-pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px;
  border-radius: 20px; font-size: 11.5px; font-weight: 600;
}
.badge-pill.green { background: var(--success-soft); color: var(--success); }
.badge-pill.amber { background: var(--warning-soft); color: var(--warning); }
.badge-pill.red { background: var(--danger-soft); color: var(--danger); }
.badge-pill.blue { background: var(--brand-soft); color: var(--brand); }
.badge-pill.gray { background: var(--surface-2); color: var(--fg-muted); }

/* ---- Forms ---- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.col-2 { grid-column: span 2; }
.field.col-full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--fg-muted); }
.field label .req { color: var(--danger); }
.field input, .field select, .field textarea {
  height: 38px; padding: 0 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--fg); font-size: 13.5px; font-family: inherit; transition: var(--transition);
  width: 100%;
}
.field textarea { height: auto; padding: 9px 11px; resize: vertical; min-height: 72px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field .hint { font-size: 11px; color: var(--fg-faint); }
.input-inline { display: flex; align-items: center; gap: 8px; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .search-box { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.toolbar .search-box input { width: 100%; height: 38px; padding: 0 12px 0 34px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--fg); }
.toolbar .search-box .ic { position: absolute; left: 11px; top: 10px; opacity: .5; }
.toolbar select { height: 38px; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200; background: rgba(15,23,42,.5);
  display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; animation: fadeIn .18s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 640px; animation: modalIn .22s cubic-bezier(.34,1.3,.5,1);
  border: 1px solid var(--border); margin: auto;
}
.modal.wide { max-width: 920px; }
.modal.narrow { max-width: 440px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(18px) scale(.97); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; font-weight: 700; }
.modal-head .close { margin-left: auto; }
.modal-body { padding: 22px; max-height: 68vh; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 16px 22px; border-top: 1px solid var(--border); }

/* ---- Toast ---- */
.toast-stack { position: fixed; bottom: 22px; right: 22px; z-index: 500; display: flex; flex-direction: column; gap: 10px; }
.toast {
  min-width: 260px; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--brand); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; animation: toastIn .3s cubic-bezier(.34,1.3,.5,1);
}
.toast.out { animation: toastOut .25s forwards; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warning); }
.toast .t-ic { font-size: 17px; }
.toast .t-body { flex: 1; }
.toast .t-title { font-weight: 700; font-size: 13.5px; }
.toast .t-msg { font-size: 12.5px; color: var(--fg-muted); }
.toast .t-action { color: var(--brand); font-weight: 600; font-size: 12.5px; background: none; border: none; padding: 4px 0 0; }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(40px); } }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab { padding: 9px 15px; font-weight: 600; font-size: 13.5px; color: var(--fg-muted); border-bottom: 2px solid transparent; transition: var(--transition); }
.tab:hover { color: var(--fg); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---- Misc ---- */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.kbd { display: inline-block; padding: 1px 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-2); font-family: var(--mono); font-size: 11px; }
.muted { color: var(--fg-muted); }
.text-right { text-align: right; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* progress bar */
.progress { height: 7px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 6px; transition: width .4s; }

/* ---- Lock / login screen ---- */
.lock-screen {
  position: fixed; inset: 0; z-index: 1000;
  background: radial-gradient(1200px 600px at 50% -10%, var(--brand-soft), var(--bg));
  display: grid; place-items: center; padding: 20px; animation: fadeIn .3s;
}
.lock-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 32px 28px; width: 100%; max-width: 380px; text-align: center;
  animation: modalIn .3s cubic-bezier(.34,1.3,.5,1);
}
.lock-logo {
  width: 76px; height: 76px; margin: 0 auto 16px; border-radius: 18px; background: #fff;
  display: grid; place-items: center; overflow: hidden; box-shadow: var(--shadow-sm); font-size: 30px; font-weight: 800; color: var(--brand);
  border: 1px solid var(--border);
}
.lock-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lock-card h2 { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.lock-card > p { font-size: 13px; margin-bottom: 18px; }
.lock-form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.lock-form input {
  height: 44px; padding: 0 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--fg); font-size: 15px; transition: var(--transition);
}
.lock-form input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); background: var(--surface); }
.lock-err { color: var(--danger); font-size: 12.5px; min-height: 16px; font-weight: 600; }
.lock-forgot { text-align: center; color: var(--brand); font-size: 13px; font-weight: 600; margin-top: 4px; }
.lock-forgot:hover { text-decoration: underline; }

/* simple bar chart */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 180px; padding-top: 10px; }
.bars .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .bar { width: 70%; max-width: 46px; background: linear-gradient(180deg, var(--brand), var(--brand-700)); border-radius: 6px 6px 0 0; transition: height .5s cubic-bezier(.4,0,.2,1); min-height: 2px; position: relative; }
.bars .bar:hover::after { content: attr(data-val); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--surface); font-size: 10px; padding: 2px 6px; border-radius: 4px; white-space: nowrap; margin-bottom: 4px; }
.bars .bar-label { font-size: 10.5px; color: var(--fg-muted); }
