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

:root {
  --blue-900: #0d1b3e;
  --blue-800: #1a2f5a;
  --blue-700: #1e3a6e;
  --blue-600: #2563eb;
  --blue-500: #3b82f6;
  --blue-100: #dbeafe;
  --blue-50: #eff6ff;
  --green-600: #059669;
  --green-500: #10b981;
  --green-100: #d1fae5;
  --green-50: #ecfdf5;
  --yellow-500: #f59e0b;
  --yellow-100: #fef3c7;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --red-500: #ef4444;
  --white: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
}

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: 64px;
}

/* === Auth Status Bar === */
.auth-bar {
  background: var(--blue-900);
  color: var(--white);
  padding: 6px 16px;
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.auth-bar .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.auth-bar .dot.none { background: var(--gray-400); }
.auth-bar .dot.low { background: var(--yellow-500); }
.auth-bar .dot.high { background: var(--green-500); }

.auth-bar .persona-badge {
  background: rgba(255,255,255,0.15);
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 4px;
}

.auth-bar .user-info {
  opacity: 0.7;
}

/* === Header === */
.header {
  background: linear-gradient(135deg, var(--blue-800) 0%, var(--blue-700) 100%);
  color: var(--white);
  padding: 14px 20px;
}

.header-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.emblem-svg {
  width: 32px;
  height: auto;
  filter: brightness(0) invert(1);
  flex-shrink: 0;
}

.header h1 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 0;
  line-height: 1.2;
}

.header .subtitle {
  font-size: 0.7rem;
  opacity: 0.7;
  font-weight: 400;
}

/* === Tab Content === */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* === Main Content === */
.main {
  flex: 1;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 24px 16px 100px;
}

/* === Question / Prompt === */
.prompt {
  text-align: center;
  margin-bottom: 20px;
}

.prompt h2 {
  font-size: 1.35rem;
  font-weight: 400;
  color: var(--gray-800);
  font-family: Georgia, 'Times New Roman', serif;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

/* === Search === */
.search-container {
  position: relative;
  margin-bottom: 24px;
}

.search-input {
  width: 100%;
  padding: 14px 16px 14px 44px;
  font-size: 1rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--gray-900);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}

.search-input:focus {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.search-input::placeholder {
  color: var(--gray-400);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.95rem;
  color: var(--gray-400);
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--gray-400);
  cursor: pointer;
  padding: 4px;
  display: none;
}

.search-clear.visible {
  display: block;
}

/* === Autocomplete Dropdown === */
.autocomplete {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  max-height: 260px;
  overflow-y: auto;
  display: none;
}

.autocomplete.open {
  display: block;
}

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--gray-100);
  transition: background 0.1s;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: var(--blue-50);
}

.autocomplete-item .ac-icon {
  font-size: 1rem;
  flex-shrink: 0;
  color: var(--blue-600);
  width: 24px;
  text-align: center;
}

.autocomplete-item .ac-text {
  flex: 1;
  min-width: 0;
}

.autocomplete-item .ac-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.autocomplete-item .ac-agency {
  font-size: 0.72rem;
  color: var(--gray-500);
}

/* === Quick Links === */
.quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 28px;
  justify-content: center;
}

.quick-link {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.78rem;
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.quick-link .lni {
  font-size: 0.85rem;
  color: var(--blue-500);
}

.quick-link:hover {
  border-color: var(--blue-500);
  color: var(--blue-600);
  background: var(--blue-50);
}

/* === Results === */
.results-header {
  font-size: 0.78rem;
  color: var(--gray-500);
  margin-bottom: 12px;
  display: none;
}

.results-header.visible {
  display: block;
}

.results {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* === Result Card === */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  animation: cardIn 0.3s ease;
  transition: box-shadow 0.2s, transform 0.2s;
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.card-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--blue-50);
  border-radius: 10px;
  color: var(--blue-600);
  font-size: 1.2rem;
  flex-shrink: 0;
}

.card-info {
  flex: 1;
  min-width: 0;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 2px;
}

.card-agency {
  font-size: 0.78rem;
  color: var(--gray-500);
  font-weight: 500;
}

.card-auth {
  font-size: 0.65rem;
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  margin-left: 6px;
}

.card-auth.auth-none {
  background: var(--gray-100);
  color: var(--gray-500);
}

.card-auth.auth-low {
  background: var(--yellow-100);
  color: #92400e;
}

.card-auth.auth-high {
  background: var(--green-100);
  color: #065f46;
}

.card-message {
  font-size: 0.88rem;
  color: var(--gray-700);
  line-height: 1.5;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--blue-50);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--blue-500);
}

.card-message.personalized {
  background: var(--green-50);
  border-left-color: var(--green-500);
}

.card-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: var(--blue-600);
  color: var(--white);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 0.83rem;
  font-weight: 600;
  transition: background 0.15s;
  width: 100%;
  justify-content: center;
}

.card-link:hover {
  background: var(--blue-700);
}

.card-link .lni {
  font-size: 0.9rem;
}

/* === AI Fallback Card === */
.ai-card {
  background: linear-gradient(135deg, var(--blue-50), var(--green-50));
  border: 1px solid var(--blue-100);
  border-radius: var(--radius);
  padding: 20px;
  animation: cardIn 0.4s ease;
}

.ai-card .ai-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--blue-600);
}

.ai-card .ai-body {
  font-size: 0.88rem;
  color: var(--gray-700);
  line-height: 1.6;
}

.ai-card .ai-body p {
  margin-bottom: 8px;
}

.ai-card .ai-body p:last-child {
  margin-bottom: 0;
}

.ai-card-compact {
  margin-bottom: 12px;
}

.ai-card-compact .ai-body {
  font-size: 0.83rem;
}

.ai-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}

.ai-typing span {
  width: 6px;
  height: 6px;
  background: var(--blue-500);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}

.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* === Suggested Services (shown on empty state) === */
.suggested-section {
  margin-top: 8px;
}

.suggested-section h3 {
  font-size: 0.83rem;
  color: var(--gray-500);
  font-weight: 600;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* === Footer === */
.footer {
  text-align: center;
  padding: 16px;
  color: var(--gray-400);
  font-size: 0.67rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.admin-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--white);
  opacity: 0.35;
  transition: opacity 0.2s;
  padding: 2px 4px;
  margin-left: auto;
  position: absolute;
  right: 12px;
}

.admin-toggle:hover {
  opacity: 0.8;
}

/* === Admin Panel === */
.admin-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.admin-overlay.open {
  opacity: 1;
  visibility: visible;
}

.admin-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px 32px;
  z-index: 1000;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  box-shadow: 0 -10px 40px rgba(0,0,0,0.15);
  max-width: 520px;
  margin: 0 auto;
}

.admin-panel.open {
  transform: translateY(0);
}

.admin-panel .admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.admin-panel .admin-title {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--gray-800);
}

.admin-panel .admin-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--gray-400);
  cursor: pointer;
  padding: 4px;
}

.admin-section {
  margin-bottom: 20px;
}

.admin-section:last-child {
  margin-bottom: 0;
}

.admin-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.auth-buttons {
  display: flex;
  gap: 8px;
}

.auth-btn {
  flex: 1;
  padding: 10px 8px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: var(--white);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  text-align: center;
}

.auth-btn:hover {
  border-color: var(--blue-300, #93c5fd);
}

.auth-btn.active {
  border-color: var(--blue-500);
  background: var(--blue-50);
  color: var(--blue-600);
}

.persona-select {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.88rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--gray-800);
  cursor: pointer;
  font-family: inherit;
  outline: none;
}

.persona-select:focus {
  border-color: var(--blue-500);
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--gray-400);
}

.empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 0.88rem;
}

/* === No Results === */
.no-results {
  text-align: center;
  padding: 24px;
  color: var(--gray-500);
  font-size: 0.88rem;
}

/* === Responsive === */
@media (min-width: 640px) {
  .main {
    padding: 32px 24px 100px;
  }

  .header {
    padding: 18px 24px;
  }

  .header h1 {
    font-size: 1.3rem;
  }

  .emblem-svg {
    width: 36px;
  }

  .prompt h2 {
    font-size: 1.8rem;
  }
}

@media (min-width: 1024px) {
  .main {
    max-width: 580px;
  }
}

/* === Scrollbar === */
.autocomplete::-webkit-scrollbar {
  width: 6px;
}

.autocomplete::-webkit-scrollbar-track {
  background: transparent;
}

.autocomplete::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: 3px;
}

/* === Bottom Nav === */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-around;
  padding: 6px 0 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 200;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 12px;
  color: var(--gray-400);
  font-size: 0.6rem;
  font-family: inherit;
  font-weight: 500;
  transition: color 0.15s;
  position: relative;
}

.bottom-nav-item .lni {
  font-size: 1.2rem;
}

.bottom-nav-item.active {
  color: var(--blue-600);
}

.bottom-nav-item:hover {
  color: var(--blue-500);
}

.nav-badge {
  position: absolute;
  top: 2px;
  right: 4px;
  background: var(--red-500);
  color: var(--white);
  font-size: 0.55rem;
  font-weight: 700;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* === Tab Pages (shared) === */
.tab-page {
  text-align: center;
}

.tab-page h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.tab-page-icon {
  font-size: 2rem;
  color: var(--blue-600);
  margin-bottom: 12px;
}

.tab-page-desc {
  font-size: 0.83rem;
  color: var(--gray-500);
  margin-bottom: 24px;
}

/* === ID Card === */
.id-card {
  background: linear-gradient(145deg, var(--blue-800), var(--blue-700));
  border-radius: var(--radius);
  padding: 20px;
  color: var(--white);
  text-align: left;
  box-shadow: var(--shadow-lg);
  margin-bottom: 20px;
}

.id-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  opacity: 0.8;
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.id-card-header .id-card-emblem {
  width: 18px;
  height: auto;
  filter: brightness(0) invert(1);
}

.id-card-body {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.id-card-photo {
  width: 64px;
  height: 80px;
  background: rgba(255,255,255,0.15);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  flex-shrink: 0;
}

.id-card-details {
  flex: 1;
}

.id-card-name {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.id-card-field {
  font-size: 0.75rem;
  opacity: 0.85;
  margin-bottom: 6px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.id-card-field span {
  opacity: 0.5;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.id-card-field strong {
  font-weight: 600;
}

.id-actions {
  display: flex;
  gap: 10px;
}

.id-action {
  flex: 1;
  padding: 12px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-700);
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
}

.id-action .lni {
  font-size: 1rem;
  color: var(--blue-600);
}

.id-action:hover {
  border-color: var(--blue-500);
  background: var(--blue-50);
}

/* === Ärenden === */
.arende-list {
  text-align: left;
}

.arende-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--gray-100);
}

.arende-item:last-child {
  border-bottom: none;
}

.arende-status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.arende-status.active { background: var(--blue-500); }
.arende-status.waiting { background: var(--yellow-500); }
.arende-status.done { background: var(--green-500); }

.arende-info {
  flex: 1;
  min-width: 0;
}

.arende-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--gray-800);
}

.arende-agency {
  font-size: 0.72rem;
  color: var(--gray-500);
}

.arende-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.arende-badge.pågående {
  background: var(--blue-100);
  color: var(--blue-600);
}

.arende-badge.väntar {
  background: var(--yellow-100);
  color: #92400e;
}

.arende-badge.klar {
  background: var(--green-100);
  color: #065f46;
}

/* === Meddelanden === */
.msg-list {
  text-align: left;
}

.msg-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--gray-100);
}

.msg-item:last-child {
  border-bottom: none;
}

.msg-item.unread {
  font-weight: 600;
}

.msg-icon {
  width: 36px;
  height: 36px;
  background: var(--gray-100);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  font-size: 0.9rem;
  flex-shrink: 0;
}

.msg-item.unread .msg-icon {
  background: var(--blue-100);
  color: var(--blue-600);
}

.msg-info {
  flex: 1;
  min-width: 0;
}

.msg-title {
  font-size: 0.83rem;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-item.unread .msg-title {
  font-weight: 700;
}

.msg-sender {
  font-size: 0.7rem;
  color: var(--gray-500);
  font-weight: 400;
}

.msg-time {
  font-size: 0.67rem;
  color: var(--gray-400);
  white-space: nowrap;
}

/* === Language Buttons === */
.lang-btn {
  flex: 1;
  padding: 10px 8px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: var(--white);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  text-align: center;
}

.lang-btn:hover {
  border-color: var(--blue-300, #93c5fd);
}

.lang-btn.active {
  border-color: var(--blue-500);
  background: var(--blue-50);
  color: var(--blue-600);
}

/* === Translate Overlay === */
.translate-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.translate-spinner {
  padding: 20px 40px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

/* === RTL Support === */
[dir="rtl"] .search-icon {
  left: auto;
  right: 14px;
}

[dir="rtl"] .search-input {
  padding: 14px 44px 14px 40px;
}

[dir="rtl"] .search-clear {
  right: auto;
  left: 12px;
}

[dir="rtl"] .card-message {
  border-left: none;
  border-right: 3px solid var(--blue-500);
}

[dir="rtl"] .card-message.personalized {
  border-right-color: var(--green-500);
}

[dir="rtl"] .card-auth {
  margin-left: 0;
  margin-right: 6px;
}

[dir="rtl"] .admin-toggle {
  right: auto;
  left: 12px;
}

[dir="rtl"] .card-link .lni-arrow-right {
  transform: scaleX(-1);
}

/* === Utility === */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
