/* Pages: templates/app.html and the base layout of templates/portal.html and demo.html.
   UI order: foundation -> header -> content -> forms -> dialogs -> footer.
   Shared property dependencies and responsive override positions preserve the cascade. */
/* 01 Shared foundation */
:root {
  font-family: system-ui,-apple-system,"Segoe UI",sans-serif;
  color: #183341;
  background: #f2f5f4;
  font-size: 16px;
  line-height: 1.55;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

a {
  color: #08766a;
}

button,input,select,textarea {
  font: inherit;
}

button,.button,.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 15px;
  border: 1px solid #bed0ce;
  border-radius: 9px;
  background: #fff;
  color: #183341;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  text-align: center;
}

button:hover,.button:hover {
  background: #e8f2ef;
}

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.primary {
  background: #087568;
  color: white;
  border-color: #087568;
}

.primary:hover {
  background: #075e54;
}

.quiet {
  background: transparent;
}

input,textarea,select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 11px 12px;
  border: 1px solid #b4c7c7;
  border-radius: 8px;
  background: #fff;
  min-height: 44px;
}

textarea {
  resize: vertical;
}

label {
  display: block;
  font-weight: 600;
  margin: 12px 0 6px;
}

button:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible,a:focus-visible,summary:focus-visible {
  outline: 3px solid #d7872c;
  outline-offset: 3px;
}

[hidden] {
  display: none!important;
}

.file-button:focus-within {
  outline: 3px solid #d7872c;
}

/* 02 Header and navigation */
.app-header {
  background: #122a37;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px max(18px,env(safe-area-inset-right));
  gap: 15px;
}

.brand {
  color: #c4ebd5;
  text-decoration: none;
  font-size: 22px;
  font-weight: 800;
}

.brand span {
  color: #fff;
  font-size: 17px;
  margin-left: 12px;
}

/* 01 Shared foundation */
.mode {
  font-size: 13px;
  color: #b9cece;
}

main {
  width: min(1500px,100%);
  margin: auto;
  padding: 24px max(16px,env(safe-area-inset-left)) 48px;
}

.card {
  background: #fff;
  border: 1px solid #d8e3df;
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 18px;
  min-width: 0;
}

.login-card {
  max-width: 520px;
  margin: 7vh auto;
}

.login-card button {
  width: 100%;
  margin-top: 18px;
}

/* 02 Header and navigation */
.tabs button {
  border: 0;
  background: #e2eae6;
}

/* 04 Main content and research panels */
.workspace-heading {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
}

/* 01 Shared foundation */
h1 {
  font-size: clamp(1.8rem,4vw,2.7rem);
  line-height: 1.15;
  letter-spacing: -.04em;
  margin: 5px 0 12px;
}

h2 {
  font-size: 1.35rem;
  line-height: 1.3;
  margin: 0 0 12px;
}

h3 {
  font-size: 1.1rem;
  margin-top: 24px;
}

.eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .16em;
  color: #087568;
  margin: 0 0 8px;
}

.muted,.hint {
  color: #526b74;
}

.hint {
  font-size: 13px;
  margin: 7px 0 14px;
}

.report {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  font-size: 14px;
  line-height: 1.7;
  max-width: 100%;
}

.report a {
  font-weight: 700;
}

.file-button {
  font-size: 14px;
}

/* 02 Header and navigation */
.tabs button[aria-pressed=true] {
  background: #122a37;
  color: #fff;
}

/* 01 Shared foundation */
.empty {
  border: 1px dashed #c5d5d0;
  border-radius: 10px;
  padding: 22px;
  color: #657c83;
}

.danger {
  color: #a03225;
}

/* 05 Forms, plans and account controls */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 4px 18px;
}

/* 01 Shared foundation */
.identity {
  grid-template-columns: 1fr 1.5fr 1.5fr;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  margin: 16px 0;
}

.actions select,.actions input {
  width: auto;
  flex: 1 1 140px;
}

.actions label {
  margin: 0;
}

.result-card {
  align-self: start;
}

.file-button input {
  width: 1px;
  height: 1px;
  min-height: 0;
  padding: 0;
  position: absolute;
  clip-path: inset(50%);
}

summary {
  cursor: pointer;
  font-weight: 650;
  min-height: 35px;
}

/* 02 Header and navigation */
.tabs {
  display: grid;
  grid-template-columns: repeat(4,minmax(0,1fr));
  gap: 6px;
  margin: 24px 0 18px;
}

/* 01 Shared foundation */
.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(0,1fr);
  gap: 20px;
}

details {
  margin: 20px 0;
  border-top: 1px solid #d8e3df;
  padding-top: 16px;
}

.saved-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-top: 1px solid #d8e3df;
  padding: 16px 0;
}

.saved-row p {
  margin: 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.saved-row strong {
  display: block;
  font-size: 17px;
}

.saved-row .actions {
  margin: 0;
  flex-shrink: 0;
}

#status {
  position: sticky;
  bottom: 10px;
  border-radius: 10px;
  background: #122a37;
  color: #fff;
  padding: 14px 18px;
  box-shadow: 0 8px 30px #142c3422;
  margin-top: 14px;
  overflow-wrap: anywhere;
}

#status:empty {
  display: none;
}

code {
  overflow-wrap: anywhere;
}

/* 06 Dialogs and reading controls */
#status.error {
  background: #8c3026;
}

/* 07 Closing content and footer */
footer {
  text-align: center;
  color: #657c83;
  font-size: 12px;
  padding: 20px 12px calc(20px + env(safe-area-inset-bottom));
}

/* 01 Shared foundation */
.sr-only,.skip {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
}

.skip:focus {
  width: auto;
  height: auto;
  clip-path: none;
  z-index: 10;
  background: white;
  padding: 10px;
}

/* 08 Responsive and display overrides */
@media(max-width:850px) {
  /* 01 Shared foundation */
  .analysis-grid {
    grid-template-columns: minmax(0,1fr);
  }

  .identity {
    grid-template-columns: minmax(0,1fr);
  }

  .card {
    padding: 19px;
  }

  .mode {
    display: none;
  }

}

@media(max-width:480px) {
  /* 01 Shared foundation */
  main {
    padding: 18px max(12px,env(safe-area-inset-left)) 30px;
  }

  .card {
    padding: 16px;
    border-radius: 12px;
  }

  .saved-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .saved-row .actions {
    width: 100%;
  }

  .actions>* {
    max-width: 100%;
  }

  /* 02 Header and navigation */
  .tabs {
    gap: 4px;
  }

  .tabs button {
    padding: 10px 4px;
    font-size: 14px;
  }

  .brand span {
    font-size: 16px;
  }

  /* 01 Shared foundation */
  .report {
    font-size: 13px;
  }

  /* 04 Main content and research panels */
  .workspace-heading {
    align-items: flex-start;
  }

  /* 05 Forms, plans and account controls */
  .form-grid {
    grid-template-columns: minmax(0,1fr);
  }

}

/* 01 Shared foundation */
/* Tutorial stays bright over an inert, dimmed workspace, even on a small phone. */
body.tutorial-active {
  overflow: hidden;
}

/* 06 Dialogs and reading controls */
#tutorial-dialog {
  padding: 0;
  border: 3px solid #a5ce78;
  border-radius: 16px;
  background: #f8f8f1;
  color: #163730;
  width: min(600px,calc(100% - 24px));
  max-width: calc(100% - 24px);
  max-height: calc(100dvh - 24px);
  box-shadow: 0 24px 80px #0008;
}

#tutorial-dialog::backdrop,#info-dialog::backdrop {
  background: rgba(0,0,0,.8);
}

.tutorial-card {
  padding: clamp(16px,4vw,30px);
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 30px);
}

#tutorial-title {
  font-size: clamp(23px,5vw,32px);
  line-height: 1.2;
  margin: 8px 0 18px;
  flex-shrink: 0;
}

.tutorial-copy,.info-copy {
  overflow-y: auto;
  min-height: 0;
  line-height: 1.65;
}

.tutorial-copy {
  overscroll-behavior: contain;
}

.tutorial-copy h3 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .07em;
  margin: 8px 0;
}

.tutorial-copy p {
  margin: 0 0 20px;
}

/* 04 Main content and research panels */
.info-copy li {
  margin-bottom: 12px;
}

/* 02 Header and navigation */
.app-header .mode {
  margin-left: auto;
}

/* 06 Dialogs and reading controls */
.tutorial-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 16px;
  flex-shrink: 0;
}

/* 04 Main content and research panels */
/* Keep Info actions visible while its guide scrolls. */
#info-dialog {
  padding: 0;
  border: 3px solid #a5ce78;
  border-radius: 16px;
  background: #f8f8f1;
  color: #163730;
  width: min(720px,calc(100% - 24px));
  max-width: calc(100% - 24px);
  max-height: calc(100dvh - 24px);
}

.info-card {
  padding: clamp(16px,4vw,28px);
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 30px);
  gap: 12px;
}

/* 02 Header and navigation */
.app-header {
  gap: 12px;
}

/* 04 Main content and research panels */
.info-card>button {
  flex-shrink: 0;
  align-self: flex-end;
}

/* 06 Dialogs and reading controls */
.tutorial-actions button {
  min-height: 44px;
}

/* Preserve CSV example rows and let the longer product name wrap. */
.tutorial-copy p {
  white-space: pre-line;
  overflow-wrap: anywhere;
}

/* 02 Header and navigation */
.app-header .brand {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* 04 Main content and research panels */
.info-copy {
  overflow-wrap: anywhere;
}
