:root {
  --clr-primary: #aa002f;
  --clr-text-brand: #740b28;
  --clr-secondary-action: #7d0022;
  --clr-text-main: rgb(4, 26, 71);
  --clr-text-secondary: #555;
  --clr-text-light: #ffffff;
  --clr-bg-main: #f0f2f5;
  --clr-bg-element: #ffffff;
  --clr-border: #ddd;
  --clr-disabled: #a9a9a9;
  --clr-listening-pulse: rgba(170, 0, 47, 0.7);
  --clr-send-button: rgb(4, 26, 71);
}

html {
  box-sizing: border-box;
}
*,
*:before,
*:after {
  box-sizing: inherit;
}

#appView,
#loginView {
  display: none;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Fira Sans", Helvetica, Roboto, Arial, sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 1.5rem;
  background-color: var(--clr-bg-main);
  color: var(--clr-text-main);
  font-size: 16px;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: 100%;
}
/* ============================================== */

#loginView {
  width: 100%;
  max-width: 520px;
}

.login-logo {
  max-width: 200px;
  margin-bottom: 2rem;
}
#signInBtn {
  margin-top: 1.5rem;
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
  background-color: var(--clr-primary);
  color: var(--clr-text-light);
  border: none;
  border-radius: 4px;
  font-weight: 500;
}

.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1200px;
  background: var(--clr-bg-element);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  height: auto;
}

header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--clr-border);
  background-color: #fafafa;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  min-height: 40px;
}

.header-logo {
  height: 40px;
}

h1 {
  color: var(--clr-text-brand);
  margin: 0;
  font-size: 1.25rem;
  font-weight: 500;
  text-align: right;
}

.tab-navigation {
  display: flex;
  gap: 0.5rem;
}

.tab-button {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  background-color: transparent;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition:
    color 0.2s,
    border-color 0.2s;
  color: var(--clr-text-secondary);
}

.tab-button.active {
  color: var(--clr-primary);
  border-bottom-color: var(--clr-primary);
}

.logout-button {
  align-self: center;
  justify-self: end;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  transition:
    color 0.2s,
    border-color 0.2s;
  font-size: 1rem;
  font-weight: 500;
  color: var(--clr-text-brand);
}

.logout-button:hover {
  color: var(--clr-primary);
  border-bottom-color: var(--clr-primary);
}

.main-content {
  flex-grow: 1;
  display: flex;
}

.tab-panel {
  display: none;
  width: 100%;
  flex-direction: column;
  gap: 1.25rem;
}
.tab-panel.active {
  display: flex;
}

#documentPanel,
#livePanel {
  padding: 1.5rem 2rem;
}

/* --- Conversation Panel Specifics --- */
#conversationPanel {
  display: none;
}
#conversationPanel.active {
  display: flex;
}
.conversation-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  flex-grow: 1;
}
.speaker-panel {
  padding: 1rem;
  display: flex;
  flex-direction: column;
}
.speaker-panel.caseworker {
  border-right: 1px solid var(--clr-border);
}
.speaker-panel.is-speaking {
  box-shadow: inset 0 0 15px var(--clr-listening-pulse);
}
h2 {
  margin-top: 0;
  margin-bottom: 1.5rem;
  color: var(--clr-text-main);
  font-weight: 500;
}
.language-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.language-selector label {
  font-weight: 500;
}
.language-selector span {
  font-size: 1rem;
  padding: 0.5rem;
  border-radius: 4px;
  height: 2.4rem;
  display: flex;
  align-items: center;
}

.language-selector select {
  font-size: 1rem;
  padding: 0.5rem;
  border-radius: 4px;
  height: 2.4rem;
  background-color: #fff;
  border: 1px solid var(--clr-border);
}
.text-area {
  width: 100%;
  min-height: 160px;
  font-size: 1.3rem;
  padding: 10px;
  border: 1px solid var(--clr-border);
  border-radius: 4px;
  resize: vertical;
  margin-top: 1rem;
  background-color: #fff;
  flex-grow: 1;
}
.action-bar {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}
.speak-button {
  flex-grow: 1;
  padding: 1rem;
  font-size: 1.1rem;
  border-radius: 8px;
  border: none;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background-color: var(--clr-primary);
  color: var(--clr-text-light);
}
.speak-button .mic-icon {
  width: 1.2em;
  height: 1.2em;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.send-button {
  padding: 1rem;
  font-size: 1.1rem;
  border-radius: 8px;
  border: none;
  font-weight: bold;
  cursor: pointer;
  background-color: var(--clr-send-button);
  color: white;
}
.speak-button.active {
  background-color: var(--clr-secondary-action);
  transform: scale(1.02);
}
button:disabled {
  background-color: var(--clr-disabled) !important;
  cursor: not-allowed !important;
}

/* Status Bar & Toggle */
.status-bar-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background-color: #f8f9fa;
  border-top: 1px solid var(--clr-border);
  border-bottom: 1px solid var(--clr-border);
}
#status {
  flex-grow: 1;
  font-style: italic;
  color: var(--clr-text-secondary);
}
.header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.toggle-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--clr-text-secondary);
}
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 28px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}
input:checked + .slider {
  background-color: var(--clr-primary);
}
input:checked + .slider:before {
  transform: translateX(22px);
}

/* History & Modal */
.history-panel {
  padding: 1.5rem;
  background-color: #fafafa;
}
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.history-header h2 {
  margin: 0;
}
.history-header .controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: nowrap;
}
.history-header button {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  background-color: #6c757d;
  color: white;
  border-radius: 4px;
  border: none;
  cursor: pointer;
}
#summarizeBtn {
  background-color: #17a2b8;
}
.history-log {
  max-height: 250px;
  overflow-y: auto;
  padding: 1rem;
  background-color: var(--clr-bg-element);
  border-radius: 4px;
  border: 1px solid var(--clr-border);
}
.history-entry {
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--clr-border);
}
.history-entry:last-child {
  border-bottom: none;
}

/* --- Styles for the new playback feature --- */
.history-entry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.history-entry strong {
  font-weight: 700;
}

.play-again-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--clr-text-secondary);
  transition:
    background-color 0.2s,
    color 0.2s;
}

.play-again-btn:hover {
  background-color: #e9ecef;
  color: var(--clr-text-main);
}
/* ------------------------------------------- */

.caseworker-entry strong {
  color: var(--clr-text-brand);
}
.client-entry strong {
  color: var(--clr-primary);
}
.original-text {
  font-size: 1rem;
}
.translated-text {
  font-size: 0.9rem;
  color: var(--clr-text-secondary);
  font-style: italic;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}
.modal-content {
  background: white;
  border-radius: 8px;
  width: 90%;
  max-width: 700px;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--clr-border);
}
.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
}
.modal-close-btn {
  font-size: 2rem;
  border: none;
  background: none;
  cursor: pointer;
}
.modal-body {
  padding: 1.5rem;
}
.modal-body textarea {
  width: 100%;
  height: 300px;
  resize: vertical;
}
.modal-footer {
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  border-top: 1px solid var(--clr-border);
}
.modal-footer button {
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  color: white;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  background-color: #6c757d;
}
.modal-footer button:hover:not(:disabled) {
  opacity: 0.9;
}
/* Style for the speak button when it is active/listening */
.speak-button.active {
  background-color: var(--clr-secondary-action);
  transform: scale(1.02);
  box-shadow: 0 0 15px var(--clr-listening-pulse);
}

/* --- Document & Live Panel Shared Styles --- */
#documentPanel,
#livePanel {
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}
.controls-grid {
  display: flex;
  gap: 1.5rem;
  align-items: center;
}
.action-button {
  padding: 0.8rem;
  font-size: 1.1rem;
  font-weight: 500;
  cursor: pointer;
  background-color: var(--clr-primary);
  color: var(--clr-text-light);
  border: none;
  border-radius: 4px;
  width: 100%;
}
.file-upload-area {
  border: 2px dashed var(--clr-border);
  border-radius: 8px;
  padding: 2.5rem;
  text-align: center;
  cursor: pointer;
  background-color: #fcfcfc;
}
.file-upload-area:hover,
.file-upload-area.dragover {
  background-color: #f8f9fa;
  border-color: var(--clr-primary);
}
.file-upload-area svg {
  color: var(--clr-primary);
  margin-bottom: 0.5rem;
  stroke: currentColor;
  stroke-width: 1;
  fill: none;
}
.file-upload-area p {
  margin: 0;
}
#fileName {
  font-weight: 500;
  margin-top: 0.5rem;
  display: inline-block;
}
.results-area {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}
.results-area h3 {
  margin-top: 0;
  margin-bottom: 0.5rem;
}
.results-area textarea {
  width: 100%;
  min-height: 200px;
  flex-grow: 1;
  resize: vertical;
  background-color: #f8f9fa;
}
.result-controls {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}
.result-controls button {
  padding: 0.5rem 1rem;
  background-color: #6c757d;
  color: white;
  border-radius: 4px;
  border: none;
  cursor: pointer;
}

/* Camera Section */
.camera-container {
  position: relative;
  width: 100%;
  padding-top: 75%;
  background-color: #000;
  border-radius: 8px;
  overflow: hidden;
}
#cameraFeed,
#overlayContainer,
.status-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
#cameraFeed {
  object-fit: cover;
}
.status-overlay {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 1.2rem;
}
#overlayContainer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.ocr-box {
  position: absolute;
  background-color: rgba(20, 20, 20, 0.9);
  color: white;
  font-size: 16px;
  font-weight: bold;
  line-height: 1.2;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2px 4px;
  box-sizing: border-box;
  white-space: nowrap;
  border-radius: 3px;
  transition: all 0.2s ease-in-out;
  padding: 2px 4px;
  line-height: 1.1;
  font-size: 14px;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  max-height: 1.4em;
}
#pageStatus {
  text-align: center;
  padding: 0.75rem;
  background-color: #f8f9fa;
  border-top: 1px solid var(--clr-border);
  font-style: italic;
  color: var(--clr-text-secondary);
}

/* ======================================= */
/* ===== RESPONSIVE DESIGN - ALL VIEWS ===== */
/* ======================================= */

/* --- DESKTOP VIEW --- */
@media (min-width: 901px) {
  .header-top {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    min-height: 60px;
  }

  .header-logo {
    grid-column: 1 / 2;
    justify-self: start;
    height: 60px;
  }

  h1 {
    grid-column: 2 / 3;
    font-size: 1.75rem;
    text-align: center;
  }

  /* ===== MODIFIED: Adjustments for better desktop layout ===== */
  .tab-button {
    font-size: 1.1rem; /* Make tab text larger and more readable */
  }

  #documentPanel,
  #livePanel {
    max-width: 960px; /* Allow content to use more screen width */
  }
}

/* --- MOBILE - PORTRAIT --- */
@media (max-width: 900px) {
  body {
    padding: 0;
  }
  h2 {
    font-size: 1rem;
  }

  .app-container {
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
  }
  header {
    padding: 0.75rem 1rem;
  }
  .header-top {
    margin-bottom: 0.75rem;
  }
  .tab-navigation {
    justify-content: center;
  }
  .tab-button {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
  }

  .conversation-grid {
    grid-template-columns: 1fr;
  }
  .conversation-grid h2 {
    margin: 0;
  }
  .speaker-panel.caseworker {
    border-right: none;
    border-bottom: 2px solid var(--clr-border);
  }
  .text-area {
    margin-top: 10px;
  }

  .controls-grid {
    flex-wrap: wrap;
  }

  .result-controls {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .speak-button {
    padding: 0.75rem;
    font-size: 1rem;
    gap: 0.4rem;
  }
  .speak-button span {
    font-size: 0.8rem;
    font-weight: 500;
  }

  #documentPanel,
  #livePanel {
    padding: 1rem;
  }

  .history-header .controls {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  h2 {
    margin: 0;
  }
  .tab-panel {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 1rem;
  }
  .camera-container {
    height: 100%;
  }
}

.speak-button:hover:not(:disabled),
.send-button:hover:not(:disabled),
.action-button:hover:not(:disabled) {
  opacity: 0.9;
}
.history-header button:hover:not(:disabled),
.result-controls button:hover:not(:disabled),
.modal-footer button:hover:not(:disabled) {
  opacity: 0.9;
}
.modal-close-btn:hover {
  opacity: 0.6;
}

.tab-button:hover:not(.active) {
  color: var(--clr-text-main);
  background-color: rgba(0, 0, 0, 0.04);
}

/* --- MOBILE - LANDSCAPE --- */
@media (max-width: 900px) and (orientation: landscape) {
  body {
    padding: 0;
    overflow-y: auto;
  }
  .app-container {
    height: 100vh;
  }

  header,
  #pageStatus,
  .history-panel,
  .status-bar-container,
  .controls-grid {
    display: none;
  }

  .main-content {
    height: 100%;
  }

  #conversationPanel.active {
    height: 100%;
    flex-direction: column;
  }
  .conversation-grid {
    grid-template-columns: 1fr 1fr;
    height: 100%;
  }

  .speaker-panel.caseworker {
    border-bottom: none;
    border-right: 1px solid var(--clr-border);
  }

  .speaker-panel {
    padding: 0.75rem;
    overflow-y: auto;
  }

  .text-area {
    min-height: 40px;
  }

  #livePanel.active {
    height: 100%;
    padding: 1rem;
  }

  .camera-container {
    flex-grow: 1;
    min-height: 150px;
    padding-top: 0;
  }

  #documentPanel.active {
    height: 100%;
    padding: 1rem;
    overflow-y: auto;
  }

  #documentPanel.active .results-area {
    flex-grow: 1;
  }
}
/* === Mobile menu – base (skjult som standard) === */
.mobile-menu {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 60%;
  max-width: 280px;

  background-color: var(--clr-bg-element);
  z-index: 3000;

  display: flex;
  flex-direction: column;
  padding: 1.5rem;

  transform: translateX(100%);
  transition: transform 0.25s ease-out;
}

.mobile-menu.open {
  transform: translateX(0);
}

/* === Burger skjult på desktop === */
.burger-button {
  display: none;
}
@media (max-width: 900px) {
  .burger-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    background: none;
    border: none;

    font-size: 1.5rem;
    line-height: 1;
    font-weight: 500;

    color: var(--clr-text-brand);

    padding: 0.5rem 0.75rem;
    border-radius: 6px;

    cursor: pointer;

    transition:
      background-color 0.2s ease,
      transform 0.1s ease;
  }

  .burger-button:hover {
    background-color: rgba(0, 0, 0, 0.04);
  }

  .burger-button:active {
    transform: scale(0.96);
  }
  .tab-navigation {
    display: none;
  }
  .header-top h1,
  .logout-button {
    display: none;
  }
}
.mobile-menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 2500;

  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease-out;
}

.mobile-menu-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.mobile-menu #closeMenuBtn {
  align-self: flex-end;
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--clr-text-secondary);
  margin-bottom: 0.75rem;
}
.mobile-menu #closeMenuBtn:hover {
  color: var(--clr-text-main);
}
.mobile-menu nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.mobile-tab {
  background: transparent;
  border: none;

  padding: 0.75rem 0;
  font-size: 1rem;
  font-weight: 500;

  text-align: left;
  color: var(--clr-text-secondary);
  cursor: pointer;
}
.mobile-tab:hover {
  color: var(--clr-text-main);
}

.mobile-tab:active {
  color: var(--clr-primary);
}

@media (max-width: 480px) {
  #loginView {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
  }

  .login-card {
    width: 100%;
    max-width: 420px;
    max-height: calc(100dvh - 2rem);
    overflow: auto;

    padding: 2rem 1.5rem;
    gap: 0.75rem;
  }

  .login-logo {
    max-width: 150px;
    margin-bottom: 0.5rem;
  }

  .login-title,
  .login-text {
    word-break: break-word;
    overflow-wrap: anywhere;
    hyphens: auto;
    text-wrap: balance;
  }

  .login-title {
    font-size: 1.3rem;
    line-height: 1.2;
    text-align: center;
  }

  .login-text {
    font-size: 0.95rem;
  }

  #signInBtn {
    width: 100%;
    padding: 0.9rem;
    font-size: 1rem;
    border-radius: 8px;
  }
}
/* ========================= */
/* ===== LOGIN MODE ======== */
/* ========================= */

body.login-mode {
  justify-content: center;
  margin-top: 3rem;
}

body.login-mode .app-container {
  display: none;
}

#loginView {
  width: 100%;
  max-width: 520px;
}

.login-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;

  padding: 3rem 2.5rem;
  background: var(--clr-bg-element);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  text-align: center;
}

.login-logo {
  max-width: 200px;
  margin-bottom: 1rem;
}

.login-title {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--clr-text-brand);
  text-align: center;
}

.login-text {
  margin: 0;
  font-size: 1rem;
  color: var(--clr-text-secondary);
  max-width: 420px;
}

#signInBtn {
  margin-top: 1.5rem;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;

  background-color: var(--clr-primary);
  color: var(--clr-text-light);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.app-loader {
  position: fixed;
  inset: 0;
  background: var(--clr-bg-page, #f7f7f7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(0, 0, 0, 0.1);
  border-top-color: var(--clr-primary, #005bbb);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

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