:root {
  color-scheme: dark; /* webbläsarens egna kontroller (menyer, fält) i mörkt läge */
  --bg: #0b0b14;
  --bg-soft: #13131f;
  --card: #181828;
  --border: #2a2a40;
  --text: #ececf4;
  --muted: #9a9ab3;
  --violet: #8b5cf6;
  --cyan: #22d3ee;
  --grad: linear-gradient(135deg, var(--violet), var(--cyan));
  --radius: 16px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

/* Dölj scrollbarer överallt – det går fortfarande att scrolla med mushjul, styrplatta och touch. */
* { scrollbar-width: none; }
*::-webkit-scrollbar { display: none; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }

.gradient-text {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, opacity .15s;
  font: inherit;
  font-weight: 600;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
  background: var(--grad);
  border: none;
  color: #fff;
  box-shadow: 0 8px 30px -8px rgba(139, 92, 246, .6);
}
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ---------- Navigering ---------- */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  max-width: 1150px;
  margin: 0 auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -.02em;
}
.brand img { width: 34px; height: 34px; }
.nav-links { display: flex; gap: 22px; align-items: center; }
.nav-links a:not(.btn) { color: var(--muted); }
.nav-links a:not(.btn):hover { color: var(--text); }

/* ---------- Startsida ---------- */
.hero {
  position: relative;
  text-align: center;
  padding: 90px 20px 70px;
  max-width: 900px;
  margin: 0 auto;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 0 10% auto;
  height: 380px;
  background: radial-gradient(closest-side, rgba(139, 92, 246, .35), transparent);
  filter: blur(40px);
  z-index: -1;
}
.pill {
  display: inline-block;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: .85rem;
  margin-bottom: 22px;
  background: var(--bg-soft);
}
.hero h1 {
  font-size: clamp(2.4rem, 7vw, 4.4rem);
  line-height: 1.05;
  letter-spacing: -.04em;
  margin: 0 0 20px;
}
.hero p {
  font-size: 1.2rem;
  color: var(--muted);
  max-width: 620px;
  margin: 0 auto 34px;
}
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.section {
  max-width: 1150px;
  margin: 0 auto;
  padding: 60px 24px;
}
.section h2 {
  text-align: center;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: -.03em;
  margin: 0 0 40px;
}
.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}
.feature {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
}
.feature .icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(139, 92, 246, .15);
  font-size: 1.3rem;
  margin-bottom: 14px;
}
.feature h3 { margin: 0 0 6px; font-size: 1.1rem; }
.feature p { margin: 0; color: var(--muted); }

.cta {
  text-align: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 56px 24px;
  background-image: radial-gradient(circle at top, rgba(34, 211, 238, .12), transparent 60%);
}
.cta h2 { margin-bottom: 14px; }
.cta p { color: var(--muted); margin: 0 0 28px; }

footer {
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
  padding: 40px 20px;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

/* ---------- Chatt ---------- */
.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}
.chat-page {
  flex: 1;
  min-width: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.chat-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Sidomeny med chattar ---------- */
.sidebar {
  width: 270px;
  flex: 0 0 270px;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  gap: 12px;
}
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px;
}
.new-chat-btn { justify-content: center; width: 100%; padding: 10px 16px; border-radius: 12px; }
.new-chat-btn:hover { border-color: var(--violet); }
.chat-list {
  flex: 1;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px;
}
.chat-group {
  color: var(--muted);
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 14px 10px 6px;
}
.chat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 10px;
  color: var(--muted);
}
.chat-item:hover { background: var(--card); color: var(--text); }
.chat-item.active { background: var(--card); color: var(--text); box-shadow: inset 2px 0 0 var(--violet); }
.chat-item .open {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  font-size: .92rem;
  text-align: left;
  padding: 9px 10px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item .actions { display: none; padding-right: 4px; }
.chat-item:hover .actions, .chat-item.active .actions, .chat-item:focus-within .actions { display: flex; }
.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
}
.icon-btn:hover { background: var(--border); color: var(--text); }
.chat-item .icon-btn { width: 26px; height: 26px; font-size: .85rem; }
.chat-item input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--violet);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: .92rem;
  padding: 6px 8px;
  margin: 2px;
  outline: none;
}
.chat-list-empty { color: var(--muted); font-size: .88rem; padding: 12px 10px; }
.sidebar-foot { color: var(--muted); font-size: .75rem; padding: 0 6px; }
.menu-btn, .sidebar-close { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 10;
    background: rgba(0, 0, 0, .5);
  }
  .menu-btn, .sidebar-close { display: inline-grid; }
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
.chat-header .btn { padding: 8px 16px; font-size: .9rem; }
.header-actions { display: flex; gap: 10px; align-items: center; }
.model-select {
  appearance: none;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%239a9ab3' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 14px center;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  padding: 8px 36px 8px 16px;
  cursor: pointer;
  flex-shrink: 0;
  transition: width .15s ease, border-color .15s ease;
}
.model-select:hover, .model-select:focus { border-color: var(--violet); outline: none; }
.model-select option { background: var(--card); }
.msg .token-tag {
  display: block;
  color: var(--muted);
  font-size: .75rem;
  margin-top: 6px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 12px;
}
.messages-inner {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.welcome {
  text-align: center;
  margin-top: 8vh;
}
.welcome img { width: 64px; height: 64px; margin-bottom: 14px; }
.welcome h1 { margin: 0 0 8px; font-size: 2rem; letter-spacing: -.03em; }
.welcome p { color: var(--muted); margin: 0 0 28px; }
.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  text-align: left;
}
.suggestion {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: border-color .15s;
}
.suggestion:hover { border-color: var(--violet); }
.suggestion small { display: block; color: var(--muted); }

.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg .avatar {
  flex: 0 0 32px;
  width: 32px; height: 32px;
  border-radius: 10px;
}
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 18px 18px 4px 18px;
  max-width: 80%;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.assistant .bubble {
  flex: 1;
  min-width: 0;
  padding-top: 3px;
}
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre {
  background: #07070d;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  overflow-x: auto;
}
/* Kodblock med en rad för språk + Copy-knapp */
.code-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin: 1em 0;
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px 5px 14px;
  background: #12121e;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: .78rem;
  font-family: "JetBrains Mono", Consolas, monospace;
}
.code-block pre { margin: 0; border: none; border-radius: 0; }
.copy-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  font-family: "Inter", system-ui, sans-serif;
  font-size: .78rem;
  padding: 3px 9px;
  cursor: pointer;
}
.copy-btn:hover { color: var(--text); border-color: var(--border); background: var(--card); }
.copy-btn.copied { color: var(--cyan); }
.bubble code {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: .9em;
}
.bubble :not(pre) > code {
  background: var(--card);
  padding: 2px 6px;
  border-radius: 6px;
}
.bubble a { color: var(--cyan); text-decoration: underline; }
.bubble table { border-collapse: collapse; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; }

.typing span {
  display: inline-block;
  width: 7px; height: 7px;
  margin-right: 4px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

.composer {
  padding: 12px 16px 18px;
}
.composer form {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 10px 10px 18px;
  transition: border-color .15s;
}
.composer form:focus-within { border-color: var(--violet); }
.composer textarea {
  flex: 1;
  resize: none;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font: inherit;
  max-height: 200px;
  padding: 8px 0;
}
.composer textarea::placeholder {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.composer .btn { padding: 10px 18px; }
.composer .hint {
  max-width: 780px;
  margin: 8px auto 0;
  text-align: center;
  color: var(--muted);
  font-size: .78rem;
}

@media (max-width: 640px) {
  .nav-links a:not(.btn) { display: none; }
  .hero { padding-top: 60px; }
  .model-select { max-width: 150px; }
}

/* ---------- Inloggning ---------- */
[hidden] { display: none !important; }
.auth-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background-image: radial-gradient(circle at 50% 0%, rgba(139, 92, 246, .25), transparent 55%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
}
.auth-brand { justify-content: center; margin-bottom: 22px; }
.auth-card h1 { margin: 0 0 6px; font-size: 1.6rem; letter-spacing: -.02em; text-align: center; }
.auth-sub { margin: 0 0 24px; color: var(--muted); text-align: center; font-size: .95rem; }
.google-btn {
  width: 100%;
  justify-content: center;
  background: #fff;
  color: #1f1f1f;
  border: none;
  padding: 12px 18px;
}
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: .85rem;
  margin: 18px 0;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
#auth-form { display: flex; flex-direction: column; gap: 14px; }
#auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; font-weight: 600; }
#auth-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font: inherit;
  font-weight: 400;
  outline: none;
}
#auth-form input:focus { border-color: var(--violet); }
.auth-submit { width: 100%; justify-content: center; margin-top: 4px; }
.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--cyan);
  font: inherit;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }
.forgot-link { align-self: flex-end; font-size: .85rem; margin-top: -6px; }
.auth-message { font-size: .9rem; border-radius: 10px; }
.auth-message.error, .auth-message.success { padding: 10px 12px; }
.auth-message.error { background: rgba(239, 68, 68, .12); color: #fca5a5; }
.auth-message.success { background: rgba(34, 211, 238, .12); color: #a5f3fc; }
.auth-switch { text-align: center; color: var(--muted); font-size: .9rem; margin: 20px 0 0; }

/* Användarruta i sidomenyn */
.user-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 6px 0;
  border-top: 1px solid var(--border);
}
.user-avatar {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--grad);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-email { flex: 1; min-width: 0; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout-btn { font-size: .8rem; padding: 6px 10px; }
.auth-pending .app { visibility: hidden; }

/* Tokenmätare i sidomenyn */
.usage-box { padding: 0 6px; font-size: .78rem; color: var(--muted); }
.usage-row { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.usage-row span:first-child { color: var(--text); font-weight: 600; }
.usage-bar { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.usage-fill { height: 100%; width: 0; border-radius: 999px; background: var(--grad); transition: width .3s ease; }
.usage-meter + .usage-meter { margin-top: 10px; }
.usage-meter.warn .usage-fill { background: #f59e0b; }
.usage-meter.full .usage-fill { background: #ef4444; }
.usage-reset { margin-top: 6px; }
.usage-reset:empty { display: none; }
.usage-meter.full .usage-reset { color: #fca5a5; }

/* Veyriz Pro: knapp i sidomenyn och uppgraderingsruta */
.plan-btn { width: 100%; justify-content: center; padding: 9px 14px; font-size: .85rem; border-radius: 12px; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 30px 28px 24px;
  background-image: radial-gradient(circle at top, rgba(139, 92, 246, .18), transparent 60%);
}
.modal-close { position: absolute; top: 12px; right: 12px; }
.modal-card h2 { margin: 0 0 6px; font-size: 1.5rem; letter-spacing: -.02em; }
.modal-sub { margin: 0 0 18px; color: var(--muted); }
.plan-features { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 10px; }
.plan-features li { padding-left: 28px; position: relative; }
.plan-features li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 1px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: .75rem;
  font-weight: 700;
  color: #fff;
  background: var(--grad);
}
.plan-price { font-size: 1.8rem; font-weight: 800; letter-spacing: -.02em; margin-bottom: 14px; min-height: 1.2em; }
.modal-card .auth-message { margin-bottom: 12px; }
.modal-note { margin: 12px 0 0; text-align: center; color: var(--muted); font-size: .78rem; }

/* Priser på startsidan */
.pricing { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; max-width: 760px; margin: 0 auto; }
.price-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; display: flex; flex-direction: column; }
.price-card.featured { border-color: var(--violet); box-shadow: 0 10px 40px -12px rgba(139, 92, 246, .5); }
.price-card h3 { margin: 0 0 4px; font-size: 1.2rem; }
.price-card .amount { font-size: 2rem; font-weight: 800; letter-spacing: -.03em; margin: 8px 0 18px; }
.price-card .amount small { font-size: .9rem; font-weight: 400; color: var(--muted); }
.price-card .plan-features { flex: 1; }
.price-card .btn { justify-content: center; }

/* Konto i startsidans meny */
.nav-auth { display: flex; gap: 22px; align-items: center; }
.auth-checking .nav-auth { visibility: hidden; }
.nav-account { padding: 6px 14px 6px 6px; gap: 10px; max-width: 260px; }
.nav-account .user-avatar { flex: 0 0 30px; width: 30px; height: 30px; font-size: .85rem; }
.nav-email { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 640px) {
  .nav-auth a:not(.btn) { display: none; }
  .nav-account { padding: 5px; }
  .nav-email { display: none; }
}
