/* ==========================================================================
   Survey Operations Control — theme layer
   Palette taken from the Lao Social Research logo:
     #D63812  deep red-orange   (primary actions, emphasis)
     #FE6744  coral             (active state, progress, highlights)
     #1E3044  navy-charcoal     (shell, headings, body text)
   ========================================================================== */

:root {
  --lsr-orange:        #D63812;
  --lsr-orange-dark:   #B32C0C;
  --lsr-coral:         #FE6744;
  --lsr-coral-soft:    #FDF2EE;
  --lsr-navy:          #1E3044;
  --lsr-navy-700:      #2A4055;
  --lsr-navy-600:      #3A5169;
  --lsr-navy-300:      #B8C4D2;
  --lsr-navy-400:      #7C8CA0;

  --lsr-ink:           #1E3044;
  --lsr-ink-muted:     #6B7684;
  --lsr-ink-faint:     #8A9199;

  --lsr-page:          #F7F8FA;
  --lsr-surface:       #FFFFFF;
  --lsr-line:          #E4E7EC;
  --lsr-line-soft:     #EDEFF2;

  --lsr-radius:        10px;
  --lsr-radius-sm:     7px;
  --lsr-sidebar-w:     236px;

  /* Bootstrap overrides — these cascade to every stock component. */
  --bs-primary:            #D63812;
  --bs-primary-rgb:        214, 56, 18;
  --bs-link-color:         #D63812;
  --bs-link-color-rgb:     214, 56, 18;
  --bs-link-hover-color:   #B32C0C;
  --bs-body-color:         #1E3044;
  --bs-body-color-rgb:     30, 48, 68;
  --bs-body-bg:            #F7F8FA;
  --bs-border-color:       #E4E7EC;
  --bs-border-radius:      10px;
  --bs-border-radius-sm:   7px;
  --bs-border-radius-lg:   12px;
  --bs-focus-ring-color:   rgba(214, 56, 18, 0.2);
}

/* ===== Typography ===================================================== */

body {
  font-family: "Noto Sans", "Noto Sans Lao", system-ui, -apple-system, "Segoe UI", sans-serif;
  background-color: var(--lsr-page);
  color: var(--lsr-ink);
  font-size: 0.94rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Lao glyphs sit lower and need more line height than Latin. */
:lang(lo) body,
html[lang="lo"] body {
  font-family: "Noto Sans Lao", "Noto Sans", system-ui, sans-serif;
  line-height: 1.85;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--lsr-navy);
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.28rem; }
h3 { font-size: 1.12rem; }
h4 { font-size: 1rem; }

a { text-decoration: none; }
a:hover { text-decoration: underline; }

.text-primary { color: var(--lsr-orange) !important; }
.text-muted   { color: var(--lsr-ink-muted) !important; }

.page-title {
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--lsr-navy);
  margin-bottom: 0.25rem;
}

.page-subtitle {
  color: var(--lsr-ink-muted);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

/* ===== Layout ========================================================= */

.app-layout {
  display: flex;
  min-height: 100vh;
  background: var(--lsr-page);
}

.sidebar {
  width: var(--lsr-sidebar-w);
  flex-shrink: 0;
  background: var(--lsr-navy);
  display: flex;
  flex-direction: column;
}

/* base.html nests .sidebar inside .sidebar; neutralise the inner one so it
   does not re-apply the width and background. */
.sidebar .sidebar {
  width: auto;
  background: transparent;
}

.main-content {
  flex-grow: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-left: none;
  background: var(--lsr-page);
}

.content-wrapper {
  padding: 1.75rem 2rem 3rem;
  max-width: 1400px;
  width: 100%;
}

/* ===== Brand mark ===================================================== */

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 60px;
  padding: 0 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  flex-shrink: 0;
}

.sidebar-brand img {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

.sidebar-brand span {
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

/* ===== Top bar ======================================================== */

.top-bar {
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--lsr-line);
  background: var(--lsr-surface);
  flex-shrink: 0;
}

.main-content .top-bar {
  justify-content: flex-end;
}

/* The sidebar's own .top-bar is replaced by .sidebar-brand. */
.sidebar .top-bar {
  display: none;
}

/* ===== Sidebar navigation ============================================= */

.sidebar .nav {
  padding-top: 0.5rem;
}

.sidebar .nav-link {
  color: var(--lsr-navy-300);
  border-radius: var(--lsr-radius-sm);
  margin: 2px 10px;
  padding: 8px 12px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.sidebar .nav-link:hover {
  background-color: rgba(255, 255, 255, 0.07);
  color: #fff;
  text-decoration: none;
}

.sidebar .nav-link.active {
  background-color: var(--lsr-coral);
  color: #fff;
  font-weight: 500;
}

.sidebar .nav-link.active:hover {
  background-color: var(--lsr-coral);
  color: #fff;
}

.sidebar-section {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--lsr-navy-400);
  padding: 1rem 1.375rem 0.375rem;
}

/* ===== Tabs =========================================================== */

.nav-tabs {
  border-bottom: 1px solid var(--lsr-line);
  gap: 0.25rem;
}

.nav-tabs .nav-link {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--lsr-ink-muted);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.6rem 0.9rem;
  margin-bottom: -1px;
}

.nav-tabs .nav-link:hover {
  border-color: transparent transparent var(--lsr-line);
  color: var(--lsr-navy);
  text-decoration: none;
  background: transparent;
}

.nav-tabs .nav-link.active {
  color: var(--lsr-orange);
  background: transparent;
  border-color: transparent transparent var(--lsr-orange);
}

/* ===== Cards ========================================================== */

.card {
  border-radius: 12px;
  border: 1px solid var(--lsr-line);
  background: var(--lsr-surface);
  overflow: hidden;
}

.card + .card { margin-top: 1rem; }

.card-header {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--lsr-navy);
  background-color: var(--lsr-surface);
  border-color: var(--lsr-line);
  padding: 0.875rem 1.125rem;
}

.card-footer {
  background-color: var(--lsr-surface);
  border-color: var(--lsr-line);
}

.card-body { padding: 1.125rem; }

/* ===== Metric cards =================================================== */

.metric-card {
  text-align: left;
  padding: 1.125rem 1.25rem;
  background: var(--lsr-surface);
  border: 1px solid var(--lsr-line);
  border-radius: 12px;
  height: 100%;
}

.metric-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--lsr-ink-muted);
  letter-spacing: 0.07em;
  margin-bottom: 0.25rem;
}

.metric-value {
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.15;
  color: var(--lsr-navy);
  letter-spacing: -0.02em;
}

.metric-card.is-alert .metric-value { color: var(--lsr-orange); }
.metric-card.is-good  .metric-value { color: #1D9E75; }

.metric-caption {
  font-size: 0.75rem;
  color: var(--lsr-ink-faint);
  margin-top: 0.125rem;
}

/* ===== Buttons ======================================================== */

.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--lsr-radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.4rem 0.9rem;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn:hover { text-decoration: none; }

.btn-lg { padding: 0.7rem 1.1rem; min-height: 46px; font-size: 0.95rem; }
.btn-sm { min-height: 32px; padding: 0.25rem 0.7rem; font-size: 0.8125rem; }

.btn-primary {
  background-color: var(--lsr-orange);
  border-color: var(--lsr-orange);
  color: #fff;
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
  background-color: var(--lsr-orange-dark) !important;
  border-color: var(--lsr-orange-dark) !important;
  color: #fff !important;
}

.btn-outline-primary {
  color: var(--lsr-orange);
  border-color: #E8C4B8;
}

.btn-outline-primary:hover,
.btn-outline-primary:active {
  background-color: var(--lsr-orange) !important;
  border-color: var(--lsr-orange) !important;
  color: #fff !important;
}

.btn-secondary {
  background-color: var(--lsr-navy);
  border-color: var(--lsr-navy);
  color: #fff;
}

.btn-secondary:hover,
.btn-secondary:active {
  background-color: var(--lsr-navy-700) !important;
  border-color: var(--lsr-navy-700) !important;
}

.btn-outline-secondary {
  color: var(--lsr-navy);
  border-color: #CDD3DB;
  background-color: var(--lsr-surface);
}

.btn-outline-secondary:hover,
.btn-outline-secondary:active {
  background-color: var(--lsr-navy) !important;
  border-color: var(--lsr-navy) !important;
  color: #fff !important;
}

.btn-outline-success {
  color: #1D9E75;
  border-color: #A9DCC9;
  background-color: var(--lsr-surface);
}

.btn-outline-success:hover,
.btn-outline-success:active {
  background-color: #1D9E75 !important;
  border-color: #1D9E75 !important;
  color: #fff !important;
}

.btn-outline-danger {
  color: var(--lsr-orange);
  border-color: #EFC3B8;
  background-color: transparent;
}

.btn-outline-danger:hover,
.btn-outline-danger:active {
  background-color: var(--lsr-orange) !important;
  border-color: var(--lsr-orange) !important;
  color: #fff !important;
}

.btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(214, 56, 18, 0.22);
  outline: none;
}

/* ===== Badges ========================================================= */

.badge {
  font-weight: 500;
  font-size: 0.75rem;
  padding: 0.35em 0.65em;
  border-radius: 6px;
  letter-spacing: 0.01em;
}

.badge.bg-primary   { background-color: var(--lsr-orange) !important; }
.badge.bg-secondary { background-color: #E9ECF1 !important; color: var(--lsr-navy) !important; }
.badge.bg-success   { background-color: #E1F5EE !important; color: #0F6E56 !important; }
.badge.bg-warning   { background-color: #FAEEDA !important; color: #854F0B !important; }
.badge.bg-danger    { background-color: #FBE7E1 !important; color: #9E2B0C !important; }
.badge.bg-info      { background-color: #E6F1FB !important; color: #185FA5 !important; }
.badge.bg-light     { background-color: #F1F3F6 !important; color: var(--lsr-ink-muted) !important; }

/* ===== Tables ========================================================= */

.table {
  --bs-table-bg: transparent;
  font-size: 0.875rem;
  margin-bottom: 0;
  color: var(--lsr-ink);
}

.table > thead > tr > th {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--lsr-ink-muted);
  border-bottom: 1px solid var(--lsr-line);
  padding: 0.7rem 0.75rem;
  background: transparent;
  white-space: nowrap;
}

.table > tbody > tr > td {
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--lsr-line-soft);
  vertical-align: middle;
}

.table > tbody > tr:last-child > td { border-bottom: none; }

.table-hover > tbody > tr:hover > * {
  background-color: #FAFBFC;
  --bs-table-accent-bg: #FAFBFC;
}

/* ===== Progress ======================================================= */

.progress {
  border-radius: 6px;
  height: 8px;
  background-color: var(--lsr-line-soft);
}

.progress-bar { background-color: var(--lsr-coral); }
.progress-bar.bg-success { background-color: #1D9E75 !important; }
.progress-bar.bg-warning { background-color: #EF9F27 !important; }
.progress-bar.bg-danger  { background-color: var(--lsr-orange) !important; }

/* ===== Alerts ========================================================= */

.alert {
  border-radius: var(--lsr-radius);
  border: 1px solid transparent;
  border-left-width: 3px;
  font-size: 0.875rem;
  padding: 0.8rem 1rem;
}

.alert-success   { background-color: #E9F7F1; border-color: #1D9E75; color: #0F6E56; }
.alert-danger    { background-color: #FDF0EC; border-color: var(--lsr-orange); color: #9E2B0C; }
.alert-warning   { background-color: #FDF6E9; border-color: #EF9F27; color: #854F0B; }
.alert-info      { background-color: #EDF4FC; border-color: #378ADD; color: #185FA5; }
.alert-secondary { background-color: #F1F3F6; border-color: #B4BAC4; color: var(--lsr-navy); }

/* ===== Forms ========================================================== */

.form-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--lsr-navy);
  margin-bottom: 0.3rem;
}

.form-control,
.form-select {
  border-radius: var(--lsr-radius-sm);
  border-color: #D5DAE1;
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  color: var(--lsr-ink);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--lsr-coral);
  box-shadow: 0 0 0 3px rgba(254, 103, 68, 0.16);
}

.form-control::placeholder { color: #A8AEB8; }
.form-text { font-size: 0.8125rem; color: var(--lsr-ink-muted); }

/* ===== Dropdowns ====================================================== */

.dropdown-menu {
  border-radius: var(--lsr-radius);
  border: 1px solid var(--lsr-line);
  box-shadow: 0 6px 20px rgba(30, 48, 68, 0.09);
  font-size: 0.875rem;
  padding: 0.3rem;
}

.dropdown-item { border-radius: var(--lsr-radius-sm); padding: 0.45rem 0.7rem; }
.dropdown-item:hover { background-color: var(--lsr-coral-soft); color: var(--lsr-orange); }
.dropdown-item.active { background-color: var(--lsr-orange); color: #fff; }

/* ===== Auth screens =================================================== */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--lsr-navy);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--lsr-surface);
  border-radius: 14px;
  padding: 2.25rem 2rem;
  box-shadow: 0 18px 48px rgba(12, 22, 34, 0.28);
}

.auth-logo {
  display: block;
  width: 190px;
  max-width: 100%;
  margin: 0 auto 1.5rem;
}

.auth-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--lsr-navy);
  text-align: center;
  margin-bottom: 0.25rem;
}

.auth-subtitle {
  font-size: 0.85rem;
  color: var(--lsr-ink-muted);
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-footer {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--lsr-ink-muted);
}

/* ===== Mobile ========================================================= */

.mobile-container {
  max-width: 520px;
  margin: 0 auto;
  padding: 1rem;
}

/* Unfinished-setup marker on the Setup tab. */
.tab-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--lsr-orange);
  vertical-align: 0.35em;
  margin-left: 0.3rem;
}

/* ===== Readiness strip ================================================ */

.readiness {
  background: var(--lsr-surface);
  border: 1px solid var(--lsr-line);
  border-radius: 12px;
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.readiness-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--lsr-line);
  background: #FBFCFD;
}

.readiness-title {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--lsr-ink-muted);
}

.readiness-sub {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--lsr-navy);
  margin-top: 0.1rem;
}

.readiness-steps {
  list-style: none;
  margin: 0;
  padding: 0;
}

.readiness-step {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.8rem 1.25rem;
  border-bottom: 1px solid var(--lsr-line-soft);
}

.readiness-step:last-child { border-bottom: none; }

.readiness-marker {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  background: #EDEFF2;
  color: var(--lsr-ink-muted);
}

.readiness-step.is-done .readiness-marker {
  background: #E1F5EE;
  color: #0F6E56;
}

.readiness-step.is-ready .readiness-marker {
  background: var(--lsr-orange);
  color: #fff;
}

.readiness-body { flex: 1; min-width: 0; }

.readiness-step-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--lsr-navy);
}

.readiness-detail {
  font-size: 0.8125rem;
  color: var(--lsr-ink-muted);
  margin-top: 0.1rem;
}

/* Not-ready steps are dimmed but never hidden or unclickable — the manager
   should be able to see what a step will need before they can do it. */
.readiness-step.is-blocked .readiness-step-title,
.readiness-step.is-locked .readiness-step-title {
  color: var(--lsr-ink-muted);
}

.readiness-step.is-blocked .readiness-detail { color: #9E6B4A; }

.readiness-action { flex-shrink: 0; }
.readiness-action form { margin: 0; }

@media (max-width: 768px) {
  .readiness-step { flex-wrap: wrap; }
  .readiness-action { width: 100%; padding-left: 2.375rem; }
}

/* ===== Small helpers ================================================== */

.section-heading {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--lsr-ink-muted);
  margin-bottom: 0.6rem;
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--lsr-ink-muted);
  font-size: 0.9rem;
}

.stat-divider { border-color: var(--lsr-line); opacity: 1; }

/* ===== Responsive ===================================================== */

@media (max-width: 768px) {

  .app-layout { flex-direction: column; }

  .sidebar {
    width: 100%;
    border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  }

  .sidebar .nav { flex-direction: row !important; flex-wrap: wrap; padding-bottom: 0.5rem; }
  .sidebar-section { padding: 0.6rem 1rem 0.2rem; width: 100%; }

  .main-content { border-left: none; }

  .content-wrapper { padding: 1.25rem 1rem 2.5rem; }

  .top-bar { padding: 0 1rem; }

  .metric-value { font-size: 1.5rem; }
}

/* ---------------------------------------------------------------------------
   Interview frame height
   ---------------------------------------------------------------------------
   Enketo scrolls internally, so a short frame produces two nested scrollbars
   and a question list the interviewer has to hunt through an item at a time.
   Taller on a phone, where the frame is the whole screen, than on a desktop
   where the respondent panel sits alongside it.

   dvh rather than vh: on mobile Safari and Chrome the address bar collapses on
   scroll, and 100vh refers to the LARGER viewport — so a vh-sized frame is cut
   off by the browser chrome until the user scrolls. dvh tracks the actual
   visible height. The vh line before it is the fallback for older WebViews.
*/
.instrument-frame {
  height: 70vh;
}

@media (max-width: 991.98px) {
  .instrument-frame {
    height: 78vh;
    height: 78dvh;
  }
}

@media (min-width: 992px) {
  .instrument-frame {
    height: 78vh;
  }
}
