/**
 * ============================================================================
 * ALPINE.JS PROTOTYPE FRAMEWORK — Base Styles
 * ============================================================================
 * Core layout, CSS variables, and component styles.
 * Colors are overridden at runtime from config.js.
 * Tailwind CSS handles utility classes — this file covers structural layout.
 * ============================================================================
 */

/* ===========================================
   CSS VARIABLES (defaults — overridden by config)
   =========================================== */
:root {
  --color-primary: #2563eb;
  --color-primary-light: #3b82f6;
  --color-primary-dark: #1d4ed8;
  --color-primary-bg: #eff6ff;

  --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: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-active-text: #ffffff;
  --sidebar-active-bg: #334155;
  --sidebar-width: 256px;
  --sidebar-collapsed-width: 64px;

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

/* ===========================================
   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-logo img {
  max-height: 28px;
  width: auto;
}
.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;
}
.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(148,163,184,0.6);
  padding: 16px 12px 6px;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar.collapsed .sidebar-section-title { opacity: 0; height: 0; padding: 0; }
.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: #e2e8f0;
}
.menu-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}
.menu-item i { flex-shrink: 0; }
.sidebar.collapsed .menu-item span:not(.menu-icon) { display: none; }
.sidebar.collapsed .menu-item { justify-content: center; padding: 10px; }

/* Menu divider */
.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: #e2e8f0; 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;
}

/* --- 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;
}

/* ===========================================
   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-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); } }

/* ===========================================
   LOGIN PAGE
   =========================================== */
.login-container {
  display: flex;
  height: 100vh;
}
.login-left {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.login-form {
  width: 100%;
  max-width: 380px;
}
.login-brand {
  text-align: center;
  margin-bottom: 32px;
}
.login-brand-name {
  font-size: 28px;
  font-weight: 700;
  color: var(--color-primary);
}
.login-brand img { max-height: 48px; }
.login-env-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 4px;
  background: #fef3c7;
  color: #92400e;
  margin-top: 8px;
}
.login-right {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: linear-gradient(135deg, var(--login-gradient-start, #1e3a5f), var(--login-gradient-end, #3b82f6));
  color: white;
}
.login-right-content { max-width: 400px; text-align: center; }
.login-right-title { font-size: 28px; font-weight: 700; margin-bottom: 12px; }
.login-right-subtitle { font-size: 16px; opacity: 0.85; line-height: 1.5; }
.login-footer {
  text-align: center;
  margin-top: 32px;
  font-size: 12px;
  color: #94a3b8;
}

/* ===========================================
   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) {
  .login-right { display: none; }
  .content-body { padding: 16px; }
  .app-header { padding: 0 16px; }
}
