@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --bg:        #10171A;
  --surface:   #182225;
  --surface-2: #1F2B2F;
  --border:    #2A373C;
  --text:      #E7EDEE;
  --text-dim:  #8FA0A5;
  --accent:    #D9A441; /* signalfärg, används sparsamt */
  --accent-ink:#2A1F08;
  --status-new:     #5FA8D3;
  --status-open:    #D9A441;
  --status-pending: #E08A4C;
  --status-closed:  #6E8A82;
  --danger:    #E0654C;

  --radius: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* Se till att HTML:s "hidden"-attribut alltid vinner, även över
   element som själva sätter display:flex (t.ex. login-rutan,
   #mainApp, ikonknappar). Annars kan CSS-specificitet göra att
   "dolda" element ändå visas. */
[hidden] {
  display: none !important;
}
.custom-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 8px;
  flex: 1;
  min-width: 120px;
}
.custom-input:focus {
  outline: none;
  border-color: var(--accent);
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

#mainApp {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }

/* ---------- Topbar ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px calc(12px) 14px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:active { background: var(--surface-2); color: var(--text); }
.back-btn svg { width: 20px; height: 20px; }

/* ---------- Main / views ---------- */
#app {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.view { min-height: 100%; }

/* ---------- Filter chips ---------- */
.filter-row {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  overflow-x: auto;
}

.chip {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
}

.chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 500;
}

/* ---------- Case list ---------- */
.case-list {
  list-style: none;
  margin: 0;
  padding: 0 10px 10px;
}

.case-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px;
  margin-bottom: 8px;
  display: block;
  width: 100%;
  text-align: left;
  color: inherit;
  font-family: inherit;
}

.case-card:active { background: var(--surface-2); }

.case-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.case-id {
  font-size: 12px;
  color: var(--text-dim);
  flex: 1;
}

.case-time {
  font-size: 12px;
  color: var(--text-dim);
}

.case-subject {
  font-size: 15px;
  font-weight: 500;
  margin: 0 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.case-preview {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Empty / loading / error states ---------- */
.state-msg {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 30px 20px;
}

.state-msg.is-error { color: var(--danger); }

.load-more {
  display: block;
  margin: 4px auto 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 20px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 13px;
}

/* ---------- Thread view ---------- */
.case-meta {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.case-meta h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 8px;
}

.case-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.status-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 8px;
  max-width: 55%;
}

.status-select:disabled { opacity: 0.5; }

.case-meta .tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.tag {
  font-size: 11px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 14px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.post {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.post-agent {
  align-self: flex-end;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-right-radius: 3px;
}

.post-customer {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

.post-note {
  align-self: center;
  max-width: 96%;
  background: #241C0C;
  border: 1px dashed #4A3A15;
  color: #E3C387;
}

.post-meta {
  display: flex;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

/* ---------- Composer ---------- */
.composer {
  flex: 0 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + var(--safe-bottom));
}

.note-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  padding: 2px 4px 6px;
}

.note-toggle input { accent-color: var(--accent); }

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

#replyText {
  flex: 1;
  resize: none;
  max-height: 120px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--text);
  padding: 9px 14px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
}

#replyText:focus { outline: none; border-color: var(--accent); }

.send-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-btn svg { width: 17px; height: 17px; }
.send-btn:disabled { opacity: 0.4; }

@media (prefers-reduced-motion: no-preference) {
  .case-card, .chip { transition: background-color .12s ease; }
}

/* ---------- Inloggning ---------- */
.login-screen {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0;
  text-align: center;
}

.login-sub {
  margin: -6px 0 6px;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.login-field input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 11px 12px;
  font-family: inherit;
  font-size: 15px;
}

.login-field input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-submit {
  margin-top: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
}

.login-submit:disabled { opacity: 0.6; }

.login-error {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  margin: 0;
}
