﻿/* Surfaces that hold content: cards, dialogs, flyouts, detail panels, KPI tiles, document editors
   and the command palette. */

/* ---- Card ------------------------------------------------------------------------------------ */

.card {
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  background-color: var(--color-canvas-default);
  overflow: hidden;

  & .card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--color-border-muted);
    background-color: var(--color-canvas-subtle);

    & h3 {
      margin: 0;
      font-family: var(--font-display);
      font-size: 13px;
      font-weight: 600;
      letter-spacing: 0.06em;
      text-transform: uppercase;
      color: var(--color-fg-muted);
    }
  }

  & .card-body {
    padding: 12px;
  }

  /* A card whose body is a table wants no padding - the table draws its own edges. */
  & .card-body[data-flush="true"] {
    padding: 0;
  }

  & .card-foot {
    padding: 9px 12px;
    border-top: 1px solid var(--color-border-muted);
    background-color: var(--color-canvas-subtle);
    font-size: 12px;
    color: var(--color-fg-muted);
  }
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

/* ---- KPI tile ---------------------------------------------------------------------------------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi {
  position: relative;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  background-color: var(--color-canvas-default);
  padding: 12px 14px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  display: block;

  &::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background-color: var(--color-accent-emphasis);
  }

  &[data-tone="success"]::before { background-color: var(--color-success-emphasis); }
  &[data-tone="attention"]::before { background-color: var(--color-attention-emphasis); }
  &[data-tone="danger"]::before { background-color: var(--color-danger-emphasis); }
  &[data-tone="neutral"]::before { background-color: var(--color-neutral-emphasis); }

  &[href]:hover {
    border-color: var(--color-border-strong);
    text-decoration: none;
  }

  & .kpi-label {
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-fg-muted);
    margin-bottom: 5px;
  }

  & .kpi-value {
    font-family: var(--font-display);
    font-size: 27px;
    font-weight: 600;
    line-height: 1.05;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.015em;
  }

  & .kpi-note {
    margin-top: 4px;
    font-size: 11.5px;
    color: var(--color-fg-muted);
  }

  & .kpi-delta {
    font-family: var(--font-mono);
    font-size: 11.5px;
    font-weight: 600;

    &[data-direction="up"] { color: var(--color-success-fg); }
    &[data-direction="down"] { color: var(--color-danger-fg); }
    &[data-direction="flat"] { color: var(--color-fg-subtle); }
  }
}

/* ---- Detail panel (read view of a record) --------------------------------------------------------- */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px 20px;
}

.detail-item {
  min-width: 0;

  & dt {
    font-family: var(--font-display);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-fg-muted);
    margin-bottom: 2px;
  }

  & dd {
    margin: 0;
    font-size: 13.5px;
    overflow-wrap: anywhere;
  }

  & dd.num {
    font-family: var(--font-mono);
  }
}

/* ---- Document totals block ------------------------------------------------------------------------- */

/* The subtotal / tax / total stack that sits under an invoice, bill, quote or purchase order. Right
   aligned and narrow, so it lines up under the amount column of the lines above it. */
.doc-totals {
  margin-left: auto;
  width: min(320px, 100%);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  overflow: hidden;

  & .doc-total-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding: 6px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--color-border-muted);

    & span:last-child {
      font-family: var(--font-mono);
      font-variant-numeric: tabular-nums;
    }

    &:last-child { border-bottom: 0; }

    &[data-emphasis="true"] {
      background-color: var(--color-canvas-subtle);
      font-weight: 700;
      font-size: 15px;
      border-top: 1px solid var(--color-border-strong);
    }

    &[data-tone="muted"] {
      color: var(--color-fg-muted);
    }
  }
}

/* A journal entry has to balance before it can be saved; this is the running debit-credit check. */
.balance-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  font-weight: 600;
  background-color: var(--color-success-subtle);
  color: var(--color-success-fg);

  &[data-balanced="false"] {
    background-color: var(--color-danger-subtle);
    color: var(--color-danger-fg);
  }

  & .balance-figure {
    font-family: var(--font-mono);
    margin-left: auto;
  }
}

/* ---- Dialog ------------------------------------------------------------------------------------------ */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px 24px;
  background-color: rgba(8, 20, 28, 0.55);
  overflow-y: auto;
}

/* The printable preview - a confirmation dialog's backdrop, but a sheet rather than a box: the
   whole point is seeing the document at a readable size before deciding anything, so it takes most
   of the viewport and gives every pixel it can spare to the page itself.

   Its own class rather than a wide variant of .dialog because almost nothing is shared - this is a
   fixed-height flex column with a scrolling viewer in the middle and actions pinned below, where a
   dialog is a small box that grows with its message. */
.print-preview {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1100px;
  height: min(88vh, 1200px);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg);
  background-color: var(--color-canvas-overlay);
  box-shadow: var(--shadow-overlay);
  overflow: hidden;
}

.print-preview-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-shrink: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border-muted);
}

.print-preview-title {
  flex: 1;
  min-width: 0;

  & h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
  }

  & span {
    font-size: 12px;
  }
}

/* min-height:0 so the iframe can shrink inside the flex column - without it the viewer keeps its
   intrinsic height and pushes the actions off the bottom of the sheet. */
.print-preview-body {
  flex: 1;
  min-height: 0;
  background-color: var(--color-canvas-inset);

  & iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
  }
}

.print-preview-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border-muted);
}

.print-preview-hint {
  flex: 1;
  margin: 0;
  font-size: 12px;
}

@media (max-width: 720px) {
  .print-preview {
    height: 92vh;
  }

  /* The hint is the first thing to go on a phone - the three buttons are what matter. */
  .print-preview-hint {
    display: none;
  }
}

.dialog {
  width: 100%;
  max-width: 520px;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg);
  background-color: var(--color-canvas-overlay);
  box-shadow: var(--shadow-overlay);
  overflow: hidden;

  &[data-size="wide"] { max-width: 820px; }
  &[data-size="full"] { max-width: 1180px; }

  & .dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border-muted);

    & h2 {
      margin: 0;
      font-size: 15px;
      font-weight: 600;
    }

    & .dialog-close {
      border: 0;
      background: transparent;
      color: var(--color-fg-subtle);
      font-size: 17px;
      line-height: 1;
      cursor: pointer;
      padding: 2px 4px;

      &:hover { color: var(--color-fg-default); }
    }
  }

  & .dialog-body {
    padding: 16px;
    max-height: 70vh;
    overflow-y: auto;
  }

  & .dialog-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--color-border-muted);
    background-color: var(--color-canvas-subtle);
  }
}

/* ---- Flyout (a menu anchored to a control) ------------------------------------------------------------- */

.flyout {
  position: relative;
  display: inline-flex;
}

.flyout-menu {
  position: absolute;
  z-index: 120;
  top: calc(100% + 4px);
  min-width: 190px;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  background-color: var(--color-canvas-overlay);
  box-shadow: var(--shadow-overlay);
  padding: 3px;

  &[data-placement="end"] { right: 0; }
  &[data-placement="start"] { left: 0; }
}

.flyout-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 9px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-fg-default);
  font-size: 13px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;

  &:hover:not(:disabled) {
    background-color: var(--color-neutral-subtle);
    text-decoration: none;
  }

  &:disabled {
    color: var(--color-fg-subtle);
    cursor: not-allowed;
  }

  &[data-variant="danger"] {
    color: var(--color-danger-fg);

    &:hover:not(:disabled) { background-color: var(--color-danger-subtle); }
  }
}

.flyout-separator {
  height: 1px;
  margin: 3px 0;
  background-color: var(--color-border-muted);
}

/* The signed-in address above the account menu's items. Not a .flyout-item: it is a label, and
   giving it the same hover as the items below would invite a click that does nothing. */
.flyout-user {
  padding: 0 9px 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--color-fg-default);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A form wrapping a flyout item (sign-out) must not add a box of its own. */
.flyout-menu form {
  margin: 0;
}

.flyout-menu form .flyout-item {
  width: 100%;
}

.flyout-heading {
  padding: 6px 9px 3px;
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-fg-subtle);
}

/* ---- Command palette --------------------------------------------------------------------------------------- */

.palette-backdrop {
  position: fixed;
  inset: 0;
  z-index: 180;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 16px 24px;
  background-color: rgba(8, 20, 28, 0.5);
}

.palette {
  width: 100%;
  max-width: 560px;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg);
  background-color: var(--color-canvas-overlay);
  box-shadow: var(--shadow-overlay);
  overflow: hidden;

  & .palette-input {
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--color-border-muted);
    padding: 13px 16px;
    font-size: 15px;
    background: transparent;
    color: var(--color-fg-default);

    &:focus { outline: none; }
  }

  & .palette-results {
    max-height: 55vh;
    overflow-y: auto;
    padding: 5px;
  }

  & .palette-foot {
    display: flex;
    gap: 14px;
    padding: 7px 14px;
    border-top: 1px solid var(--color-border-muted);
    background-color: var(--color-canvas-subtle);
    font-size: 11px;
    color: var(--color-fg-subtle);

    & kbd {
      font-family: var(--font-mono);
      border: 1px solid var(--color-border-default);
      border-radius: var(--radius-sm);
      padding: 0 4px;
    }
  }
}

.palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 11px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-fg-default);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;

  &[data-highlighted="true"] {
    background-color: var(--color-accent-subtle);
    color: var(--color-accent-fg);
  }

  & .palette-item-section {
    margin-left: auto;
    font-size: 11px;
    color: var(--color-fg-subtle);
  }
}

/* ---- Timeline (approval history, posting trail) ------------------------------------------------------------- */

.timeline {
  list-style: none;
  margin: 0;
  padding: 0 0 0 18px;
  border-left: 2px solid var(--color-border-muted);

  & li {
    position: relative;
    padding: 0 0 14px 12px;
    font-size: 12.5px;

    &::before {
      content: "";
      position: absolute;
      left: -23px;
      top: 4px;
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background-color: var(--color-border-strong);
      border: 2px solid var(--color-canvas-default);
    }

    &[data-tone="success"]::before { background-color: var(--color-success-emphasis); }
    &[data-tone="danger"]::before { background-color: var(--color-danger-emphasis); }
    &[data-tone="accent"]::before { background-color: var(--color-accent-emphasis); }

    & .timeline-title { font-weight: 600; }

    & .timeline-meta {
      color: var(--color-fg-subtle);
      font-size: 11.5px;
    }
  }
}

/* ---- Account screens ------------------------------------------------------------------------------ */

/* The permission list on the profile page, grouped by module. Dense on purpose: this is a reference
   a user scans for one code, not prose. */
.permission-module {
  border-bottom: 1px solid var(--color-border-muted);
  padding: 10px 12px;

  &:last-child { border-bottom: 0; }

  & .permission-module-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 6px;
  }
}

.permission-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 2px 18px;

  & li {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 12.5px;
    min-width: 0;
  }

  & code {
    font-size: 11.5px;
    color: var(--color-accent-fg);
    white-space: nowrap;
  }

  & span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Two-factor enrolment. The QR gets a white plate in both themes - a dark background behind a QR
   code is exactly what phone cameras fail to read. */
.totp-qr {
  display: block;
  width: 176px;
  height: 176px;
  padding: 8px;
  margin: 4px 0 14px;
  background-color: #ffffff;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
}

.totp-secret {
  display: block;
  padding: 7px 10px;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  background-color: var(--color-canvas-inset);
  font-size: 12.5px;
  letter-spacing: 0.08em;
  word-break: break-all;
}

/* ---- Permission picker ----------------------------------------------------------------------- */

/* Choosing from seventy-eight permissions. Grouped by module and dense, because this is a set a
   person scans and toggles rather than reads through once. */

.permission-picker {
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  background-color: var(--color-canvas-default);
  overflow: hidden;
}

.permission-picker-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 12px;
  border-bottom: 1px solid var(--color-border-default);
  background-color: var(--color-canvas-subtle);
  /* Sticks while the list scrolls: the running count and the clear-all are what you reach for
     halfway down, which is exactly where they would otherwise have scrolled away. */
  position: sticky;
  top: 0;
  z-index: 2;

  & .form-input {
    flex: 1;
    min-width: 180px;
    height: 28px;
    min-height: 28px;
    font-size: 12.5px;
  }
}

.permission-picker-count {
  font-size: 12.5px;
  color: var(--color-fg-muted);
  white-space: nowrap;

  & b {
    font-family: var(--font-mono);
    color: var(--color-fg-default);
  }
}

.permission-group {
  border-bottom: 1px solid var(--color-border-muted);

  &:last-child { border-bottom: 0; }
}

.permission-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background-color: var(--color-canvas-subtle);
  position: sticky;
  top: 46px;
  z-index: 1;

  & .eyebrow { flex: 1; }
}

.permission-group-count {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--color-fg-muted);

  /* A fully-granted module is the thing you scan for when auditing a role. */
  &[data-all="True"] {
    color: var(--color-success-fg);
    font-weight: 600;
  }
}

.permission-group-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 0 14px;
  padding: 6px 12px 10px;
}

.permission-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-width: 0;

  &:hover { background-color: var(--color-neutral-subtle); }

  & input[type="checkbox"] {
    width: 15px;
    height: 15px;
    margin: 2px 0 0;
    accent-color: var(--color-accent-emphasis);
    flex-shrink: 0;
  }
}

.permission-option-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.permission-option-label {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.permission-option code {
  font-size: 11px;
  color: var(--color-fg-subtle);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Roles on a user ------------------------------------------------------------------------- */

.role-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.role-choice-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  padding: 6px;
}
