/* Tokens moved to styles/base/variables.css (imported explicitly in app.ts). */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* App shell: vertical nav sidebar + scrolling content column. */
.app-shell {
  display: flex;
  align-items: flex-start;
  min-height: 100vh;
}

.app-content {
  flex: 1;
  min-width: 0;
}

.nav {
  position: relative;
  top: 0;
  flex: 0 0 15rem;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100vh;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}

.nav-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.nav-links .nav-divider-after {
  padding-bottom: 0.4rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.nav-links .nav-section-label {
  padding: 0.4rem 0.6rem 0.2rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Pushed to the bottom of the sidebar. */
.nav-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

/* Narrow viewports: fall back to a horizontal bar that wraps. */
@media (width <= 48rem) {
  .app-shell {
    flex-direction: column;
    align-items: stretch;
  }

  .nav {
    position: static;
    flex: none;
    flex-flow: row wrap;
    align-items: center;
    height: auto;
    gap: 0.6rem;
    padding: 0.85rem 1.25rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .nav-links {
    flex-flow: row wrap;
    gap: 0.3rem;
  }

  .nav-links .nav-divider-after {
    padding: 0 0.3rem 0 0;
    margin: 0;
    border-bottom: none;
    border-right: 1px solid var(--border);
  }

  .nav-footer {
    margin-top: 0;
    margin-left: auto;
    flex-direction: row;
    align-items: center;
  }
}

.container {
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

h1 {
  font-size: 1.4rem;
  margin: 0 0 1rem;
}

.login-card {
  h1 {
    text-align: center;
  }

  .forgot-password {
    margin-top: 0;
  }
}

.card {
  max-width: 480px;
  margin: 3rem auto;
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);

  h1:first-child,
  h2:first-child,
  h3:first-child {
    margin-top: 0;
  }
}

.smaller-fontsize {
  font-size: 0.85rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input {
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  width: 100%;
}

input:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

form button {
  margin-top: 0.5rem;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

button.primary-ghost {
  background: none;
  color: black;
  border: 1px solid var(--accent);
  font-weight: normal;
}

.link {
  background: none;
  color: var(--accent);
  padding: 0.3rem 0.5rem;
  font-weight: 500;
}

.link.danger {
  color: var(--danger);
}

.row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.row.between {
  justify-content: space-between;
}

.create {
  margin: 1rem 0 1.5rem;
}

.create input {
  flex: 1;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.muted {
  color: var(--muted);
}

/* Status badges (workflow states, see docs/workflows.md). Muted palette:
   each state tints the surface via color-mix so both themes work. */
.badge {
  display: inline-block;
  padding: 0 0.55em;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge.status-draft {
  color: var(--muted);
}

.badge.status-submitted {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

.badge.status-approved {
  color: #3fb950;
  border-color: color-mix(in srgb, #3fb950 45%, var(--border));
  background: color-mix(in srgb, #3fb950 12%, var(--surface));
}

.badge.status-rejected {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
}

.badge.status-ordered {
  color: #b07cf7;
  border-color: color-mix(in srgb, #b07cf7 45%, var(--border));
  background: color-mix(in srgb, #b07cf7 12%, var(--surface));
}

.badge.status-received {
  color: #2fbf9f;
  border-color: color-mix(in srgb, #2fbf9f 45%, var(--border));
  background: color-mix(in srgb, #2fbf9f 12%, var(--surface));
}

.badge.status-closed {
  color: var(--muted);
  background: color-mix(in srgb, var(--muted) 12%, var(--surface));
}

.empty {
  padding: 1.5rem;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.error {
  margin: 0;
  padding: 0.6rem 0.75rem;
  background: rgb(255 92 108 / 12%);
  border: 1px solid var(--danger);
  border-radius: 8px;
  color: var(--danger);
  font-size: 0.9rem;
}

a {
  color: var(--accent);

  .muted & {
    color: var(--muted-accent);
  }
}

/* ---- import mapping ---- */
.import-mapping {
  width: 100%;
  border-collapse: collapse;
}

.import-mapping th,
.import-mapping td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid #e3e3e8;
}

.import-mapping thead {
  background-color: color-mix(in srgb, var(--accent) 16%, transparent);
}

/* ---- data table ---- */
.data-table-scroll {
  overflow-x: auto;
  margin-bottom: 1rem;
}

.data-table table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid #e3e3e8;
  white-space: nowrap;
}

.data-table-filters th {
  font-weight: 400;
}

.data-table thead th {
  font-weight: 600;
}

.import-mapping tbody th {
  font-weight: normal;
}

/* Compact table density (User setting `tableDensity`), applied to <html>.
   Sits below the plain `th`/`td` rules it overrides: it only touches padding,
   so the font-weight rules above are unaffected by the order. */
:root[data-density="compact"] .data-table th,
:root[data-density="compact"] .data-table td {
  padding: 0.15rem 0.4rem;
}

.data-table-sort {
  font: inherit;
  font-weight: 600;
  padding: 0;
}

.search-trigger,
select {
  width: 100%;
  padding: 0.5rem 0.65rem;
  font: inherit;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.data-table-filters input,
.data-table-filters select {
  width: 100%;
  min-width: 5rem;
  font-size: 0.85rem;
  padding: 0.2rem 0.35rem;
}

.data-table-range {
  display: flex;
  gap: 0.25rem;
}

.data-table-range input {
  min-width: 4rem;
}

.data-table tbody.is-loading {
  opacity: 0.5;
}

.data-table-toolbar {
  margin-bottom: 0.5rem;
}

.data-table-toolbar-filters {
  flex: 1 1 18rem;
}

.data-table-search {
  max-width: 18rem;
}

/* Shown only while filters or the search narrow the rows. */
.data-table-filter-summary {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1rem 0.2rem 0.1rem 0.6rem;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  font-size: 0.8rem;
  white-space: nowrap;
}

.data-table-menu {
  position: relative;
}

.data-table-menu summary {
  cursor: pointer;
}

.data-table-menu ul {
  position: absolute;
  right: 0;
  z-index: 10;
  margin: 0.25rem 0 0;
  padding: 0.5rem;
  list-style: none;
  background: #fff;
  border: 1px solid #e3e3e8;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgb(0 0 0 / 8%);
  min-width: 14rem;
}

.data-table-menu li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.15rem 0;
}

/* Checkbox before the column name, on one line: the global `label` is a
   column and `input` is full width, which stacked the box above the name. */
.data-table-menu label {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;

  input {
    width: auto;
    margin: 0;
  }
}

.data-table-move {
  display: flex;
  gap: 0.25rem;
}

.data-table-footer {
  margin-top: 0.5rem;
}

/* Toasts */
.toast-stack {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
  max-width: 24rem;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 10px rgb(0 0 0 / 35%);
}

.toast-success {
  border-color: #3fb950;
}

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

.toast-info {
  border-color: var(--accent);
}

.toast-dismiss {
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  margin-left: auto;
}

/* Email-verification banner (soft gate) */
.verify-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
}

.verify-banner button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.3rem 0.7rem;
  cursor: pointer;
}

.verify-banner-dismiss {
  margin-left: auto;
  border: none;
  background: none;
  font-size: 1.15rem;
  line-height: 1;
  padding: 0 0.25rem;
}

/* Notification bell */
.notification-bell {
  position: relative;
}

.notification-bell summary {
  cursor: pointer;
  list-style: none;
}

.notification-bell .badge {
  background: var(--danger);
  color: var(--bg);
  border-radius: 999px;
  font-size: 0.7rem;
  padding: 0 0.4em;
  vertical-align: top;
}

.notification-panel {
  position: absolute;
  right: 0;
  min-width: 20rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgb(0 0 0 / 35%);
  padding: 0.5rem;
  z-index: 50;
}

.notification-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 20rem;
  overflow-y: auto;
}

.notification-item {
  display: flex;
  flex-direction: column;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  color: var(--text);
  font-weight: 400;
  cursor: pointer;
  padding: 0.4rem 0.5rem;
}

.notification-item.unread {
  font-weight: 600;
}

/* Visually hidden but available to assistive tech (live regions, hidden inputs). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.file-upload .dropzone {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.file-upload .dropzone.dragging {
  border-color: var(--accent, #4a90d9);
  background: color-mix(in srgb, var(--accent, #4a90d9) 8%, var(--surface));
}

.file-upload .dropzone-hint {
  margin: 0;
}

.file-upload .hint {
  flex-basis: 100%;
  margin: 0.25rem 0 0;
  font-size: 0.85em;
}

.file-upload .upload-tasks {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.file-upload .upload-task {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.file-upload .upload-task .filename {
  font-weight: 600;
}

.file-upload .upload-task.error .error {
  color: var(--danger, #c0392b);
}

.file-upload .upload-task.success .success {
  color: var(--success, #2e7d32);
}

/* Global search (command palette, see components/command-palette.gts) */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.search-trigger kbd {
  padding: 0 0.3rem;
  margin-left: 0.25rem;
  font-size: 0.8em;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}

.command-palette-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 10vh;
  background: rgb(0 0 0 / 45%);
}

.command-palette {
  width: min(560px, 92vw);
  max-height: 70vh;
  overflow-y: auto;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 40px rgb(0 0 0 / 35%);
}

.command-palette-input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  font: inherit;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.palette-hint,
.palette-empty {
  margin: 0.6rem 0.25rem 0.1rem;
}

.palette-heading {
  margin-top: 0.6rem;
  padding: 0 0.35rem 0.2rem;
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.palette-option {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border-radius: calc(var(--radius) - 4px);
  cursor: pointer;
}

.palette-option.active {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
}

.palette-secondary {
  font-size: 0.9em;
}

/* Deep-link landing flash (utils/highlight.ts adds/removes the class) */

@keyframes highlight-flash {
  0% {
    background-color: color-mix(in srgb, var(--accent) 35%, transparent);
  }

  100% {
    background-color: transparent;
  }
}

.highlight-flash {
  animation: highlight-flash 1.6s ease-out;
}

/* ---- nav sidebar overrides (kept last: they specialise the base `a` and
   `.notification-panel` rules above) ---- */

.nav-links a {
  display: block;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
}

.nav-links a:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 7%, transparent);
}

.nav-links a.active {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

/* The bell panel anchors right in a wide bar; in the sidebar it opens rightwards. */
.nav .notification-panel {
  right: auto;
  left: 0;
}

/* Insights page/dashboard-card styles moved to styles/pages/insights.css. */

.grid {
  display: grid;
  grid-template-columns: auto auto;
  gap: 1rem;
}

.si-logo {
  display: flex;
  justify-content: center;

  img {
    width: 9rem;
  }

  @media (width <= 48rem) {
    width: 100%;

    img {
      width: 6rem;
    }
  }
}

img.si-decoration-1 {
  position: absolute;
  bottom: 15%;
  transform: rotate(270deg);
  filter: opacity(0.3);
  height: 13rem;
  z-index: 1;

  @media (width <= 48rem) {
    display: none;
  }
}

/* A filtered column: accent border on its filter controls. Kept last because it
   outranks every plainer `input`/`select` rule above (no-descending-specificity). */
.data-table-filters .is-filtered input,
.data-table-filters .is-filtered select {
  border-color: var(--accent);
}

/*
 * Shared modal shell (import, digest subscribe, API key / webhook secret,
 * workflow reason). Same values as si-chainpulse's copy of these components.
 * Layers: 50 notification panel · 90 dialogs · 100 command palette.
 */
.import-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 5vh;
  background: rgb(0 0 0 / 45%);
}

.import-dialog {
  width: min(900px, 92vw);
  max-height: 85vh;
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 40px rgb(0 0 0 / 35%);
}

/* Insight create/edit dialog styles moved to styles/components/insight-dialog.css. */
