.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 1.5rem 2rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  background: linear-gradient(110deg, var(--gradient-header-start), var(--gradient-header-end));
  border-bottom: 1px solid var(--color-border);
}

.brand {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: radial-gradient(circle at 30% 30%, var(--color-heading), var(--color-primary));
  box-shadow: var(--shadow-soft);
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  color: var(--color-text-muted);
}

.app-header h1 {
  margin: 0;
  font-size: 1.6rem;
  color: var(--color-heading);
}

.header-controls {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.auth-panel {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-base);
  background: var(--color-surface);
  box-shadow: var(--shadow-soft);
  min-width: 220px;
}

.auth-info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.auth-mode {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-primary);
  text-transform: uppercase;
}

.auth-user {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.auth-actions {
  display: flex;
  gap: 0.5rem;
}

.auth-actions button {
  border: none;
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--color-primary);
  color: var(--color-on-primary);
  transition: opacity var(--transition-base);
}

.auth-actions button[hidden] {
  display: none;
}

.theme-switch {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  font-weight: 600;
}

.theme-switch input {
  cursor: pointer;
}

.config-panel {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  background: var(--color-surface);
  border-radius: var(--radius-base);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow-soft);
}

.config-panel label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  display: flex;
  flex-direction: column;
}

.config-panel input {
  border-radius: 10px;
  border: 1px solid var(--color-border);
  padding: 0.35rem 0.75rem;
  min-width: 240px;
  font-size: 0.95rem;
}

.config-panel button {
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.5rem 1.5rem;
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.config-panel button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

.app-body {
  flex: 1;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 2rem;
  padding: 2rem;
}

.sidebar {
  background: var(--color-surface);
  border-radius: var(--radius-base);
  padding: 1rem;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  height: fit-content;
}

.nav-btn {
  border: none;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  text-align: left;
  font-size: 0.95rem;
  font-weight: 600;
  background: transparent;
  cursor: pointer;
  color: var(--color-text);
  transition: background var(--transition-base), color var(--transition-base);
}

.nav-btn.is-active,
.nav-btn:hover {
  background: var(--tone-primary-soft);
  color: var(--color-primary);
}

#app-view {
  min-height: 65vh;
}

.page {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.markdown h2,
.markdown h3,
.markdown p,
.markdown ul {
  margin: 0 0 0.75rem;
}

.markdown ul {
  padding-left: 1.25rem;
}

.panel {
  background: var(--color-surface);
  border-radius: var(--radius-base);
  box-shadow: var(--shadow-elevated);
  padding: 1.5rem;
}

.report-detail {
  margin-top: 1.5rem;
  padding: 1rem;
  border-radius: var(--radius-base);
  border: 1px solid var(--color-border);
  background: var(--color-surface-muted);
}

.panel h2,
.panel h3 {
  margin-top: 0;
  color: var(--color-heading);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-start;
}

.editor-toolbar {
  display: inline-flex;
  gap: 0.35rem;
  padding: 0.4rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  background: var(--color-surface-muted);
  box-shadow: var(--shadow-soft);
}

.editor-toolbar button {
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.35rem 0.85rem;
  font-weight: 600;
  font-size: 0.85rem;
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
  transition: background var(--transition-base), color var(--transition-base);
}

.editor-toolbar button:hover:not(:disabled),
.editor-toolbar button.is-active {
  background: var(--tone-primary-soft);
  color: var(--color-primary);
}

.editor-toolbar button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.editor-toolbar button[data-command="bold"] {
  font-weight: 700;
}

.editor-toolbar button[data-command="italic"] {
  font-style: italic;
}

.toolbar-separator {
  width: 1px;
  background: var(--color-border);
  align-self: stretch;
}

.generated-report-id-panel {
  background: linear-gradient(110deg, rgba(16, 185, 129, 0.08), var(--color-surface));
  border: 2px solid rgb(16, 185, 129);
}

.generated-report-id-panel .panel-head {
  color: rgb(16, 185, 129);
}

.generated-report-id-panel h3 {
  margin-bottom: 0.5rem;
}

.report-id-display {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.report-id-display label {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-weight: 600;
}

.report-id-input {
  font-family: 'Courier New', monospace;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  background: var(--color-background);
  color: rgb(16, 185, 129);
  cursor: text;
}

.report-id-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.report-id-actions button {
  flex: 1;
  min-width: 180px;
}

.input-hint {
  margin: 0.5rem 0 0 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  font-weight: 400;
}

.editor-wrapper {
  margin-top: 1rem;
  padding: 1.5rem;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-base);
  background: linear-gradient(135deg, rgba(8, 82, 128, 0.02), rgba(243, 111, 33, 0.04));
  overflow: auto;
}

.editor-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
}

.report-page {
  margin: 0 auto;
  width: min(100%, 820px);
  min-height: 1120px;
  background: var(--color-surface);
  border-radius: 24px;
  padding: 2.5rem;
  box-shadow: 0 35px 80px rgba(8, 82, 128, 0.18);
  border: 1px solid rgba(8, 82, 128, 0.08);
  font-family: var(--font-family-base);
  line-height: 1.6;
}

.report-placeholder {
  min-height: 200px;
  display: grid;
  place-items: center;
  color: var(--color-text-muted);
  text-align: center;
}

.doc-header {
  text-align: center;
  margin-bottom: 2rem;
}

.doc-header h1 {
  margin: 0.2rem 0;
  font-size: 2rem;
  color: var(--color-heading);
}

.doc-eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.doc-meta {
  margin: 0.15rem 0;
  font-size: 0.95rem;
  color: var(--color-text-muted);
}

.doc-section {
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px dashed var(--color-border);
}

.doc-section:last-child {
  border-bottom: none;
}

.doc-section h2,
.doc-section h3 {
  margin-top: 0;
}

.doc-section[contenteditable="true"]:focus-within {
  outline: 2px solid rgba(8, 82, 128, 0.35);
  outline-offset: 6px;
}

.doc-richtext p {
  margin: 0.2rem 0 0.8rem;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.doc-table th,
.doc-table td {
  border: 1px solid var(--color-border);
  padding: 0.45rem 0.4rem;
}

.doc-table th {
  background: var(--color-surface-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
}

.doc-footer {
  text-align: right;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

input[type="text"],
input[type="date"],
input[type="url"],
select,
textarea {
  border-radius: 12px;
  border: 1px solid var(--color-border);
  padding: 0.6rem 0.9rem;
  font-size: 1rem;
  font-family: var(--font-family-base);
  background: var(--color-surface-muted);
  color: var(--color-text);
}

textarea {
  min-height: 160px;
  resize: vertical;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

button.cta {
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.85rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}

button.primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

button.secondary {
  background: var(--tone-primary-soft);
  color: var(--color-primary);
}

button.ghost {
  background: transparent;
  border: 1px dashed var(--color-border);
  color: var(--color-text-muted);
}

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

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.stat-card {
  border-radius: 16px;
  padding: 1rem;
  background: var(--color-surface-muted);
  border: 1px solid var(--color-border);
}

.big {
  font-size: 1.2rem;
  font-weight: 600;
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th,
td {
  border-bottom: 1px solid var(--color-border);
  padding: 0.65rem 0.5rem;
  text-align: left;
}

th {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--color-text-muted);
}

iframe.report-frame {
  width: 100%;
  min-height: 420px;
  border: 1px solid var(--color-border);
  border-radius: 18px;
  background: var(--color-surface);
}

.meta {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.empty-state {
  background: var(--color-surface);
  border-radius: var(--radius-base);
  padding: 4rem 2rem;
  text-align: center;
  box-shadow: var(--shadow-elevated);
}

.loader {
  position: fixed;
  inset: 0;
  background: var(--overlay-backdrop);
  display: grid;
  place-items: center;
  z-index: 1000;
}

.loader[hidden] {
  display: none;
}

.loader-box {
  background: var(--color-surface);
  padding: 1.25rem 1.75rem;
  border-radius: 20px;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  box-shadow: var(--shadow-elevated);
}

.loader-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-accent);
  animation: pulse 0.85s infinite ease-in-out;
}

@keyframes pulse {
  0% {
    transform: scale(0.8);
    opacity: 0.6;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(0.8);
    opacity: 0.6;
  }
}

.toast-container {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 1100;
}

.toast {
  min-width: 260px;
  border-radius: 14px;
  padding: 0.85rem 1rem;
  color: var(--color-on-primary);
  font-weight: 600;
  box-shadow: var(--shadow-elevated);
  animation: slide-in 200ms ease;
}

.toast.fade-out {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.success {
  background: var(--color-success);
}

.toast.error {
  background: var(--color-error);
}

.toast.info {
  background: var(--color-primary);
}

@keyframes slide-in {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.debug-log {
  font-family: "Consolas", "SFMono-Regular", Menlo, monospace;
  background: var(--color-code-bg);
  color: var(--color-code-text);
  border-radius: 16px;
  padding: 1rem;
  min-height: 200px;
  overflow: auto;
}

.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  padding: 0.2rem 0.7rem;
  font-size: 0.75rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface-muted);
}

.tag[data-state*="valid"] {
  border-color: var(--color-success);
  background: var(--tag-valid-bg);
  color: var(--color-success);
}

.tag[data-state*="pending"] {
  border-color: var(--color-warning);
  background: var(--tag-pending-bg);
  color: var(--color-warning);
}

.tag[data-state*="error"],
.tag[data-state*="reject"] {
  border-color: var(--color-error);
  background: var(--tag-error-bg);
  color: var(--color-error);
}

@media (max-width: 960px) {
  .app-body {
    grid-template-columns: 1fr;
  }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .nav-btn {
    flex: 1;
    text-align: center;
  }
  .config-panel {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 600px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-controls {
    width: 100%;
    justify-content: flex-start;
  }
}
