:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f7f9fd;
  --surface-3: #eef3fa;
  --border: #e4e9f2;
  --border-strong: #d3dae7;
  --text: #1b2537;
  --text-2: #3f4a5f;
  --muted: #6f7a90;
  --muted-2: #9aa4b6;
  --accent: #2f6fed;
  --accent-hover: #245fd1;
  --accent-soft: #eaf1ff;
  --green: #16a36a;
  --green-soft: #e7f7f0;
  --red: #e5484d;
  --red-soft: #fdecec;
  --amber: #df8b0b;
  --amber-soft: #fff4df;
  --violet: #7c5cff;
  --violet-soft: #f0edff;
  --cyan: #0891b2;
  --cyan-soft: #e6f7fb;
  --sidebar: #172136;
  --sidebar-2: #202d48;
  --sidebar-text: #aab6cd;
  --sidebar-muted: #7c8aa5;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-xs: 0 1px 2px rgba(20, 31, 51, 0.05);
  --shadow-sm: 0 1px 2px rgba(20, 31, 51, 0.05), 0 4px 14px rgba(20, 31, 51, 0.05);
  --shadow-md: 0 10px 40px rgba(20, 31, 51, 0.14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; }
::selection { background: #cddcff; color: #10224a; }

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn .icon { width: 17px; height: 17px; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: 0 3px 10px rgba(47, 111, 237, .22); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text-2); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--surface-2); border-color: #c2cadb; }
.btn-ghost { color: var(--muted); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-danger { color: var(--red); background: var(--red-soft); border-color: transparent; }
.btn-danger:hover { background: #fbdcdd; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn-sm .icon { width: 15px; height: 15px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn .icon { width: 19px; height: 19px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .01em; }
.label .req { color: var(--red); }
.input, .select, .textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.input::placeholder, .textarea::placeholder { color: var(--muted-2); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, .12);
}
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--muted); }
.textarea { resize: vertical; min-height: 82px; line-height: 1.5; }
.select { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236f7a90' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; }
.input-sm { min-height: 32px; padding: 5px 9px; font-size: 12.5px; border-radius: 7px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-hint { font-size: 11.5px; color: var(--muted-2); }
.form-error { display: none; padding: 9px 12px; border-radius: 8px; background: var(--red-soft); color: #b4232a; font-size: 12.5px; }
.form-error.show { display: block; }
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
input[type="color"] { width: 34px; height: 34px; padding: 3px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); cursor: pointer; }

/* Text helpers */
.muted { color: var(--muted); }
.muted-2 { color: var(--muted-2); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.semibold { font-weight: 600; }
.bold { font-weight: 700; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: .92em; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.text-accent { color: var(--accent); }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

/* Avatar */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: .01em;
  user-select: none;
}
.avatar-sm { width: 25px; height: 25px; font-size: 9.5px; }
.avatar-lg { width: 42px; height: 42px; font-size: 14px; }
.avatar-xl { width: 60px; height: 60px; font-size: 19px; }
.avatar-square { border-radius: 10px; }
.avatar-stack { display: flex; }
.avatar-stack .avatar { border: 2px solid var(--surface); margin-left: -7px; }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-green { background: var(--green-soft); color: #0b7c4f; }
.badge-red { background: var(--red-soft); color: #bd2b30; }
.badge-amber { background: var(--amber-soft); color: #a86500; }
.badge-blue { background: var(--accent-soft); color: #245fd1; }
.badge-violet { background: var(--violet-soft); color: #6146d9; }
.badge-gray { background: #eef1f6; color: #68748a; }
.badge-outline { background: transparent; border: 1px solid var(--border-strong); color: var(--muted); }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14px; font-weight: 700; letter-spacing: -.01em; }
.card-subtitle { margin-top: 2px; font-size: 12px; color: var(--muted); }
.card-body { padding: 16px 18px; }
.card-footer { padding: 13px 18px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* Tables */
.table-wrap { overflow: auto; border-radius: var(--radius); }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}
.table td { padding: 11px 12px; 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.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: #f8faff; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { width: 1%; white-space: nowrap; text-align: right; }

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(17, 26, 45, .48);
  backdrop-filter: blur(2px);
  animation: fadeIn .16s ease-out;
}
.overlay.closing { animation: fadeOut .14s ease-in forwards; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* Modal */
.modal {
  position: fixed;
  z-index: 121;
  top: 50%;
  left: 50%;
  display: flex;
  flex-direction: column;
  width: calc(100vw - 32px);
  max-width: 600px;
  max-height: calc(100vh - 48px);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transform: translate(-50%, -48%) scale(.98);
  opacity: 0;
  animation: modalIn .18s ease-out forwards;
}
@keyframes modalIn { to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
.modal.modal-sm { max-width: 460px; }
.modal.modal-lg { max-width: 760px; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 20px 22px 0; }
.modal-heading { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.modal-sub { margin-top: 3px; color: var(--muted); font-size: 12.5px; }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 9px; padding: 15px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.modal-footer .left { margin-right: auto; }

/* Drawer */
.drawer-overlay { z-index: 100; background: rgba(17, 26, 45, .4); }
.drawer {
  position: fixed;
  z-index: 101;
  top: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  width: min(620px, 100vw);
  height: 100dvh;
  background: var(--surface);
  box-shadow: -14px 0 50px rgba(20, 31, 51, .16);
  transform: translateX(100%);
  animation: drawerIn .22s cubic-bezier(.22, .8, .3, 1) forwards;
}
.drawer.drawer-wide { width: min(720px, 100vw); }
@keyframes drawerIn { to { transform: translateX(0); } }
.drawer.closing { animation: drawerOut .16s ease-in forwards; }
@keyframes drawerOut { to { transform: translateX(100%); } }
.drawer-header { display: flex; align-items: flex-start; gap: 14px; padding: 20px 22px 16px; border-bottom: 1px solid var(--border); }
.drawer-title { font-size: 18px; font-weight: 700; letter-spacing: -.02em; line-height: 1.25; }
.drawer-sub { margin-top: 4px; color: var(--muted); font-size: 12.5px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px 22px 28px; }
.drawer-footer { display: flex; align-items: center; gap: 9px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); }
.drawer-footer .left { margin-right: auto; }
.drawer-close { margin-left: auto; flex: 0 0 auto; }

/* Toasts */
.toast-root { position: fixed; z-index: 300; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 9px; width: min(380px, calc(100vw - 32px)); }
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  color: var(--text-2);
  font-size: 13px;
  animation: toastIn .18s ease-out;
}
.toast.success { border-color: #bfe8d6; }
.toast.success .toast-icon { color: var(--green); }
.toast.error { border-color: #f6c9ca; }
.toast.error .toast-icon { color: var(--red); }
.toast-icon { flex: 0 0 auto; margin-top: 1px; }
.toast.removing { animation: toastOut .16s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }

/* Empty / loading */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 54px 24px; text-align: center; }
.empty-icon { display: flex; align-items: center; justify-content: center; width: 54px; height: 54px; margin-bottom: 14px; border-radius: 16px; background: var(--surface-3); color: var(--muted); }
.empty-icon .icon { width: 25px; height: 25px; }
.empty-title { font-size: 15px; font-weight: 700; }
.empty-text { max-width: 360px; margin-top: 5px; color: var(--muted); font-size: 12.5px; }
.empty-action { margin-top: 16px; }
.skeleton { border-radius: 7px; background: linear-gradient(90deg, #edf1f7 25%, #f6f8fc 37%, #edf1f7 63%); background-size: 400% 100%; animation: shimmer 1.3s infinite linear; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.spinner { width: 18px; height: 18px; border: 2px solid rgba(47,111,237,.2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Scrollbar */
* { scrollbar-width: thin; scrollbar-color: #cbd4e3 transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: #cbd4e3; border-radius: 99px; }
*::-webkit-scrollbar-thumb:hover { background: #b4bfd2; }
*::-webkit-scrollbar-track { background: transparent; }

/* Focus */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:focus-visible, .icon-btn:focus-visible { outline-offset: 1px; }

/* Boot */
.boot { position: fixed; inset: 0; z-index: 400; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--bg); }
.boot-logo { display: flex; align-items: center; justify-content: center; width: 52px; height: 52px; margin-bottom: 22px; border-radius: 15px; background: linear-gradient(135deg, #3b82f6, #1d4ed8); color: #fff; font-size: 26px; font-weight: 800; box-shadow: 0 10px 30px rgba(47,111,237,.3); }
.boot-spinner { width: 24px; height: 24px; border: 2.5px solid #dbe4f4; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.boot-text { margin-top: 12px; color: var(--muted); font-size: 12px; }
.noscript { position: fixed; inset: auto 16px 16px; z-index: 500; padding: 14px 16px; border: 1px solid var(--red); border-radius: 10px; background: var(--red-soft); color: #a51d22; }

/* Generic page pieces */
.page-stack { display: flex; flex-direction: column; gap: 18px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.toolbar-search { position: relative; min-width: 220px; max-width: 340px; flex: 1; }
.toolbar-search .icon { position: absolute; top: 50%; left: 11px; width: 17px; height: 17px; transform: translateY(-50%); color: var(--muted-2); pointer-events: none; }
.toolbar-search .input { padding-left: 35px; }
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.segmented button { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--accent-soft); color: var(--accent); }
.segmented button .icon { width: 15px; height: 15px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; padding: 11px 15px 12px; border: 0; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); }
.tab.active::after { content: ""; position: absolute; left: 13px; right: 13px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); }
.tab .count { margin-left: 6px; padding: 1px 6px; border-radius: 99px; background: var(--surface-3); color: var(--muted); font-size: 10.5px; }
.divider { height: 1px; background: var(--border); }

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .modal { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .modal-header { padding: 16px 16px 0; }
  .modal-body { padding: 14px 16px; }
  .modal-footer { padding: 12px 16px; }
  .drawer-header { padding: 16px; }
  .drawer-body { padding: 16px; }
  .drawer-footer { padding: 12px 16px; }
  .toast-root { right: 12px; bottom: 12px; width: calc(100vw - 24px); }
}
