/* ================================================================
   Franchise Portal — Angry Chickz
   Vanilla CSS, no preprocessor, CSS custom properties for theming.
   ================================================================ */

/* ─── Theme Variables ─────────────────────────────────────── */

:root {
  /* Brand */
  --color-brand: #C73E1D;
  --color-brand-dark: #A33218;
  --color-brand-light: #F5E0D8;

  /* UI */
  --color-primary: #C73E1D;
  --color-primary-hover: #A33218;
  --color-success: #34D399;
  --color-warning: #FBBF24;
  --color-danger: #EF4444;
  --color-info: #5B9BDA;

  /* Neutrals */
  --color-bg: #F8F9FA;
  --color-surface: #FFFFFF;
  --color-surface-hover: #F3F4F6;
  --color-text: #1F2937;
  --color-text-secondary: #6B7280;
  --color-text-muted: #9CA3AF;
  --border-color: #E5E7EB;
  --border-color-strong: #D1D5DB;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
  --font-size-xs: 11px;
  --font-size-sm: 13px;
  --font-size-base: 14px;
  --font-size-md: 16px;
  --font-size-lg: 20px;
  --font-size-xl: 24px;
}

/* ─── Reset ───────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

table {
  border-collapse: collapse;
  width: 100%;
}

/* ─── Utilities ───────────────────────────────────────────── */

.hidden { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ─── Boot Splash ─────────────────────────────────────────── */

.app-boot-splash {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-bg);
}

.app-boot-splash-card {
  text-align: center;
  color: var(--color-text-secondary);
}

.loading-spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.loading-spinner-lg { width: 32px; height: 32px; border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Auth Gate ───────────────────────────────────────────── */

.auth-gate {
  position: fixed; inset: 0; z-index: 900;
  display: flex; align-items: center; justify-content: center;
}

.auth-gate-backdrop {
  position: absolute; inset: 0;
  background: var(--color-bg);
}

.auth-gate-panel {
  position: relative; z-index: 1;
  background: var(--color-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.auth-gate-logo {
  margin-bottom: var(--space-md);
}

.auth-logo-img {
  width: 64px; height: 64px;
  margin: 0 auto;
  border-radius: var(--radius-md);
}

.section-label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
}

.auth-gate-panel h1 {
  font-size: var(--font-size-lg);
  margin-bottom: var(--space-sm);
}

.panel-copy {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-lg);
}

.auth-form {
  display: flex; flex-direction: column; gap: var(--space-md);
  text-align: left;
}
.auth-link-row {
  text-align: center; margin: 0; font-size: var(--font-size-sm);
}
.auth-link-row a {
  color: var(--color-primary); text-decoration: none;
}
.auth-link-row a:hover {
  text-decoration: underline;
}

.field-group {
  display: flex; flex-direction: column; gap: var(--space-xs);
}

.field-group span {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
}

.storage-note {
  font-size: var(--font-size-sm);
  color: var(--color-danger);
  margin-top: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: #FEF2F2;
  border-radius: var(--radius-sm);
}

/* ─── Buttons ─────────────────────────────────────────────── */

.primary-button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.primary-button:hover { background: var(--color-primary-hover); }
.primary-button:disabled { opacity: 0.5; cursor: not-allowed; }
.primary-button--sm { padding: 6px 12px; font-size: var(--font-size-xs); }

.ghost-button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.ghost-button:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
  border-color: var(--border-color-strong);
}

.ghost-button--sm { padding: 4px 10px; font-size: var(--font-size-xs); }

/* ─── Form Fields ─────────────────────────────────────────── */

.field-input {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.15s;
  width: 100%;
}

.field-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(199, 62, 29, 0.1);
}

.field-input--sm {
  padding: 6px 10px;
  font-size: var(--font-size-xs);
}

.field-textarea {
  resize: vertical;
  min-height: 60px;
}

.field-row {
  display: flex; gap: var(--space-md);
}

.field-row > * { flex: 1; }

.item-detail-field {
  display: flex; flex-direction: column; gap: var(--space-xs);
  margin-bottom: var(--space-md);
}

.item-detail-field label {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
}

/* ─── App Header ──────────────────────────────────────────── */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-lg);
  background: var(--color-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex; align-items: center; gap: var(--space-md);
}

.header-home-btn {
  background: none; border: none; cursor: pointer; padding: 0;
  display: flex; align-items: center;
}

.header-logo-img {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
}

.header-app-title {
  font-size: var(--font-size-md);
  font-weight: 700;
  color: var(--color-text);
}

.header-nav {
  display: flex; gap: var(--space-xs);
  margin-left: var(--space-md);
}

.nav-link {
  padding: 6px 14px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  border-radius: var(--radius-md);
  transition: all 0.15s;
  text-decoration: none;
}

.nav-link:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
  text-decoration: none;
}

.nav-link.active {
  background: var(--color-brand-light);
  color: var(--color-brand);
  font-weight: 600;
}

.header-right {
  display: flex; align-items: center; gap: var(--space-md);
}

.header-user-info {
  display: flex; flex-direction: column; align-items: flex-end;
  line-height: 1.3;
}

.user-name {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
}

.user-role {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  text-transform: capitalize;
}

/* ─── App Main ────────────────────────────────────────────── */

.app-main {
  padding: var(--space-lg);
  max-width: 1400px;
  margin: 0 auto;
}

.view-header {
  margin-bottom: var(--space-lg);
}

.eyebrow {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
}
/* ─── Progress Bars ───────────────────────────────────────── */

.progress-bar-container {
  display: flex; align-items: center; gap: var(--space-sm);
  width: 100%;
}

.progress-bar-track {
  flex: 1;
  background: #F3F4F6;
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
  min-width: 0;
}

.progress-bar-label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text);
  min-width: 32px;
}

.progress-bar-count {
  font-size: 10px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* Progress Ring */
.progress-ring {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
}

.progress-ring-label {
  position: absolute;
  font-size: 9px;
  font-weight: 700;
  color: var(--color-text);
}

/* ─── Status & Phase Badges ───────────────────────────────── */

.status-badge {
  display: inline-block;
  padding: 2px 10px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  text-transform: capitalize;
  background: #F3F4F6;
  color: var(--color-text-secondary);
}

.status-badge--success { background: #D1FAE5; color: #065F46; }
.status-badge--warning { background: #FEF3C7; color: #92400E; }
.status-badge--danger  { background: #FEE2E2; color: #991B1B; }
.status-badge--muted   { background: #F3F4F6; color: #6B7280; }

.phase-chip {
  display: inline-block;
  padding: 2px 8px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  background: var(--color-brand-light);
  color: var(--color-brand);
  border-radius: var(--radius-sm);
}

.role-badge {
  display: inline-block;
  padding: 2px 10px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  text-transform: capitalize;
}

.role-badge--admin { background: #EDE9FE; color: #5B21B6; }
.role-badge--corporate { background: #DBEAFE; color: #1E40AF; }
.role-badge--franchisee { background: #FEF3C7; color: #92400E; }

/* ─── Modal ───────────────────────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.modal-overlay.is-visible { opacity: 1; }

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative; z-index: 1;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  padding: var(--space-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.modal-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
}

.modal-close-btn {
  background: none; border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: var(--space-xs);
  border-radius: var(--radius-sm);
}

.modal-close-btn:hover { color: var(--color-text); background: var(--color-surface-hover); }

.modal-body { /* content here */ }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-color);
}

.modal-form {
  display: flex; flex-direction: column;
}

.modal-confirm-message {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-md);
}

/* ─── Empty States ────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
  color: var(--color-text-muted);
}

.empty-state h3 {
  font-size: var(--font-size-md);
  color: var(--color-text-secondary);
  margin: var(--space-md) 0 var(--space-sm);
}

.empty-state p {
  font-size: var(--font-size-sm);
}

.empty-state-text {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  font-style: italic;
}

/* ─── Responsive ──────────────────────────────────────────── */

@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
  }

  .header-left {
    width: 100%;
    flex-wrap: wrap;
  }

  .header-nav {
    margin-left: 0;
    width: 100%;
    overflow-x: auto;
    padding-bottom: var(--space-xs);
  }

  .header-right {
    width: 100%;
    justify-content: flex-end;
  }

  .app-main {
    padding: var(--space-md);
  }

  .dashboard-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .documents-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .documents-search {
    max-width: none;
  }

  .field-row {
    flex-direction: column;
  }

  .modal-panel {
    width: 95%;
    padding: var(--space-md);
  }

  .nro-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ─── Launcher ───────────────────────────────────────────── */

.launcher {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-2xl) var(--space-lg);
  min-height: calc(100vh - 80px);
}

.launcher-greeting {
  text-align: center;
  margin-bottom: var(--space-2xl);
}

.launcher-greeting h1 {
  font-size: 28px;
  font-weight: 800;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

.launcher-greeting p {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.launcher-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-lg);
  width: 100%;
  max-width: 720px;
}

.launcher-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xl) var(--space-md);
  background: var(--color-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  text-decoration: none;
  color: inherit;
}

.launcher-tile:hover {
  border-color: var(--border-color-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
}

.launcher-tile-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.launcher-tile-icon svg {
  width: 24px;
  height: 24px;
}

.launcher-tile-name {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
}

.launcher-tile-desc {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  line-height: 1.3;
}

/* ─── App Switcher Button ────────────────────────────────── */

.app-switcher-btn {
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  transition: all 0.15s;
}

.app-switcher-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
  border-color: var(--border-color);
}

/* ─── Toast Notifications ────────────────────────────────── */

.toast-container {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.toast {
  padding: var(--space-sm) var(--space-md);
  background: var(--color-text);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s ease;
}

.toast--success { background: #065F46; }
.toast--error { background: #991B1B; }

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