/* ============================================================
   drillbaby.ai admin panel.
   Self-contained (independent of the Tailwind build) and written with the
   same tokens as the React app's shadcn "zinc" theme (client/src/index.css):
   white surfaces, zinc-950 text, zinc-200 hairlines, zinc-900 primary
   buttons, 0.5rem radius, the system sans stack. The rust wordmark is the
   only accent, as on the landing page.
   ============================================================ */
:root {
  --bg: #ffffff;
  --bg-muted: #fafafa;
  --surface: #ffffff;
  --secondary: #f4f4f5;
  --border: #e4e4e7;
  --input: #e4e4e7;
  --text: #09090b;
  --text-muted: #71717a;
  --text-subtle: #a1a1aa;
  --primary: #18181b;
  --primary-hover: #27272a;
  --primary-fg: #fafafa;
  --ring: #a1a1aa;
  --brand: #9a3412;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #b91c1c;
  --success-soft: #f0fdf4;
  --success-border: #bbf7d0;
  --success-text: #15803d;
  --info-soft: #f4f4f5;
  --info-text: #3f3f46;
  --radius: 0.5rem;
  --radius-md: calc(var(--radius) - 2px);
  --shadow-sm: 0 1px 2px rgba(9, 9, 11, .05);
  --shadow-lg: 0 10px 15px -3px rgba(9, 9, 11, .1), 0 4px 6px -4px rgba(9, 9, 11, .1);
  --sidebar-w: 256px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.nowrap { white-space: nowrap; }
.material-symbols-outlined {
  font-variation-settings: 'wght' 400, 'opsz' 20;
  vertical-align: middle;
  line-height: 1;
  font-size: 20px;
}
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* ---- Brand ---- */
.brand { display: flex; align-items: center; gap: 8px; }
.brand-icon { height: 28px; width: 28px; border-radius: 7px; flex-shrink: 0; }
.avatar-img { object-fit: cover; }
.user-cell { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; color: var(--brand); }
.brand-tag { font-size: 11px; font-weight: 600; color: var(--text-muted); background: var(--secondary); border-radius: 999px; padding: 2px 8px; }
.brand-light .brand-mark { color: #fdba74; }
.brand-light .brand-tag { color: #d4d4d8; background: rgba(255, 255, 255, .12); }

/* ---- Sign-in (split panel) ---- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 45% 1fr; }
.auth-panel {
  background: var(--primary);
  color: #fafafa;
  padding: 48px;
  display: flex; flex-direction: column; justify-content: space-between;
  background-image:
    linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px);
  background-size: 48px 48px;
}
.auth-panel-line { margin: 20px 0 0; font-size: 18px; color: #d4d4d8; max-width: 26ch; }
.auth-panel-foot { margin: 0; font-size: 12px; color: #71717a; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 48px 24px; }
.auth-form { width: 100%; max-width: 400px; }
.auth-title { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.auth-sub { color: var(--text-muted); margin: 6px 0 24px; }
.auth-help { color: var(--text-muted); font-size: 13px; margin: 20px 0 0; }
@media (max-width: 800px) {
  .auth { grid-template-columns: 1fr; }
  .auth-panel { padding: 28px 24px; }
  .auth-panel-foot { display: none; }
}

/* ---- App shell (classic sidebar) ---- */
.app { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) 1fr; }
.sidebar {
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex; flex-direction: column; gap: 24px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 0 0 0 4px; min-width: 0; }
.sidebar-head .brand { min-width: 0; gap: 6px; }
.sidebar-head .brand-mark { font-size: 18px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-head .brand-tag { flex-shrink: 0; }
.sidebar-toggle { flex-shrink: 0; }
/* Collapsed sidebar: icons only, labels hidden. */
.app-collapsed { grid-template-columns: 64px 1fr; }
.app-collapsed .sidebar { padding: 24px 12px; }
.app-collapsed .sidebar-head { padding: 0; justify-content: center; }
.app-collapsed .brand, .app-collapsed .nav-label, .app-collapsed .me-text { display: none; }
.app-collapsed .nav-item, .app-collapsed .btn-ghost { justify-content: center; padding-left: 0; padding-right: 0; }
.app-collapsed .me { justify-content: center; padding: 0; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-md);
  color: var(--text); text-decoration: none; font-size: 14px; font-weight: 500;
}
.nav-item:hover { background: var(--secondary); }
.nav-item-active { background: var(--secondary); }
.nav-item .material-symbols-outlined { color: var(--text-muted); }
.sidebar-foot { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); padding-top: 16px; }
.me { display: flex; align-items: center; gap: 10px; padding: 0 4px; min-width: 0; }
.me-text { min-width: 0; }
.me-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-email { color: var(--text-muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { height: 32px; width: 32px; border-radius: 999px; background: var(--secondary); color: var(--text); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.content { padding: 32px 40px 64px; min-width: 0; max-width: 1280px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-title { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
@media (max-width: 900px) {
  .app, .app-collapsed { grid-template-columns: 1fr; }
  .sidebar-toggle { display: none; }
  .app-collapsed .brand, .app-collapsed .nav-label, .app-collapsed .me-text { display: revert; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); padding: 16px; gap: 12px; }
  .nav { flex-direction: row; }
  .sidebar-foot { flex-direction: row; align-items: center; justify-content: space-between; border-top: none; padding-top: 0; }
  .sidebar-foot form { width: auto; }
  .content { padding: 24px 16px 48px; }
}

/* ---- Cards ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.stat-card { padding: 20px 24px; }
.stat-label { font-size: 14px; color: var(--text-muted); }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; margin-top: 4px; }
@media (max-width: 720px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

/* ---- Toolbar ---- */
.toolbar { display: flex; gap: 16px; padding: 16px 20px; margin-bottom: 16px; flex-wrap: wrap; align-items: flex-end; }
.toolbar-field { display: flex; flex-direction: column; gap: 6px; min-width: 180px; }
.toolbar-search { flex: 1; min-width: 240px; }
.search { position: relative; }
.search .search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 18px; pointer-events: none; }
.search .input { padding-left: 36px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; font: inherit; font-size: 14px; font-weight: 500;
  border-radius: var(--radius-md); border: 1px solid transparent; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn .material-symbols-outlined { font-size: 18px; }
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--input); }
.btn-outline:hover { background: var(--secondary); }
.btn-ghost { background: transparent; color: var(--text); justify-content: flex-start; }
.btn-ghost:hover { background: var(--secondary); }
.btn-ghost .material-symbols-outlined { color: var(--text-muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-block { width: 100%; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  height: 32px; width: 32px; border-radius: var(--radius-md);
  border: none; background: transparent; color: var(--text-muted); cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--secondary); color: var(--text); }
.btn-icon .material-symbols-outlined { font-size: 19px; }
.btn-icon-danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn-icon-success:hover { background: var(--success-soft); color: var(--success-text); }
.btn-icon-placeholder { cursor: default; }
.spinner { height: 16px; width: 16px; }

/* ---- Forms ---- */
.field { margin-bottom: 16px; }
.label { display: block; font-size: 14px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.input, .select {
  width: 100%; height: 40px; font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--input); border-radius: var(--radius-md);
  padding: 0 12px; outline: none; transition: box-shadow .15s;
}
.input::placeholder { color: var(--text-muted); }
.input:focus, .select:focus { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ring); }
.select { appearance: none; -webkit-appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; }
.input-group {
  display: flex; align-items: center; height: 40px;
  border: 1px solid var(--input); border-radius: var(--radius-md); padding: 0 4px 0 12px;
  background: var(--surface); transition: box-shadow .15s;
}
.input-group:focus-within { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ring); }
.input-group input { flex: 1; min-width: 0; border: none; outline: none; height: 100%; font: inherit; font-size: 14px; background: transparent; color: var(--text); }
.input-group input::placeholder { color: var(--text-muted); }
.input-group .toggle { height: 32px; width: 32px; border: none; background: none; color: var(--text-muted); cursor: pointer; border-radius: var(--radius-md); display: inline-flex; align-items: center; justify-content: center; }
.input-group .toggle:hover { color: var(--text); background: var(--secondary); }
.input-group .toggle .material-symbols-outlined { font-size: 19px; }

/* ---- Table ---- */
.table-card { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table thead th { text-align: left; font-size: 14px; font-weight: 500; color: var(--text); background: var(--bg-muted); padding: 12px 20px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tbody td { padding: 12px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-muted); }
.ta-right { text-align: right; }
.user-name { font-weight: 500; }
.user-email { color: var(--text-muted); font-size: 13px; }
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 2px; }
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 14px; }
.table-foot { flex-wrap: wrap; }
.pager { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pager-per { display: flex; align-items: center; gap: 8px; }
.select-sm { height: 32px; width: auto; padding-right: 28px; font-size: 13px; }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; }
.btn-sm .material-symbols-outlined { font-size: 16px; }
.row-inactive .user-name, .row-inactive .user-email { color: var(--text-muted); }

/* ---- Badges ---- */
.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge-role { background: var(--secondary); color: var(--text); }
.badge-active { background: var(--success-soft); color: var(--success-text); }
.badge-inactive { background: var(--secondary); color: var(--text-muted); }
.badge-attention { background: var(--danger-soft); color: var(--danger-text); }

/* ---- Skeletons (first load) and in-flight dimming (htmx requests) ---- */
.skeleton { background: var(--secondary); border-radius: var(--radius-md); animation: pulse 1.6s ease-in-out infinite; }
.skeleton-text { height: 14px; margin: 4px 0; }
.skeleton-sm { height: 12px; }
.skeleton-value { height: 30px; width: 56px; margin-top: 8px; }
.skeleton-pill { height: 22px; width: 72px; border-radius: 999px; }
.skeleton-icon { height: 24px; width: 24px; }
.skeleton-row { display: flex; align-items: center; gap: 20px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.skeleton-head { background: var(--bg-muted); }
.skeleton-cell { display: flex; flex-direction: column; justify-content: center; }
.skeleton-actions { margin-left: auto; flex-direction: row; gap: 8px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
#users-container.htmx-request { opacity: .6; transition: opacity .15s; }

/* ---- Empty / loading ---- */
.empty { text-align: center; padding: 56px 24px; color: var(--text-muted); }
.empty-icon { font-size: 36px; color: var(--text-subtle); display: block; margin: 0 auto 8px; }
.empty p { margin: 0; }
.loading { padding: 24px 0; color: var(--text-muted); }

/* ---- Alerts ---- */
.alert { border-radius: var(--radius-md); padding: 10px 12px; font-size: 14px; margin-bottom: 16px; border: 1px solid transparent; }
.alert-error { background: var(--danger-soft); color: var(--danger-text); border-color: var(--danger-border); }
.alert-success { background: var(--success-soft); color: var(--success-text); border-color: var(--success-border); }
.alert-info { background: var(--info-soft); color: var(--info-text); border-color: var(--border); }

/* ---- Modal ---- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(9, 9, 11, .5); padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 440px; padding: 24px; position: relative; }
.modal-title { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 4px; padding-right: 28px; }
.modal-sub { font-size: 14px; color: var(--text-muted); margin: 0 0 20px; }
.modal-close { position: absolute; top: 14px; right: 14px; color: var(--text-muted); cursor: pointer; background: none; border: none; display: inline-flex; padding: 4px; border-radius: var(--radius-md); }
.modal-close:hover { color: var(--text); background: var(--secondary); }
.modal-close .material-symbols-outlined { font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---- Toast ---- */
.toast-area { position: fixed; bottom: 24px; right: 24px; z-index: 60; width: calc(100% - 32px); max-width: 360px; pointer-events: none; }
.toast-area .alert { pointer-events: auto; box-shadow: var(--shadow-lg); }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--primary); color: var(--primary-fg);
  border-radius: var(--radius-md); padding: 12px 14px; font-size: 14px;
  box-shadow: var(--shadow-lg); animation: toast-in .2s ease-out;
}
.toast .material-symbols-outlined { color: #86efac; font-size: 18px; }
.toast-problem { background: var(--danger); color: #fff; }
.toast-problem .material-symbols-outlined { color: #fecaca; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- Spinner ---- */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-block; }

/* A link inside a table cell, to another section of the panel. It keeps the
   table's own colour and says it is a link with an underline, not with blue. */
.table a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.table a:hover { color: var(--text); }
