/* ==========================================================================
   Management portal
   ========================================================================== */

/* --- Shell ---------------------------------------------------------------- */

.shell { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: 264px;
  display: flex; flex-direction: column;
  background: var(--bg-elevated); border-right: 1px solid var(--border);
  transition: transform .3s var(--ease);
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 20px 16px 12px 20px; }
.brand-stack { display: grid; gap: 6px; justify-items: start; }
.brand-stack small { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand-text strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { font-size: 12px; color: var(--text-3); }
.sidebar-close { display: none; }

.nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 12px; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px; border-radius: 10px;
  font-size: 14px; font-weight: 500; color: var(--text-2); transition: background-color .15s, color .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.is-active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.nav-sep { height: 1px; background: var(--border); margin: 10px 12px; }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); display: grid; gap: 8px; }
.me { display: flex; align-items: center; gap: 10px; padding: 4px 4px 0; min-width: 0; }
.me-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.me-text strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { font-size: 12px; color: var(--text-3); }
.me-actions { display: flex; gap: 4px; }
.me-actions form { display: contents; }

.avatar {
  display: grid; place-items: center; width: 36px; height: 36px; flex-shrink: 0; border-radius: 999px;
  font-size: 14px; font-weight: 700; color: var(--brand-text); background: var(--brand-soft);
}
.avatar-sm { width: 32px; height: 32px; font-size: 13px; }

.main { flex: 1; min-width: 0; margin-left: 264px; display: flex; flex-direction: column; }
.mobile-bar { display: none; }
.content { width: 100%; max-width: 1120px; margin: 0 auto; padding: 32px 32px 64px; }

.backdrop { display: none; }

@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar-close { display: inline-grid; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open { overflow: hidden; }
  .backdrop {
    display: block; position: fixed; inset: 0; z-index: 30; background: rgba(16, 24, 40, .45);
    opacity: 0; pointer-events: none; transition: opacity .3s;
  }
  body.nav-open .backdrop { opacity: 1; pointer-events: auto; }
  .main { margin-left: 0; }
  .mobile-bar {
    position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; height: 60px; padding: 0 12px 0 8px;
    background: color-mix(in oklab, var(--bg) 85%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
  }
  .mobile-title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .content { padding: 24px 16px 48px; }
}

/* --- Page header ---------------------------------------------------------- */

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { font-size: 26px; font-weight: 700; letter-spacing: -.025em; }
.page-head .muted { margin-top: 4px; }
@media (max-width: 639px) {
  .page-head h1 { font-size: 22px; }
  .page-head > .btn { width: 100%; }
}
.back-link { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 12px; font-size: 14px; font-weight: 500; color: var(--text-3); }
.back-link:hover { color: var(--text); }
.link { color: var(--brand-text); font-weight: 500; }
.link:hover { text-decoration: underline; }

/* --- Toasts & alerts ------------------------------------------------------ */

.toasts { position: fixed; top: 16px; right: 16px; z-index: 60; display: grid; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 12px 12px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 500; animation: toast-in .35s var(--ease) both;
}
.toast > .icon { margin-top: 1px; }
.toast span { flex: 1; }
.toast-success > .icon, .toast-info > .icon { color: var(--green); }
.toast-error > .icon, .toast-warning > .icon { color: var(--red); }
.toast-close { display: grid; place-items: center; width: 22px; height: 22px; border: 0; border-radius: 6px; background: transparent; color: var(--text-3); }
.toast-close:hover { background: var(--surface-2); }
.toast.is-leaving { animation: toast-out .25s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(12px); } }

.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; font-size: 14px; margin-bottom: 16px; }
.alert-error { background: var(--red-soft); color: var(--red-text); }

/* --- Stats & panels ------------------------------------------------------- */

.stats { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); margin-bottom: 24px; }
.stat {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "label icon" "value icon" "meta meta";
  row-gap: 2px; padding: 20px; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-xs); transition: border-color .2s, box-shadow .2s, transform .2s var(--ease);
}
a.stat:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-icon { grid-area: icon; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--brand-soft); color: var(--brand-text); }
.stat-label { grid-area: label; font-size: 13px; font-weight: 500; color: var(--text-3); }
.stat-value { grid-area: value; font-size: 30px; font-weight: 700; letter-spacing: -.03em; line-height: 1.2; }
.stat-meta { grid-area: meta; margin-top: 6px; font-size: 13px; color: var(--text-3); }

.panels { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }
.panel { padding: 20px; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-xs); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-head h2 { font-size: 15px; font-weight: 600; }
.panel-head .link { font-size: 13px; }
.panel-empty { padding: 24px 0 8px; color: var(--text-3); font-size: 14px; }

.mini-icon {
  display: grid; place-items: center; width: 36px; height: 36px; flex-shrink: 0; overflow: hidden; border-radius: 10px;
  background: color-mix(in oklab, var(--accent, var(--brand)) 12%, var(--surface));
  border: 1px solid color-mix(in oklab, var(--accent, var(--brand)) 16%, transparent);
  color: var(--accent, var(--brand)); font-size: 12px; font-weight: 700;
}
.mini-icon img { width: 24px; height: 24px; object-fit: contain; }
.mini-icon-plain { background: var(--surface-2); border-color: transparent; color: var(--text-3); }

.rank, .list { list-style: none; margin: 0; padding: 0; display: grid; }
.rank li, .list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.list li + li, .rank li + li { border-top: 1px solid var(--border); }
.rank-body { flex: 1; min-width: 0; display: grid; gap: 6px; }
.rank-row { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.rank-row span { color: var(--text-3); font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: inherit; background: var(--accent, var(--brand)); }

.list-body { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 14px; }
.list-body small { color: var(--text-3); font-size: 12px; }

.pill, .pill-btn {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--text-2); border: 0;
}
.pill-green { background: var(--green-soft); color: var(--green-text); }
.pill-red { background: var(--red-soft); color: var(--red-text); }
.pill-blue { background: var(--blue-soft); color: var(--blue-text); }
.pill-brand { background: var(--brand-soft); color: var(--brand-text); }
.pill-btn { height: 28px; transition: filter .15s, box-shadow .15s; }
.pill-btn:hover { box-shadow: inset 0 0 0 1px currentColor; }

/* --- Toolbar -------------------------------------------------------------- */

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.toolbar-search { position: relative; flex: 1 1 260px; }
.toolbar-search .input { padding-left: 38px; }
.toolbar-search .search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.toolbar .select { flex: 0 1 180px; }
@media (max-width: 639px) {
  .toolbar .select { flex: 1 1 calc(50% - 4px); }
  .toolbar .btn { flex: 1; }
}

/* --- Tables (become cards on small screens) ------------------------------- */

.table-card { border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-xs); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  padding: 12px 16px; text-align: left; font-size: 12px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
  color: var(--text-3); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color .15s; }
.table tbody tr:hover { background: var(--surface-hover); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table form { margin: 0; }
.col-handle { width: 40px; padding-right: 0 !important; }
.col-actions { width: 1%; white-space: nowrap; }
.drag-handle { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; color: var(--text-3); cursor: grab; touch-action: none; }
.drag-handle:hover { background: var(--surface-2); color: var(--text); }
.sortable-ghost { opacity: .4; background: var(--brand-soft) !important; }
.sortable-chosen { box-shadow: var(--shadow-md); }

.app-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.app-cell-text { display: flex; flex-direction: column; min-width: 0; }
.row-title { font-weight: 600; color: var(--text); }
.row-title:hover { color: var(--brand-text); }
.row-sub { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
a.row-sub:hover { color: var(--text); }
.row-actions { display: flex; justify-content: flex-end; gap: 2px; }
.table-foot { margin-top: 12px; font-size: 13px; }

@media (max-width: 767px) {
  .table-card { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .table thead { display: none; }
  .table, .table tbody { display: block; }
  .table tbody { display: grid; gap: 12px; }
  .table tbody tr {
    display: grid; grid-template-columns: auto 1fr auto; align-items: center; column-gap: 8px;
    padding: 14px; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-xs);
  }
  .table tbody tr:hover { background: var(--surface); }
  .table td { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border: 0; text-align: left; }
  .table td.num { text-align: left; }
  .table td[data-label] { grid-column: 1 / -1; border-top: 1px solid var(--border); font-size: 13px; }
  .table td[data-label]::before { content: attr(data-label); color: var(--text-3); font-weight: 500; }
  .table td.col-handle { grid-column: 1; width: auto; }
  .table td.cell-main { grid-column: 2; min-width: 0; padding-top: 0; }
  .table tr:not(:has(.col-handle)) td.cell-main { grid-column: 1 / 3; }
  .table td.col-actions { grid-column: 3; grid-row: 1; width: auto; padding-top: 0; }
}

.empty-panel {
  display: grid; justify-items: center; gap: 8px; padding: 56px 20px; text-align: center;
  border-radius: var(--radius-lg); border: 1px dashed var(--border-strong); background: var(--surface);
}
.empty-panel h2 { font-size: 17px; }
.empty-panel .muted { max-width: 420px; margin-bottom: 8px; }
.empty-panel .btn { margin-top: 4px; }
.empty-icon { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 4px; border-radius: 14px; background: var(--surface-2); color: var(--text-3); }

/* --- Forms ---------------------------------------------------------------- */

.form-layout { display: grid; gap: 24px; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
.form-layout.single { grid-template-columns: minmax(0, 760px); gap: 16px; }
.form-main { display: grid; gap: 16px; min-width: 0; }
@media (max-width: 1023px) { .form-layout { grid-template-columns: minmax(0, 1fr); } }

.form-panel { display: grid; gap: 18px; padding: 24px; }
@media (max-width: 639px) { .form-panel { padding: 18px; } }
.panel-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; padding-bottom: 14px; margin-bottom: 2px; border-bottom: 1px solid var(--border); }
.panel-title .icon { color: var(--text-3); }

.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field-row { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.label { font-size: 14px; font-weight: 600; color: var(--text); }
.optional { font-weight: 400; font-size: 12px; color: var(--text-3); margin-left: 4px; }
.help { font-size: 13px; color: var(--text-3); }
.field-error { font-size: 13px; color: var(--red-text); font-weight: 500; }

.input {
  width: 100%; height: 42px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-size: 14px; outline: none; box-shadow: var(--shadow-xs); transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--text-3); }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); }
.has-error .input { border-color: var(--red); }
.has-error .input:focus { box-shadow: 0 0 0 4px color-mix(in oklab, var(--red) 25%, transparent); }
textarea.input { height: auto; min-height: 96px; padding: 10px 14px; resize: vertical; }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 38px; cursor: pointer;
  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='%23667085' 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 12px center;
}

/* Switch */
.field-switch { padding: 2px 0; }
.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.switch-input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative; flex-shrink: 0; width: 40px; height: 22px; margin-top: 1px; border-radius: 999px;
  background: var(--border-strong); transition: background-color .2s;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 999px;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .2s var(--ease);
}
.switch-input:checked + .switch-track { background: var(--brand); }
.switch-input:checked + .switch-track::after { transform: translateX(18px); }
.switch-input:focus-visible + .switch-track { outline: 2px solid var(--brand); outline-offset: 2px; }
.switch-text { display: grid; gap: 2px; }
.switch-text strong { font-size: 14px; font-weight: 600; }
.switch-text small { font-size: 13px; color: var(--text-3); }

/* Colour */
.color-input { display: flex; gap: 8px; }
.color-input input[type="color"] {
  flex-shrink: 0; width: 42px; height: 42px; padding: 4px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface);
}
.color-input input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-input input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 6px; }
.color-input input[type="color"]::-moz-color-swatch { border: 0; border-radius: 6px; }
.color-input .input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; }

/* Image upload */
.image-input { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.image-preview {
  display: grid; place-items: center; width: 72px; height: 72px; flex-shrink: 0; overflow: hidden;
  border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2);
  background-image: linear-gradient(45deg, var(--border) 25%, transparent 25%), linear-gradient(-45deg, var(--border) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--border) 75%), linear-gradient(-45deg, transparent 75%, var(--border) 75%);
  background-size: 12px 12px; background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}
.image-preview img { width: 56px; height: 56px; object-fit: contain; }
.image-preview.is-empty { background-image: none; border-style: dashed; border-color: var(--border-strong); }
.image-placeholder { display: none; color: var(--text-3); }
.image-preview.is-empty .image-placeholder { display: block; }
.image-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.image-actions label.btn { position: relative; cursor: pointer; }
.image-filename { font-size: 13px; color: var(--text-3); max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.remove-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--red-text); cursor: pointer; }
.remove-check input { accent-color: var(--red); }

/* Password */
.password-wrap { position: relative; }
.password-wrap .input { padding-right: 44px; }
.password-toggle { position: absolute; right: 3px; top: 3px; }

/* Role radio cards */
.radio-cards { display: grid; gap: 8px; }
.radio-card {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border-strong); font-size: 14px; transition: border-color .15s, background-color .15s;
}
.radio-card input { margin-top: 3px; accent-color: var(--brand); }
.radio-card:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }

.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.actions .push-left { margin-right: auto; }
.actions-stack { flex-direction: column; margin-top: 16px; }
@media (max-width: 479px) {
  .actions:not(.actions-stack) { flex-direction: column-reverse; }
  .actions:not(.actions-stack) .btn { width: 100%; }
  .actions .push-left { margin-right: 0; }
}

/* Preview card on the application form */
.form-side .sticky { position: sticky; top: 24px; }
.side-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin-bottom: 10px; }
.preview-card {
  display: grid; gap: 12px; padding: 20px; border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid color-mix(in oklab, var(--accent) 35%, var(--border)); box-shadow: var(--shadow-md);
}
.preview-card .card-head { display: flex; justify-content: space-between; align-items: flex-start; }
.preview-card .app-icon {
  display: grid; place-items: center; width: 56px; height: 56px; border-radius: 14px; overflow: hidden;
  background: color-mix(in oklab, var(--accent) 12%, var(--surface)); border: 1px solid color-mix(in oklab, var(--accent) 18%, transparent);
  color: var(--accent); font-weight: 700; font-size: 18px;
}
.preview-card .app-icon img { width: 40px; height: 40px; object-fit: contain; }
.preview-card .card-arrow { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 999px; color: var(--on-accent, #0b0b0b); background: var(--accent); }
.preview-card .card-title { font-size: 17px; font-weight: 650; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; word-break: break-word; }
.preview-card .card-text { font-size: 14px; color: var(--text-2); word-break: break-word; }
.preview-card .domain { font-size: 13px; color: var(--text-3); padding-top: 12px; border-top: 1px dashed var(--border); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 1023px) {
  .form-side .sticky { position: static; }
}

/* Delete confirmation */
.narrow { max-width: 520px; margin: 32px auto 0; }
.danger-panel { display: grid; justify-items: center; gap: 10px; padding: 32px 24px; text-align: center; }
.danger-panel h1 { font-size: 20px; word-break: break-word; }
.danger-panel .actions { margin-top: 12px; justify-content: center; width: 100%; }
.danger-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 999px; background: var(--red-soft); color: var(--red); }

/* --- Sign-in page --------------------------------------------------------- */

body.auth {
  background:
    radial-gradient(700px 400px at 10% 0%, color-mix(in oklab, var(--brand) 18%, transparent), transparent 70%),
    radial-gradient(600px 400px at 100% 100%, color-mix(in oklab, var(--brand) 10%, transparent), transparent 70%),
    var(--bg);
}
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 20px; padding: 24px 16px; }
.auth-card {
  width: min(400px, 100%); padding: 32px; border-radius: var(--radius-xl);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
@media (max-width: 479px) { .auth-card { padding: 24px 20px; } }
.auth-brand { margin-bottom: 24px; }
.auth-card h1 { font-size: 22px; font-weight: 700; }
.auth-card > .muted { margin: 4px 0 24px; }
.stack { display: grid; gap: 16px; }
.stack .btn { margin-top: 4px; height: 44px; }
.auth-back { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--text-3); }
.auth-back:hover { color: var(--text); }
