/* ============================================
   Archway Admin - Design System
   Per UI-SPEC: neutral admin aesthetic, DM Sans,
   blue/slate accents, white-label friendly
   ============================================ */

/* --- Custom Properties --- */
:root {
  --admin-bg: #F8FAFC;
  --admin-surface: #FFFFFF;
  --admin-accent: #3B82F6;
  --admin-accent-hover: #2563EB;
  --admin-accent-subtle: #EFF6FF;
  --admin-border: #E2E8F0;
  --admin-border-focus: #3B82F6;
  --admin-text: #1E293B;
  --admin-text-muted: #64748B;
  --admin-warning: #F59E0B;
  --admin-warning-bg: #FFFBEB;
  --admin-success: #10B981;
  --admin-destructive: #EF4444;
  --admin-sidebar-bg: #FFFFFF;
  --admin-sidebar-active: #EFF6FF;
  --admin-overlay: rgba(0, 0, 0, 0.4);
}

/* --- Global / Reset --- */
*, *::before, *::after {
  box-sizing: border-box;
}

[x-cloak] {
  display: none !important;
}

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--admin-text);
  background: var(--admin-bg);
  margin: 0;
  padding: 0;
}

/* --- Typography --- */
.display-heading {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
}

.tab-heading {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  margin: 0;
}

.label-text {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.text-muted {
  color: var(--admin-text-muted);
}

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: 240px;
  height: 100vh;
  background: var(--admin-sidebar-bg);
  border-right: 1px solid var(--admin-border);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-header {
  padding: 24px 24px 16px;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 8px 0;
}

.sidebar-tab {
  display: block;
  width: 100%;
  padding: 12px 24px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  color: var(--admin-text-muted);
  font-weight: 400;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  text-align: left;
  transition: all 0.15s;
}

.sidebar-tab:hover {
  background: var(--admin-bg);
  color: var(--admin-text);
}

.sidebar-tab-active {
  border-left: 3px solid var(--admin-accent);
  background: var(--admin-sidebar-active);
  color: var(--admin-accent);
  font-weight: 600;
}

.sidebar-footer {
  padding: 16px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--admin-border);
}

/* Publish button */
.publish-btn {
  width: 100%;
  padding: 10px 16px;
  background: #10B981;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.publish-btn:hover:not(:disabled) { background: #059669; }
.publish-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.publish-status {
  font-size: 12px;
  line-height: 1.3;
  padding: 0 2px;
}
.publish-ok { color: #10B981; }
.publish-err { color: #E74C3C; }

/* Advanced disclosure */
.advanced-toggle {
  font-size: 12px;
  color: var(--admin-text-muted);
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
}
.advanced-toggle:hover { color: var(--admin-text); }
.advanced-toggle + div { display: flex; flex-direction: column; gap: 8px; }

/* Hide/unhide inline status */
.hide-status-msg {
  font-size: 12px;
  color: var(--admin-text-muted);
  white-space: nowrap;
}

/* --- Content Panel --- */
.content-panel {
  margin-left: 240px;
  padding: 48px 32px;
  min-height: 100vh;
}

/* --- Buttons --- */
.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-destructive {
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  padding: 0 12px;
  height: 36px;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--admin-accent);
  color: #FFFFFF;
  border: none;
}

.btn-primary:hover {
  background: var(--admin-accent-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--admin-text);
  border: 1px solid var(--admin-border);
}

.btn-secondary:hover {
  background: var(--admin-bg);
}

.btn-ghost {
  background: transparent;
  color: var(--admin-text-muted);
  border: none;
}

.btn-ghost:hover {
  background: var(--admin-bg);
}

.btn-destructive {
  background: transparent;
  color: var(--admin-destructive);
  border: 1px solid var(--admin-destructive);
}

.btn-destructive:hover {
  background: var(--admin-destructive);
  color: #FFFFFF;
}

/* --- Download button with dirty dot --- */
.download-btn {
  position: relative;
  width: 100%;
}

.dirty-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--admin-warning);
  position: absolute;
  top: -2px;
  right: -2px;
}

.preview-btn {
  width: 100%;
}

/* --- Data Table --- */
.data-table {
  width: 100%;
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  border-collapse: separate;
  border-spacing: 0;
}

.data-table thead th {
  background: var(--admin-bg);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--admin-text-muted);
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--admin-border);
}

.data-table thead th:first-child {
  border-top-left-radius: 8px;
}

.data-table thead th:last-child {
  border-top-right-radius: 8px;
}

.data-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--admin-border);
  font-size: 14px;
}

.data-table tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}

.data-table tbody tr:hover {
  background: var(--admin-bg);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:last-child td:first-child {
  border-bottom-left-radius: 8px;
}

.data-table tbody tr:last-child td:last-child {
  border-bottom-right-radius: 8px;
}

/* Hidden course row */
.data-table tbody tr.row-hidden {
  color: var(--admin-text-muted);
  opacity: 0.6;
}

/* --- Badges --- */
.badge-hidden {
  background: var(--admin-warning-bg);
  color: var(--admin-warning);
  border: 1px solid var(--admin-warning);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  text-transform: uppercase;
  display: inline-block;
}

.badge-deleted {
  background: #FEF2F2;
  color: var(--admin-destructive);
  border: 1px solid var(--admin-destructive);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  text-transform: uppercase;
  display: inline-block;
}

/* --- Active Badge --- */
.badge-active {
  background: #ECFDF5;
  color: var(--admin-success);
  border: 1px solid var(--admin-success);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  text-transform: uppercase;
  display: inline-block;
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 48px;
  color: var(--admin-text-muted);
}

.empty-state h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 8px;
}

.empty-state p {
  font-size: 14px;
  margin: 0;
}

/* --- Drawer --- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: var(--admin-overlay);
  z-index: 200;
  display: flex;
  justify-content: flex-end;
}

.drawer {
  width: 480px;
  height: 100vh;
  background: var(--admin-surface);
  border-left: 1px solid var(--admin-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drawer-header {
  padding: 20px 32px;
  border-bottom: 1px solid var(--admin-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.drawer-close {
  padding: 4px;
  color: var(--admin-text-muted);
}

.drawer-close:hover {
  color: var(--admin-text);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

.drawer-footer {
  padding: 16px 32px;
  border-top: 1px solid var(--admin-border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  background: var(--admin-surface);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
  z-index: 1;
}

.drawer-footer-spacer {
  flex: 1;
}

/* Drawer transitions */
.drawer-enter {
  transition: opacity 0.2s ease-out;
}
.drawer-enter-start {
  opacity: 0;
}
.drawer-enter-end {
  opacity: 1;
}
.drawer-leave {
  transition: opacity 0.15s ease-in;
}
.drawer-leave-start {
  opacity: 1;
}
.drawer-leave-end {
  opacity: 0;
}

.drawer-enter .drawer,
.drawer-leave .drawer {
  transition: transform 0.2s ease-out;
}

.drawer-enter-start .drawer {
  transform: translateX(100%);
}

.drawer-enter-end .drawer {
  transform: translateX(0);
}

.drawer-leave-start .drawer {
  transform: translateX(0);
}

.drawer-leave-end .drawer {
  transform: translateX(100%);
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--admin-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.modal {
  background: var(--admin-surface);
  border-radius: 12px;
  max-width: 560px;
  width: 90%;
  padding: 24px;
}

/* Modal transitions */
.modal-enter {
  transition: opacity 0.2s ease-out;
}
.modal-enter-start {
  opacity: 0;
}
.modal-enter-end {
  opacity: 1;
}
.modal-leave {
  transition: opacity 0.15s ease-in;
}
.modal-leave-start {
  opacity: 1;
}
.modal-leave-end {
  opacity: 0;
}

.modal-enter .modal,
.modal-leave .modal {
  transition: transform 0.2s ease-out;
}

.modal-enter-start .modal {
  transform: scale(0.95);
}

.modal-enter-end .modal {
  transform: scale(1);
}

.modal-leave-start .modal {
  transform: scale(1);
}

.modal-leave-end .modal {
  transform: scale(0.95);
}

/* --- Form Inputs --- */
input,
select,
textarea {
  border: 1px solid var(--admin-border);
  border-radius: 6px;
  padding: 0 12px;
  height: 40px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  color: var(--admin-text);
  background: var(--admin-surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea {
  height: auto;
  padding: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--admin-border-focus);
  box-shadow: 0 0 0 2px var(--admin-border-focus);
}

input.invalid,
select.invalid,
textarea.invalid {
  border-color: var(--admin-destructive);
}

input.advisory,
select.advisory,
textarea.advisory {
  border-color: var(--admin-warning);
}

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--admin-bg);
  color: var(--admin-text-muted);
  cursor: not-allowed;
}

input::placeholder,
textarea::placeholder {
  color: var(--admin-text-muted);
}

.field-error {
  font-size: 12px;
  color: var(--admin-destructive);
  margin-top: 4px;
}

.field-advisory {
  font-size: 12px;
  color: var(--admin-warning);
  margin-top: 4px;
}

/* --- Toolbar --- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.toolbar-search {
  flex: 1;
  max-width: 320px;
}

.toolbar-filter {
  width: 200px;
}

.toolbar-spacer {
  flex: 1;
}

/* --- Tier Buckets --- */
.tier-columns {
  display: flex;
  gap: 16px;
}

.tier-column {
  flex: 1;
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  padding: 16px;
}

.tier-column-header {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
}

.tier-chip {
  height: 36px;
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  cursor: grab;
  margin-bottom: 8px;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.tier-chip:last-child {
  margin-bottom: 0;
}

.tier-chip-ghost {
  opacity: 0.4;
}

.tier-chip-chosen {
  border: 2px solid var(--admin-accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.tier-chip .drag-handle {
  color: var(--admin-text-muted);
  cursor: grab;
  flex-shrink: 0;
}

.tier-drop-zone {
  border: 2px dashed var(--admin-accent);
  border-radius: 8px;
  min-height: 48px;
}

/* --- Preview Container --- */
.preview-container {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: var(--admin-surface);
  display: flex;
  flex-direction: column;
}

.preview-header {
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--admin-border);
  background: var(--admin-surface);
}

.preview-container iframe {
  flex: 1;
  width: 100%;
  border: none;
}

/* --- Loading / Error Overlays --- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--admin-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.loading-content {
  font-size: 18px;
  font-weight: 600;
  color: var(--admin-text-muted);
}

.error-overlay {
  position: fixed;
  inset: 0;
  background: var(--admin-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.error-content {
  text-align: center;
  color: var(--admin-destructive);
  max-width: 480px;
  padding: 32px;
}

.error-content svg {
  margin-bottom: 16px;
}

.error-content p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--admin-text);
}

/* --- Competency Grid --- */
.competency-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.competency-group-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--admin-text-muted);
  margin: 0 0 8px;
}

.competency-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 0;
  border-bottom: 1px solid var(--admin-border);
}

.competency-name {
  flex: 1;
  min-width: 200px;
  font-size: 14px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.radio-label input[type="radio"] {
  width: auto;
  height: auto;
  margin: 0;
}

/* --- Overlaps & Checkboxes --- */
.overlaps-section {
  display: flex;
  flex-direction: column;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  height: auto;
  margin: 0;
}

/* --- Drawer Sections & Form Fields --- */
.drawer-section {
  margin-bottom: 24px;
}

.drawer-section h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 12px;
}

.form-field {
  margin-bottom: 16px;
}

.form-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--admin-text-muted);
  margin-bottom: 4px;
}

/* --- Modal References --- */
.modal-ref-row {
  display: flex;
  align-items: center;
  padding: 4px 0;
  font-size: 14px;
}

/* --- Utility --- */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 8px;
  color: var(--admin-text);
}

.section-gap {
  margin-bottom: 24px;
}

/* --- Domain Cards --- */
.domain-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  margin-bottom: 8px;
}

.domain-color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  flex-shrink: 0;
}

.domain-info {
  flex: 1;
}

.domain-label {
  font-weight: 600;
}

.domain-key {
  font-size: 12px;
  display: block;
}

/* --- Small Button --- */
.btn-sm {
  height: 28px;
  font-size: 12px;
  padding: 0 8px;
}

/* --- Color Input Pair --- */
.color-input-pair {
  display: flex;
  gap: 8px;
  align-items: center;
}

.color-input-pair input[type="color"] {
  width: 40px;
  height: 40px;
  padding: 2px;
  border: 1px solid var(--admin-border);
  border-radius: 6px;
  cursor: pointer;
}

/* --- Bundle Course Row --- */
.bundle-course-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.bundle-course-select {
  flex: 2;
}

.bundle-role-select {
  flex: 1;
  max-width: 120px;
}

/* --- Tiers Grid --- */
.tiers-grid {
  display: flex;
  gap: 16px;
}

.tier-heading {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.tier-bucket {
  min-height: 48px;
}

.untiered-section .tier-bucket {
  min-height: 48px;
}

/* --- Brand Form --- */
.brand-form {
  max-width: 640px;
}

.form-row {
  display: flex;
  gap: 16px;
}

.form-row .form-field {
  flex: 1;
}

/* --- Brand Preview Strip --- */
.brand-preview-strip {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 8px;
}

.preview-swatch {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Validation Issue Row --- */
.validation-issue-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--admin-border);
  font-size: 14px;
}

.warning-icon {
  flex-shrink: 0;
  margin-top: 2px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* --- Preview Overlay --- */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: var(--admin-bg);
  z-index: 400;
  display: flex;
  flex-direction: column;
}

.preview-iframe {
  flex: 1;
  border: none;
  width: 100%;
}
