/**
 * ============================================================================
 * FORM ENGINE — Base Styles
 * ============================================================================
 * Adapted from Prototype Framework. Purple/violet color scheme.
 * ============================================================================
 */

/* ===========================================
   CSS VARIABLES
   =========================================== */
:root {
  --color-primary: #7c3aed;
  --color-primary-light: #8b5cf6;
  --color-primary-dark: #6d28d9;
  --color-primary-bg: #f5f3ff;

  --color-success: #22c55e;
  --color-success-bg: #f0fdf4;
  --color-warning: #f59e0b;
  --color-warning-bg: #fffbeb;
  --color-error: #ef4444;
  --color-error-bg: #fef2f2;
  --color-info: #3b82f6;
  --color-info-bg: #eff6ff;

  --sidebar-bg: #1e1b4b;
  --sidebar-text: #a5b4fc;
  --sidebar-active-text: #ffffff;
  --sidebar-active-bg: #312e81;
  --sidebar-width: 256px;
  --sidebar-collapsed-width: 64px;

  --header-bg: #ffffff;
  --header-height: 56px;
  --content-bg: #f8fafc;
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  --footer-height: 48px;
}

/* ===========================================
   RESET & BASE
   =========================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[x-cloak] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: #1e293b;
  background: var(--content-bg);
  -webkit-font-smoothing: antialiased;
}

/* ===========================================
   APP LAYOUT
   =========================================== */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 200ms ease, transform 200ms ease;
  z-index: 40;
  overflow: hidden;
}
.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  min-height: 56px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-logo {
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 200ms;
}
.sidebar.collapsed .sidebar-logo { opacity: 0; width: 0; }
.sidebar-toggle {
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.08); color: #fff; }

/* --- Menu --- */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms;
  white-space: nowrap;
  overflow: hidden;
}
.menu-item:hover {
  background: rgba(255,255,255,0.06);
  color: #e0e7ff;
}
.menu-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}
.menu-item i { flex-shrink: 0; }
.sidebar.collapsed .menu-item span { display: none; }
.sidebar.collapsed .menu-item { justify-content: center; padding: 10px; }

.menu-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 8px 12px;
}

/* --- Sidebar Footer --- */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  overflow: hidden;
}
.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.sidebar-user-info { overflow: hidden; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #e0e7ff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-email { font-size: 11px; color: var(--sidebar-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar.collapsed .sidebar-user-info { display: none; }

/* --- Main Content --- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* --- Header --- */
.app-header {
  height: var(--header-height);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  z-index: 30;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}
.header-title {
  font-size: 16px;
  font-weight: 600;
  color: #0f172a;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* --- Breadcrumbs --- */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: #64748b;
}
.breadcrumbs a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}
.breadcrumbs a:hover {
  text-decoration: underline;
}
.breadcrumbs .bc-sep {
  color: #cbd5e1;
  font-size: 12px;
}
.breadcrumbs .bc-current {
  color: #1e293b;
  font-weight: 600;
}

/* --- Content Body --- */
.content-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--content-bg);
}

/* --- Footer --- */
.app-footer {
  height: var(--footer-height);
  background: var(--header-bg);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  font-size: 12px;
  color: #64748b;
  flex-shrink: 0;
}

/* ===========================================
   CARDS
   =========================================== */
.fe-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  transition: box-shadow 150ms, border-color 150ms;
}
.fe-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  border-color: #cbd5e1;
}
.fe-card.clickable {
  cursor: pointer;
}
.fe-card.clickable:hover {
  border-color: var(--color-primary-light);
}

/* Card grid */
.fe-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

/* ===========================================
   BUTTONS
   =========================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 150ms;
  white-space: nowrap;
}
.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.btn-primary:hover {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
}
.btn-secondary {
  background: #fff;
  color: #374151;
  border-color: var(--border-color);
}
.btn-secondary:hover {
  background: #f9fafb;
  border-color: #cbd5e1;
}
.btn-danger {
  background: #fff;
  color: var(--color-error);
  border-color: var(--color-error);
}
.btn-danger:hover {
  background: var(--color-error-bg);
}
.btn-sm {
  padding: 5px 10px;
  font-size: 13px;
}
.btn-icon {
  padding: 6px;
  border: none;
  background: none;
  color: #64748b;
  cursor: pointer;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover {
  background: #f1f5f9;
  color: #1e293b;
}

/* ===========================================
   BADGES
   =========================================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-primary {
  background: var(--color-primary-bg);
  color: var(--color-primary);
}
.badge-success {
  background: var(--color-success-bg);
  color: #16a34a;
}
.badge-warning {
  background: var(--color-warning-bg);
  color: #b45309;
}
.badge-error {
  background: var(--color-error-bg);
  color: #dc2626;
}
.badge-info {
  background: var(--color-info-bg);
  color: #2563eb;
}
.badge-gray {
  background: #f1f5f9;
  color: #475569;
}

/* ===========================================
   TABLES
   =========================================== */
.fe-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.fe-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
}
.fe-table td {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
}
.fe-table tbody tr {
  transition: background 100ms;
}
.fe-table tbody tr:hover {
  background: #f8fafc;
}
.fe-table tbody tr.clickable {
  cursor: pointer;
}
.fe-table tbody tr.clickable:hover {
  background: var(--color-primary-bg);
}

/* ===========================================
   PLACEHOLDER SCREEN
   =========================================== */
.placeholder-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 400px;
  text-align: center;
  color: #64748b;
  padding: 40px;
}
.placeholder-screen h2 {
  font-size: 22px;
  font-weight: 600;
  color: #334155;
  margin: 16px 0 8px;
}
.placeholder-screen p {
  font-size: 14px;
  max-width: 400px;
  line-height: 1.6;
}

/* ===========================================
   TOAST NOTIFICATIONS
   =========================================== */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 280px;
  max-width: 420px;
  animation: toast-in 250ms ease;
}
.toast-success { background: #065f46; color: #ecfdf5; }
.toast-error   { background: #991b1b; color: #fef2f2; }
.toast-warning { background: #92400e; color: #fffbeb; }
.toast-info    { background: #1e40af; color: #eff6ff; }
.toast-close {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  padding: 2px;
}
.toast-close:hover { opacity: 1; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ===========================================
   MODAL / DIALOG
   =========================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fade-in 150ms ease;
}
.modal-dialog {
  background: var(--card-bg, white);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  animation: modal-in 200ms ease;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}
.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: #0f172a;
}
.modal-close {
  background: none;
  border: none;
  color: #64748b;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}
.modal-close:hover { background: #f1f5f9; color: #0f172a; }
.modal-body { padding: 16px 24px; }
.modal-prompt-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 8px;
  margin-top: 16px;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.modal-prompt-input:focus {
  border-color: var(--color-primary, #7c3aed);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px 20px;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* ===========================================
   EMPTY STATE
   =========================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
  text-align: center;
  color: #94a3b8;
}
.empty-state i {
  color: #cbd5e1;
  margin-bottom: 16px;
}
.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 4px;
}
.empty-state p {
  font-size: 13px;
  max-width: 300px;
}

/* ===========================================
   RESPONSIVE
   =========================================== */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    z-index: 50;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .sidebar.collapsed {
    width: var(--sidebar-width);
    transform: translateX(-100%);
  }
  .sidebar.collapsed.mobile-open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 45;
  }
  .mobile-menu-btn { display: flex !important; }
}
@media (min-width: 1025px) {
  .mobile-menu-btn { display: none !important; }
  .sidebar-overlay { display: none !important; }
}
@media (max-width: 640px) {
  .content-body { padding: 16px; }
  .app-header { padding: 0 16px; }
  .fe-card-grid {
    grid-template-columns: 1fr;
  }
}
