/* ========================================
   Motiv till Meriter — Design System
   ======================================== */

/* --- CSS Variables --- */
:root {
  --color-bg: #f8fafb;
  --color-surface: #ffffff;
  --color-surface-hover: #f1f5f7;
  --color-border: #e2e8f0;
  --color-border-light: #edf2f7;
  
  --color-text: #1a2a3a;
  --color-text-secondary: #5a6f7e;
  --color-text-muted: #8fa0b0;
  
  --color-primary: #0f6b4b;
  --color-primary-light: #e6f4ed;
  --color-primary-dark: #0a5238;
  
  --color-accent: #d4891f;
  --color-accent-light: #fef3e2;
  
  --color-danger: #c53030;
  --color-success: #0f6b4b;
  
  --color-phase-1: #3b82f6;
  --color-phase-2: #8b5cf6;
  --color-phase-3: #f59e0b;
  --color-phase-4: #10b981;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
  
  --sidebar-width: 240px;
  --topbar-height: 64px;
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* --- Auth Overlay --- */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0a3622 0%, #0f6b4b 40%, #1a4a3a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.auth-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  text-align: center;
  margin-bottom: 28px;
}

.brand-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.auth-brand h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
}

.brand-tagline {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 4px;
}

.auth-form { display: none; }
.auth-form.active { display: block; }

.auth-form h2 {
  font-size: 18px;
  margin-bottom: 20px;
  color: var(--color-text);
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.auth-switch {
  text-align: center;
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 16px;
}

.auth-switch a {
  color: var(--color-primary);
  font-weight: 600;
  text-decoration: none;
}

.auth-error {
  background: #fef2f2;
  color: var(--color-danger);
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-top: 16px;
  text-align: center;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-outline {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text-secondary);
}
.btn-outline:hover { background: var(--color-surface-hover); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
}
.btn-ghost:hover { background: var(--color-surface-hover); }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 14px 24px; font-size: 16px; }
.btn-full { width: 100%; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- App Shell --- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

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

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px;
  font-weight: 700;
  font-size: 15px;
  color: var(--color-primary);
  border-bottom: 1px solid var(--color-border-light);
}

.nav-menu {
  list-style: none;
  padding: 12px 8px;
  flex: 1;
  overflow-y: auto;
}

.nav-menu li { margin-bottom: 2px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: all 0.15s;
}

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

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

.nav-link i { width: 18px; text-align: center; font-size: 13px; }

.nav-divider {
  padding: 16px 14px 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.phase-badge {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  background: var(--color-border);
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.nav-link.active .phase-badge {
  background: var(--color-primary);
  color: #fff;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--color-border-light);
}

.user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--color-text-secondary);
}

/* --- Main Content --- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

/* --- Topbar --- */
.topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.startup-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--color-text-secondary);
}

.startup-selector select {
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-surface);
  min-width: 220px;
}

.phase-progress {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* --- Views --- */
.view {
  display: none;
  padding: 28px 24px;
}

.view.active { display: block; }

.view-header {
  margin-bottom: 28px;
}

.view-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text);
}

.view-header p {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

/* --- Cards --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.card + .card { margin-top: 20px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-header h3 {
  font-size: 16px;
  font-weight: 700;
}

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

/* --- Stats --- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--color-text);
}

.stat-label {
  font-size: 12px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

/* --- Tables --- */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--color-border);
  background: var(--color-bg);
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border-light);
  color: var(--color-text);
}

tbody tr:hover { background: var(--color-surface-hover); }

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green { background: #e6f4ed; color: #0f6b4b; }
.badge-blue { background: #e8f0fe; color: #3b82f6; }
.badge-purple { background: #f0e8fe; color: #8b5cf6; }
.badge-amber { background: #fef3e2; color: #d4891f; }
.badge-red { background: #fef2f2; color: #c53030; }
.badge-gray { background: #f1f5f9; color: #5a6f7e; }

/* --- Phase color accents --- */
.phase-1-accent { border-left: 3px solid var(--color-phase-1); }
.phase-2-accent { border-left: 3px solid var(--color-phase-2); }
.phase-3-accent { border-left: 3px solid var(--color-phase-3); }
.phase-4-accent { border-left: 3px solid var(--color-phase-4); }

/* --- Progress bar --- */
.progress-bar {
  height: 8px;
  background: var(--color-border-light);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.progress-fill.f1 { background: var(--color-phase-1); }
.progress-fill.f2 { background: var(--color-phase-2); }
.progress-fill.f3 { background: var(--color-phase-3); }
.progress-fill.f4 { background: var(--color-phase-4); }

/* --- Toast --- */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  min-width: 280px;
  animation: slideIn 0.3s ease;
}

.toast-success { border-left: 3px solid var(--color-success); }
.toast-error { border-left: 3px solid var(--color-danger); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

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

.empty-state i {
  font-size: 40px;
  margin-bottom: 12px;
  display: block;
}

.empty-state h3 {
  font-size: 16px;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 13px;
  max-width: 400px;
  margin: 0 auto 20px;
}

/* --- SROI ratio display --- */
.sroi-ratio {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--color-primary-light);
  border-radius: var(--radius-md);
  margin: 16px 0;
}

.sroi-number {
  font-size: 42px;
  font-weight: 800;
  color: var(--color-primary);
  line-height: 1;
}

.sroi-label {
  font-size: 13px;
  color: var(--color-text-secondary);
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    overflow-x: auto;
  }
  .main-content { margin-left: 0; }
  .nav-menu { display: flex; flex-direction: row; }
  .card-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
