* {
  box-sizing: border-box;
}

:root {
  --app-workbench-gap: 14px;
  --app-side-panel-width: 252px;
  --app-panel-radius: 16px;
  --app-page-head-padding: 22px 26px 16px;
  --app-page-body-padding: 18px 26px 26px;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background: var(--bg-main);
  font-family: var(--sans);
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(rgba(84, 102, 93, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(84, 102, 93, 0.07) 1px, transparent 1px);
  background-size: 30px 30px;
  pointer-events: none;
  z-index: 0;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(110px);
  opacity: 0.22;
  pointer-events: none;
  z-index: 0;
}

.bg-orb-a {
  width: 420px;
  height: 420px;
  right: -60px;
  top: -100px;
  background: rgba(191, 94, 37, 0.7);
}

.bg-orb-b {
  width: 380px;
  height: 380px;
  left: -100px;
  bottom: -120px;
  background: rgba(20, 115, 82, 0.65);
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1720px, 97vw);
  margin: 24px auto 30px;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 18px;
}

:root.has-session .app-shell.view-hidden {
  display: grid;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 68px;
  padding: 8px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow), 0 1px 0 color-mix(in srgb, var(--accent) 12%, transparent) inset;
  backdrop-filter: blur(6px);
  border-radius: 14px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-home-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: inherit;
  text-align: left;
}

.brand-home-btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 36%, white);
  outline-offset: 3px;
  border-radius: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--stroke-soft);
  background: rgba(255, 255, 255, 0.75);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.brand-home-btn:hover .brand-icon {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px color-mix(in srgb, var(--accent) 16%, transparent);
}

.brand-home-btn:hover .brand-title {
  color: var(--accent);
}

.brand-copy {
  display: grid;
  gap: 2px;
  line-height: 1.1;
}

.brand-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.18rem;
}

.brand-subtitle {
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.icon-sm {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}

.icon-xs {
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--stroke-soft);
}

.page-head-stack {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.page-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.page-eyebrow {
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.page-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.05;
}

.page-sub {
  max-width: 56ch;
  color: var(--ink-soft);
  line-height: 1.45;
  margin: 0;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-left: 12px;
  margin-left: 4px;
  border-left: 1px solid var(--stroke-soft);
}

.topnav-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--ink-soft);
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.topnav-link:hover {
  background: var(--row-hover);
  color: var(--ink);
}

.topnav-link.active {
  background: var(--accent-soft);
  color: var(--ink);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 320px;
  min-height: 34px;
  padding: 6px 10px 6px 32px;
  border: 1px solid var(--stroke-soft);
  border-radius: 10px;
  background: var(--paper);
}

.topbar-search .icon-sm {
  position: absolute;
  left: 10px;
  color: var(--ink-soft);
  flex: 0 0 auto;
}

.topbar-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
  font: inherit;
  font-size: 0.86rem;
}

.topbar-search input:focus {
  outline: none;
}

.profile-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 240px;
  min-height: 36px;
  padding: 5px 12px 5px 5px;
  border: 1px solid var(--stroke-soft);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  font: inherit;
  cursor: pointer;
}

.profile-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-size: 0.68rem;
  font-weight: 700;
  flex: 0 0 auto;
}

.profile-label {
  display: inline-block;
  max-width: 48vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.profile-chip .profile-label {
  max-width: 170px;
}

@media (max-width: 1120px) {
  .topbar-search {
    display: none;
  }
}

@media (max-width: 760px) {
  .topnav {
    display: none;
  }
}

.sidebar,
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
  border-radius: 16px;
}

.sidebar {
  position: sticky;
  top: 18px;
  height: fit-content;
  padding: 14px;
}

.eyebrow {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.65rem;
  line-height: 1.05;
}

.subhead {
  margin: 10px 0 14px;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-link {
  text-align: left;
  border: 1px solid var(--stroke);
  background: rgba(247, 248, 246, 0.9);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--sans);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.nav-link:visited {
  color: var(--ink);
  text-decoration: none;
}

.nav-link:hover,
.nav-link:focus-visible {
  text-decoration: none;
}

.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 20%, transparent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-link-settings {
  margin-top: 0;
}

.nav-divider {
  margin: 8px 4px 2px;
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--accent) 55%, transparent),
    color-mix(in srgb, var(--stroke) 85%, transparent)
  );
  opacity: 0.95;
}

.content-pane {
  display: grid;
  gap: 14px;
}

.app-shell.app-shell-settings {
  width: min(1980px, 98vw);
  min-height: calc(100vh - 24px);
  margin: 8px auto 18px;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--app-workbench-gap);
}

.app-shell.app-shell-settings > .sidebar {
  display: none;
}

.view-hidden {
  display: none;
}

.panel {
  padding: 18px;
}

.panel h2 {
  margin: 0 0 16px;
  font-size: 1.25rem;
  font-family: var(--serif);
  letter-spacing: 0.01em;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--stroke-soft);
}

.stack {
  display: grid;
  gap: 8px;
}

.inline-form {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}

.label {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}

input[type="text"],
input[type="file"],
input[type="date"],
input[type="number"],
input[type="password"],
textarea {
  width: 100%;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  padding: 10px 11px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  font-family: var(--sans);
}

input[type="date"] {
  min-height: 42px;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%234e5d58' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: calc(100% - 10px) 50%;
  background-size: 18px 18px;
}

input[type="text"]:focus-visible,
input[type="file"]:focus-visible,
input[type="date"]:focus-visible,
input[type="number"]:focus-visible,
input[type="password"]:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(29, 106, 85, 0.35);
  outline-offset: 1px;
  border-color: #5a8378;
}

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

input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0;
  width: 20px;
  height: 20px;
  margin-right: 2px;
  background: transparent;
}

.btn {
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: rgba(247, 248, 246, 0.95);
  color: var(--ink);
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(46, 57, 52, 0.12);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 72%, black));
  color: #f5fff9;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 3px 12px color-mix(in srgb, var(--accent) 28%, transparent);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 5px 20px color-mix(in srgb, var(--accent) 40%, transparent);
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--link);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-align: left;
  text-decoration: underline;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.btn-muted {
  background: #e8ebea;
  color: #5a6467;
  border-color: #8f989d;
}

.btn-muted:hover:not(:disabled) {
  box-shadow: 0 8px 16px rgba(70, 78, 83, 0.14);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--ink-soft);
  box-shadow: none;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--row-hover);
  color: var(--ink);
  box-shadow: none;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.78rem;
}

.btn-icon-xs {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink-soft);
}

.btn-icon-xs:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.06);
  color: var(--ink);
  box-shadow: none;
}

.btn-danger-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--danger);
  box-shadow: none;
}

.btn-danger-ghost:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  color: var(--danger);
  box-shadow: none;
}

@media (max-width: 980px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .profile-label {
    max-width: 72vw;
  }

  .app-shell {
    grid-template-columns: 1fr;
    width: min(100%, 98vw);
    margin: 14px auto 18px;
  }

  .sidebar {
    position: static;
  }

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

  .btn-muted {
    width: 100%;
  }

}

@media (max-width: 760px) {
  .panel {
    padding: 14px;
  }

}

@media (min-width: 1400px) {
  .app-shell {
    grid-template-columns: 276px minmax(0, 1fr);
    gap: 20px;
  }

  .sidebar {
    padding: 16px;
  }

  .panel {
    padding: 20px;
  }

}

@media (min-width: 1800px) {
  .app-shell {
    width: min(1960px, 98vw);
    grid-template-columns: 292px minmax(0, 1fr);
  }

  .sidebar {
    padding: 18px;
  }

}

/* ─── Nav icons ─────────────────────────────────────────── */
.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.55;
  transition: opacity 140ms ease;
}

.nav-link:hover .nav-icon,
.nav-link.active .nav-icon {
  opacity: 1;
}

/* ─── Scrollbars ────────────────────────────────────────── */
.docs-table-wrap::-webkit-scrollbar,
.document-ocr-preview::-webkit-scrollbar,
.output::-webkit-scrollbar,
.filter-dropdown-options::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.docs-table-wrap::-webkit-scrollbar-track,
.document-ocr-preview::-webkit-scrollbar-track,
.output::-webkit-scrollbar-track,
.filter-dropdown-options::-webkit-scrollbar-track {
  background: transparent;
}

.docs-table-wrap::-webkit-scrollbar-thumb,
.document-ocr-preview::-webkit-scrollbar-thumb,
.output::-webkit-scrollbar-thumb,
.filter-dropdown-options::-webkit-scrollbar-thumb {
  background: var(--stroke);
  border-radius: 999px;
}

.docs-table-wrap::-webkit-scrollbar-thumb:hover,
.document-ocr-preview::-webkit-scrollbar-thumb:hover,
.output::-webkit-scrollbar-thumb:hover,
.filter-dropdown-options::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--accent) 38%, var(--stroke));
}

/* ─── Sidebar section label ─────────────────────────────── */
.nav-section-label {
  padding: 2px 4px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  opacity: 0.7;
}
