/* ═══════════════════════════════════════════════════════════
   GrantOS v12.0 — NAVY THEME
   © Unilink Center MTÜ (80668249)
   Fonts: Inter (body), Syne (display), JetBrains Mono (code)
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Syne:wght@600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg: #0F172A;
  --surface: #1E293B;
  --surface-hover: #263548;
  --border: #334155;
  --border-light: #475569;
  --accent: #00E676;
  --accent-dim: #00C853;
  --accent-glow: rgba(0, 230, 118, 0.15);
  --text: #F1F5F9;
  --text-dim: #94A3B8;
  --text-muted: #64748B;
  --danger: #EF4444;
  --warning: #F59E0B;
  --info: #3B82F6;
  --success: #00E676;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
}

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

/* Prevent iOS tap flash */
a, button, .btn, .nav-item, .chip, select {
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Layout ── */
.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-header {
  padding: 0 20px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.logo {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 22px;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.logo-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 2px;
}

.sidebar-nav { flex: 1; padding: 4px 0; overflow-y: auto; min-height: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition);
  border-left: 3px solid transparent;
  font-size: 13px;
  font-size: 14px;
  font-weight: 500;
}

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

.nav-item.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-glow);
}

.nav-icon { font-size: 18px; width: 24px; text-align: center; }

.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: var(--bg);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
}

.sidebar-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}


.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 32px;
  max-width: calc(100vw - 260px);
}

/* ── Header ── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

.page-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 26px;
  color: var(--text);
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: all var(--transition);
}

.card:hover { border-color: var(--border-light); }

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

.card-title {
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
}

.card-icon {
  font-size: 20px;
  opacity: 0.7;
}

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

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

.stat-value {
  font-family: 'Syne', sans-serif;
  font-size: 32px;
  font-weight: 800;
  color: var(--accent);
}

.stat-label {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}

.btn-primary:hover { background: var(--accent-dim); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

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

.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 6px 14px; font-size: 13px; }

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

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

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

.form-textarea {
  min-height: 120px;
  resize: vertical;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.7;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394A3B8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── AI Output ── */
.ai-output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.8;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 500px;
  overflow-y: auto;
  color: var(--text);
}

.ai-output:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  font-style: italic;
}

.ai-output.loading {
  position: relative;
  min-height: 80px;
}

.ai-output.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ── AI Rendered Output ── */
.ai-rendered { font-family: 'Inter', sans-serif; font-size: 14px; line-height: 1.8; color: var(--text); }
.ai-rendered h2 { font-family: 'Syne', sans-serif; }
.ai-rendered h3 { border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.ai-rendered strong { color: var(--text); }
.ai-rendered pre { font-family: 'JetBrains Mono', monospace; }
.ai-rendered hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.loading-spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

/* ── Grant Database Table ── */
.grant-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.grant-table th {
  text-align: left;
  padding: 10px 14px;
  background: var(--bg);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

.grant-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.grant-table tr:hover td { background: var(--surface-hover); }

.country-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}

.country-ee { background: #1D4ED8; color: white; }
.country-lv { background: #9F1239; color: white; }
.country-lt { background: #B45309; color: white; }
.country-eu { background: #6D28D9; color: white; }

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.status-open { background: rgba(0,230,118,0.15); color: var(--accent); }
.status-closed { background: rgba(239,68,68,0.15); color: var(--danger); }
.status-upcoming { background: rgba(59,130,246,0.15); color: var(--info); }

/* ── Panels ── */
.panel { display: none; }
.panel.active { display: block; }

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.panel-grid.single { grid-template-columns: 1fr; }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: 'Inter', sans-serif;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

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

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  animation: slideIn 0.3s ease;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.toast-success { background: var(--accent); color: var(--bg); }
.toast-error { background: var(--danger); color: white; }
.toast-info { background: var(--info); color: white; }

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

/* ── Evaluation Score ── */
.score-circle {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 24px;
  margin: 0 auto 12px;
}

.score-high { background: rgba(0,230,118,0.15); color: var(--accent); border: 3px solid var(--accent); }
.score-medium { background: rgba(245,158,11,0.15); color: var(--warning); border: 3px solid var(--warning); }
.score-low { background: rgba(239,68,68,0.15); color: var(--danger); border: 3px solid var(--danger); }

/* ── Language Selector ── */
.lang-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.lang-btn {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.lang-btn:hover { border-color: var(--accent); color: var(--accent); }
.lang-btn.active { background: var(--accent); color: var(--bg); border-color: var(--accent); }

/* ── Mobile Menu Toggle ── */
.mobile-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}

.mobile-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ── Output Action Buttons ── */
.output-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-bottom: 8px;
  position: relative;
  flex-wrap: wrap;
}

.copy-btn {
  padding: 6px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.copy-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-glow); }

.output-wrapper { position: relative; }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .panel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .mobile-toggle { display: block; }
  .sidebar { transform: translateX(-100%); width: 280px; }
  .sidebar.open { transform: translateX(0); }
  .mobile-overlay.active { display: block; }
  .main-content { margin-left: 0; padding: 56px 10px 80px; max-width: 100vw; overflow-x: hidden; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .page-title { font-size: 20px; }
  .page-subtitle { font-size: 12px; }
  .page-header { margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
  .card { padding: 14px; }

  /* Force all grids to single column */
  .panel-grid { grid-template-columns: 1fr !important; gap: 12px; }
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:2fr 1fr"],
  [style*="grid-template-columns: 2fr 1fr"],
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"],
  [style*="grid-template-columns:repeat"] { grid-template-columns: 1fr !important; }

  /* Touch-friendly inputs (44px min) */
  .btn { min-height: 44px; padding: 12px 20px; font-size: 15px; }
  .form-input, .form-select, .form-textarea { min-height: 44px; font-size: 16px; padding: 10px 12px; }
  .form-textarea { font-size: 14px; min-height: 80px; }
  .form-label { font-size: 12px; }

  /* AI output mobile */
  .ai-output { font-size: 12px; line-height: 1.6; padding: 12px; max-height: 400px; overflow-y: auto; -webkit-overflow-scrolling: touch; word-break: break-word; }

  /* Copy/Download buttons — side by side, not overlapping */
  .output-actions { gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
  .copy-btn { padding: 8px 14px; font-size: 12px; min-height: 36px; }

  /* Download menu — ABOVE button, not at screen bottom */
  #dlMenu { right: 0 !important; left: auto !important; bottom: 100% !important; top: auto !important; margin-bottom: 4px; }

  /* Grant table horizontal scroll */
  .grant-table { font-size: 12px; min-width: 560px; }
  .grant-table th, .grant-table td { padding: 8px; white-space: nowrap; }

  /* Stats */
  .stat-card { padding: 12px; }
  .stat-value { font-size: 22px; }
  .stat-label { font-size: 10px; }

  /* Sidebar nav compact */
  .nav-item { padding: 11px 14px; font-size: 13px; }
  .sidebar-footer { padding: 8px 10px; }
  .sidebar-footer .btn-sm { font-size: 10px !important; padding: 3px 6px !important; }

  /* Landing page mobile */
  [style*="grid-template-columns:1fr 1fr"][style*="max-width:800px"],
  [style*="grid-template-columns: 1fr 1fr"][style*="max-width:800px"] { grid-template-columns: 1fr !important; gap: 16px !important; }

  /* Pipeline kanban scroll */
  [style*="display:flex"][style*="min-width:max-content"] { padding-bottom: 12px; }
  [style*="min-width:220px"] { min-width: 200px !important; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; gap: 6px; }
  .main-content { padding: 52px 6px 80px; }
  .page-title { font-size: 17px; }
  .card { padding: 10px; border-radius: 8px; }
  .ai-output { font-size: 11px; max-height: 300px; padding: 10px; }
  .grant-table th:nth-child(3), .grant-table td:nth-child(3) { display: none; }
  .grant-table th:nth-child(5), .grant-table td:nth-child(5) { display: none; }
  .sidebar { width: 260px; }
  .stat-value { font-size: 18px; }
  .btn { width: 100%; justify-content: center; font-size: 14px; }
  .page-header .btn { width: auto; }

  /* Buttons stack on very small screens */
  .output-actions { flex-direction: row; gap: 4px; }
  .copy-btn { flex: 1; text-align: center; min-height: 36px; justify-content: center; }

  /* Pipeline cards smaller */
  [style*="min-width:220px"] { min-width: 160px !important; }
  [style*="min-width:200px"] { min-width: 160px !important; }
}

@media (max-width: 360px) {
  .main-content { padding: 48px 4px 70px; }
  .stat-value { font-size: 16px; }
  .nav-item { padding: 10px 12px; font-size: 12px; }
  .sidebar { width: 240px; }
  .ai-output { font-size: 11px; max-height: 250px; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── Usage Meter ── */
.usage-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}

.usage-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* ── Pulse animation for AI active ── */
.ai-pulse {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.5s ease infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(0,230,118,0.4); }
  50% { opacity: 0.7; box-shadow: 0 0 0 8px rgba(0,230,118,0); }
}

/* ── Chip tags ── */
.chip {
  display: inline-block;
  padding: 3px 10px;
  background: var(--accent-glow);
  color: var(--accent);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  margin: 2px;
}

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

.empty-state-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state-text { font-size: 15px; }

/* ── iPhone safe area (notch / Dynamic Island) ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .sidebar {
    padding-bottom: env(safe-area-inset-bottom);
  }
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
  @media (max-width: 768px) {
    .main-content {
      padding-bottom: calc(56px + env(safe-area-inset-bottom));
    }
    .nav-item {
      min-height: 44px;
    }
  }
}

/* ── Touch device: larger tap targets ── */
@media (hover: none) and (pointer: coarse) {
  button, .btn, .nav-item, .chip, select, input[type="button"] {
    min-height: 44px;
  }
  input, select, textarea {
    font-size: 16px; /* prevent iOS zoom */
  }
}

/* Grant table responsive scroll wrapper */
.grant-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 768px) { .grant-table-wrap { margin: 0 -10px; padding: 0 10px; } }

/* Touch action optimization */
.btn, button, .nav-item, select { touch-action: manipulation; }

/* Prevent body scroll while sidebar is open */
body.sidebar-open { overflow: hidden; }
.sidebar { overscroll-behavior: contain; }
.ai-output { overscroll-behavior: contain; }

/* Prevent accidental text selection on UI elements */
.nav-item, .btn, .sidebar-header, .page-header { user-select: none; }
