:root {
  --text: #1f1d1b;
  --muted: #6b645e;
  --surface: #fff;
  --border: #e9e4de;
  --space-1: 8px;
  --space-2: 12px;
  --space-3: 16px;
  --space-4: 20px;
  --space-5: 24px;
}

body {
  font-family: "Inter", "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  margin: 0;
  background: #f8f7f5;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container {
  max-width: 1120px;
  margin: 24px auto;
  padding: 0 24px 44px;
}

.rbj-shell {
  --rbj-bg: #f4f6fb;
  --rbj-ink: #152033;
}

.topbar {
  display: flex;
  gap: 22px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.rbj-topbar {
  background: #fff;
  border: 1px solid #e2e8f5;
  border-radius: 14px;
  padding: 14px;
}

.topbar-main {
  flex: 1;
  min-width: 0;
}

.topbar-headline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hero-card {
  background: #fff;
  border: 1px solid #e2e8f5;
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 6px 24px rgba(16, 26, 45, 0.06);
}

.top-utility {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.auth-actions.compact .rbj-btn {
  padding: 8px 10px;
  font-size: 12px;
}

.rbj-btn {
  border: 1px solid #ccd8f0;
  background: #f6f9ff;
  color: #1b315d;
}

.app-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 12px;
}

.app-tab {
  text-decoration: none;
  border: 1px solid #dde6f8;
  background: #f8fbff;
  color: #2a3f63;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.app-tab.active {
  background: #1f4b99;
  border-color: #1f4b99;
  color: #fff;
}

.service-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.service-card {
  border: 1px solid #e2e8f5;
  border-radius: 12px;
  padding: 14px;
  background: #fbfdff;
}

.service-card h3 {
  margin: 0 0 8px;
  font-size: 17px;
}

.service-card p {
  margin: 0;
  color: #455266;
  line-height: 1.5;
}

.logo-wrap {
  width: 340px;
  min-height: auto;
  background: transparent;
  border: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0;
  flex: 0 0 340px;
}

.hero-logo-only {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 150px;
}

.centered-logo {
  justify-content: center;
  flex: 0 0 auto;
  width: 420px;
  max-width: 100%;
}

.logo {
  width: 100%;
  max-width: 340px;
  height: auto;
  display: block;
}

.hero-copy {
  min-width: 0;
  padding-top: 4px;
}

h1 {
  margin: 0 0 14px;
  font-size: clamp(32px, 5vw, 44px);
  line-height: 1.08;
  letter-spacing: -0.02em;
  font-weight: 700;
}

h2 {
  font-size: clamp(24px, 3.2vw, 30px);
  line-height: 1.2;
  margin: 0 0 10px;
}

h3 {
  font-size: 20px;
  line-height: 1.25;
  margin: 0 0 10px;
}

.sub {
  margin: 0 0 10px;
  color: #3f3a35;
  font-size: 18px;
  line-height: 1.45;
  max-width: 820px;
}

.small {
  color: #6b645e;
  margin: 0 0 12px;
}

.badge {
  display: inline-block;
  padding: 7px 12px;
  border-radius: 999px;
  background: #e7f0ff;
  color: #0058e6;
  border: 1px solid #c9dcff;
  font-weight: 700;
}

.intro-line {
  margin: 18px 2px 10px;
}

.intro-line p {
  margin: 0;
  font-size: 16px;
  color: #4a433d;
}

.instructions-panel {
  margin-top: 10px;
}

.instructions-panel h3 {
  margin-top: 0;
}

.instructions-panel ol {
  margin: 8px 0 0 20px;
  color: #3f3a35;
  line-height: 1.65;
}

.role-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 26px 0 12px;
}

.role,
.info,
button {
  border: 1px solid #ddd6d0;
  background: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
}

.role.active {
  background: #0058e6;
  color: #fff;
  border-color: #0058e6;
}

.drop-zone {
  border: 1.5px dashed #c9d8ee;
  border-radius: 14px;
  padding: 24px;
  background: #fff;
  box-shadow: 0 3px 16px rgba(16, 13, 10, 0.04);
}

.drop-zone h2 {
  margin-top: 0;
  font-size: 24px;
  line-height: 1.2;
}

.drop-zone.drag {
  border-color: #0058e6;
  background: #f3f8ff;
}

.footer-note {
  margin-top: 12px;
  color: #3f3a35;
  font-weight: 600;
}

.explainer {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 18px 0;
}

.explainer > div,
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

.explainer-icon {
  font-size: 24px;
  margin-bottom: 8px;
}

.panel {
  margin: 14px 0;
}

.panel p,
.panel li,
.panel td,
.panel th,
.panel label,
.panel input,
.panel textarea,
.panel select,
.panel button {
  font-size: 14px;
}

.role-helper {
  color: #6b645e;
  margin: 2px 2px 14px;
}

.missing {
  color: #c1132f;
  font-weight: 700;
}

.ocr-warning {
  margin: 8px 0 12px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #f3c97a;
  background: #fff7e8;
  color: #7a4f00;
  font-size: 13px;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #faf8f6;
  border: 1px solid #efe9e3;
  border-radius: 10px;
  padding: 10px;
}

code {
  background: #f3f0ed;
  padding: 2px 6px;
  border-radius: 6px;
}

dialog {
  border: 1px solid #ddd5ce;
  border-radius: 12px;
  max-width: 560px;
}

input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #dcd4cd;
  margin-top: 10px;
  width: 100%;
  max-width: 390px;
  min-height: 40px;
  box-sizing: border-box;
  font-size: 14px;
}

label {
  display: block;
  margin-top: 10px;
  margin-bottom: 4px;
  font-weight: 600;
}

#draft-to,
#draft-cc,
#draft-subject {
  max-width: none;
  width: 100%;
  box-sizing: border-box;
}

#draft-body {
  display: block;
  width: 100%;
  min-height: 420px;
  box-sizing: border-box;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #dcd4cd;
  font-family: "Inter", "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  resize: vertical;
}

select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #dcd4cd;
  background: #fff;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.cost-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.cost-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}

.cost-table th,
.cost-table td {
  border-bottom: 1px solid #ece7e1;
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

.cost-table th {
  color: #5d554f;
  font-weight: 700;
  background: #faf8f6;
}

.progress {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.progress .step {
  flex: 1 1 160px;
  font-size: 12px;
  text-align: center;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid #ddd6d0;
  background: #fff;
  color: #5f5751;
}

.progress .step.active {
  background: #0058e6;
  border-color: #0058e6;
  color: #fff;
}

.progress .step.done {
  background: #e8f6ee;
  border-color: #9fd3b1;
  color: #1f6a3a;
}

.grid-two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
}

.case-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 14px;
}

.comm-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 12px;
}

.task-list, #comm-tasks {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.comm-task {
  border: 1px solid #ece7e1;
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  background: #fff;
}

.comm-task.active {
  border-color: #0058e6;
  background: #f3f8ff;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.sticky-next { position: static; }

.task-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.task-tab {
  border: 1px solid #ddd6d0;
  background: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.task-tab.active {
  border-color: #0058e6;
  background: #f3f8ff;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot-gray { background: #9ca3af; }
.dot-blue { background: #2563eb; }
.dot-green { background: #16a34a; }

.link-btn {
  border: 0;
  background: transparent;
  color: #0058e6;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

#next-steps-list {
  margin: 8px 0 0;
  padding-left: 22px;
}

#next-steps-list li {
  margin: 10px 0;
  line-height: 1.4;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.kpi {
  border: 1px solid #ece7e1;
  border-radius: 10px;
  padding: 10px;
  background: #fcfbfa;
}

.kpi-label {
  font-size: 12px;
  color: #6b645e;
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.brief {
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  background: #f3f8ff;
  border: 1px solid #dbe7ff;
}

.stage-tracker {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stage-row {
  border: 1px solid #ece7e1;
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
}

.stage-row summary {
  display: grid;
  grid-template-columns: 18px minmax(160px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  cursor: pointer;
  list-style: none;
}

.stage-mark { font-weight: 700; }
.stage-title { font-weight: 600; }
.stage-status { font-size: 12px; color: #5d554f; }
.stage-owner { font-size: 12px; color: #6b645e; }

.stage-row.complete { border-color: #9fd3b1; background: #f2fbf6; }
.stage-row.complete .stage-mark { color: #16a34a; animation: pop .35s ease; }
.stage-row.waiting .stage-mark { color: #2563eb; }
.stage-row.not-started .stage-mark { color: #9ca3af; }

.check-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.check-item {
  border: 1px solid #ece7e1;
  border-radius: 10px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: start;
  background: #fff;
  font-size: 13px;
}

.check-item.done {
  border-color: #9fd3b1;
  background: #f2fbf6;
}

.ok { color: #1f6a3a; font-weight: 700; }

@keyframes pop {
  0% { transform: scale(0.6); opacity: .4; }
  100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 840px) {
  .container {
    padding: 0 14px calc(34px + env(safe-area-inset-bottom, 0px));
    margin: 16px auto;
  }
  .topbar { flex-direction: column; gap: 10px; margin-bottom: 12px; }
  .top-utility,
  .topbar-headline { flex-direction: column; align-items: flex-start; }
  .auth-actions { width: 100%; }
  .auth-actions .rbj-btn { flex: 1 1 auto; }
  .app-tabs { gap: 6px; }
  .app-tab { font-size: 11px; padding: 6px 9px; }
  .logo-wrap { width: 100%; max-width: 220px; }
  .centered-logo { width: 260px; }
  h1 { font-size: 30px; line-height: 1.1; margin-bottom: 8px; }
  h2 { font-size: 22px; }
  h3 { font-size: 17px; }

  .panel,
  .explainer > div,
  .drop-zone,
  .hero-card {
    padding: 16px;
    border-radius: 12px;
  }

  .role-toggle { gap: 8px; margin: 18px 0 10px; }
  button,
  .role,
  .info,
  .task-tab {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 14px;
  }

  .btn-row {
    gap: 10px;
    margin-top: 10px;
  }

  input,
  select,
  #draft-to,
  #draft-cc,
  #draft-subject,
  #case-id {
    min-height: 44px;
    font-size: 16px;
  }

  #draft-body {
    min-height: 360px;
    font-size: 16px;
    line-height: 1.5;
  }

  .explainer { grid-template-columns: 1fr; gap: 10px; }
  .grid-two { grid-template-columns: 1fr; gap: 10px; }
  .service-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr; }
  .case-grid, .comm-grid { grid-template-columns: 1fr; }
  .check-grid { grid-template-columns: 1fr; gap: 10px; }

  .filter-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin: 8px 0 12px;
  }
  .filter-row select,
  #files-filter,
  #files-search {
    width: 100%;
    max-width: none;
  }

  .stage-row summary {
    grid-template-columns: 18px 1fr;
    row-gap: 6px;
    padding: 2px 0;
  }
  .stage-status, .stage-owner {
    grid-column: 2;
    font-size: 12px;
  }

  .cost-table { min-width: 620px; }
  .cost-table th,
  .cost-table td { padding: 8px 8px; }

  .sticky-next { position: static; }
}
