/*
 * Republic OS — Atlas design system.
 *
 * Ported from rc_atlas (see DESIGN.md). Flat, navy-tinted operations console:
 * one burnt-orange accent, DM type family (Serif Display / Sans / Mono),
 * 0px corners, 1px hairlines, NO shadows. Depth is tone + hairline only.
 *
 * Served as-is by Propshaft. Class names are kept stable so existing views
 * inherit the new look; values and component rules are retargeted to Atlas.
 */

:root {
  color-scheme: light;

  /* Brand & accent — burnt orange (the ONLY chromatic brand color) */
  --accent: #bd5500;
  --accent-hover: #d96100;
  --accent-deep: #984500;
  --accent-deeper: #733400;
  --accent-ink: #ffffff;
  --on-primary: #ffffff;

  /* Surfaces — neutrals tinted toward the brand anchor #0c1d37 */
  --canvas: #fbfcfe;
  --background: #fbfcfe;
  --surface: #fbfcfe;
  --surface-muted: #f0f3f8;
  --surface-1: #f0f3f8;
  --surface-2: #dbe1ec;
  --inverse-canvas: #0c1d37;
  --inverse-surface-1: #1a2b48;

  /* Hairlines */
  --line: #dbe1ec;
  --hairline: #dbe1ec;
  --hairline-mid: #9aa6bb;
  --hairline-strong: #0c1d37;

  /* Text — same navy undertone */
  --ink: #0c1d37;
  --muted: #3f4d68;
  --ink-muted: #3f4d68;
  --ink-subtle: #7a869f;
  --inverse-ink: #fbfcfe;
  --inverse-ink-muted: #b9c2d2;

  /* Semantic */
  --success: #24a148;
  --warning: #f1c21b;
  --error: #da1e28;
  --danger: #da1e28;
  --wip-ink: #946d00;

  /* Category palette — data, not decoration */
  --commerce: #4ea1ff;
  --marketing: #ff7a59;
  --finance: #24a148;
  --infra: #94a3b8;

  /* Spacing — Carbon 4px grid */
  --space-xxs: 4px;
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-xxl: 48px;
  --space-section: 96px;

  /* Geometry — flat by mandate */
  --radius: 0;
  --shadow: none;

  /* Z-index scale */
  --z-sticky: 10;
  --z-popover: 30;
  --z-drawer-backdrop: 40;
  --z-drawer: 50;

  /* Typography — DM family throughout */
  --sans: "DM Sans", "Helvetica Neue", Arial, sans-serif;
  --serif: "DM Serif Display", "DM Serif Text", "Iowan Old Style", "Georgia", serif;
  --mono: "DM Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: 0.16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Links ---------- */

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.12s ease, border-color 0.12s ease;
}

a:hover {
  color: var(--accent-deep);
  border-bottom-color: var(--accent-deep);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button,
input,
select,
textarea {
  font: inherit;
}

::selection {
  background: var(--accent);
  color: var(--on-primary);
}

/* ---------- Typography ---------- */

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.25;
}

h2 {
  margin-bottom: var(--space-md);
  font-size: 22px;
  font-weight: 400;
  line-height: 1.3;
}

h3 {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
}

p {
  margin: 0;
}

code,
kbd,
samp,
pre {
  font-family: var(--mono);
}

code {
  font-size: 0.9em;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  padding: 1px 6px;
}

/* ---------- Tables ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  letter-spacing: 0.16px;
}

th,
td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--hairline);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface-1);
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.32px;
  text-transform: uppercase;
}

tbody tr:hover td {
  background: var(--surface-1);
}

tr:last-child td {
  border-bottom: 0;
}

th.numeric,
td.numeric {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ---------- App shell (full-height sidebar + content column) ---------- */

.auth-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: var(--space-lg);
}

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

.app-shell {
  flex: 1;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.app-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ---------- Sidebar ---------- */

.app-sidebar {
  background: var(--canvas);
  border-right: 1px solid var(--hairline);
}

/* Sticks the nav while the white column itself stretches to the footer.
   100% fills the column on short pages; the viewport cap takes over on
   long pages so the nav stays pinned while content scrolls. */
.sidebar-sticky {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  height: 48px;
  padding: 0 var(--space-md);
  border-bottom: 1px solid var(--hairline);
}

.brand-mark {
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.16px;
  border-bottom: 0;
}

.brand-mark:hover {
  color: var(--ink);
  border-bottom: 0;
}

.current-user,
.muted,
small {
  color: var(--ink-subtle);
}

.current-user,
small {
  font-size: 12px;
  letter-spacing: 0.32px;
}

.sidebar-nav {
  display: grid;
  gap: 2px;
  padding: 0 var(--space-xs);
}

.sidebar-group-label {
  margin: 0;
  padding: var(--space-md) var(--space-xs) var(--space-xs);
  color: var(--ink-subtle);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.32px;
  text-transform: uppercase;
}

.nav-row {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 8px var(--space-sm);
  border-bottom: 0;
  border-left: 2px solid transparent;
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0.16px;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.nav-row:hover {
  background: var(--surface-1);
  color: var(--ink);
}

.nav-row.active {
  background: var(--surface-1);
  border-left-color: var(--accent);
  font-weight: 600;
}

.nav-row svg {
  flex-shrink: 0;
  color: var(--ink-subtle);
  transition: color 0.12s ease;
}

.nav-row:hover svg {
  color: var(--ink);
}

.nav-row.active svg {
  color: var(--accent);
}

.sidebar-footer {
  display: grid;
  margin-top: auto;
  padding: var(--space-xs);
  border-top: 1px solid var(--hairline);
}

.sidebar-copyright {
  margin: auto 0 0;
  padding: var(--space-xs) var(--space-sm);
  border-top: 1px solid var(--hairline);
  color: var(--ink-subtle);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.32px;
  text-align: center;
}

.sidebar-footer + .sidebar-copyright {
  margin-top: 0;
}

.sidebar-back {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin: var(--space-md) var(--space-xs) 0;
  padding: 8px var(--space-sm);
  border: 1px solid var(--hairline);
  color: var(--ink);
  font-size: 13px;
  letter-spacing: 0.16px;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.sidebar-back:hover {
  background: var(--surface-1);
  border-color: var(--ink-subtle);
  color: var(--ink);
}

/* ---------- Workspace switcher (disclosure in the sidebar) ---------- */

.unit-switcher {
  position: relative;
  margin: var(--space-md) var(--space-xs) 0;
}

.unit-switcher-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-xs);
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: 0;
  background: var(--surface-1);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.16px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s ease;
}

.unit-switcher-button:hover {
  border-color: var(--ink-subtle);
}

.unit-switcher-button .chevron {
  flex-shrink: 0;
  color: var(--ink-subtle);
  transition: transform 0.12s ease;
}

.unit-switcher-button[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.unit-switcher-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-switcher-panel[hidden] {
  display: none;
}

.unit-switcher-panel {
  position: absolute;
  top: calc(100% - 1px);
  left: 0;
  right: 0;
  z-index: var(--z-popover);
  display: grid;
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--hairline-mid);
  background: var(--canvas);
}

.unit-switcher-panel .button_to {
  display: contents;
}

.unit-switcher-panel .unit-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-xs);
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 0;
  background: var(--canvas);
  color: var(--ink);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.16px;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}

.unit-switcher-panel button.unit-option:hover {
  background: var(--surface-1);
  color: var(--ink);
  border-color: transparent;
}

.unit-switcher-panel .unit-option.is-current {
  color: var(--ink-muted);
  cursor: default;
}

.unit-switcher-panel .unit-option.is-current::after {
  content: "current";
  color: var(--ink-subtle);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.32px;
}

/* ---------- Top bar (48px, page context + session tools) ---------- */

.app-topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  height: 48px;
  padding: 0 var(--space-lg);
  background: var(--canvas);
  border-bottom: 1px solid var(--hairline);
}

.page-context {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-muted);
  font-size: 13px;
  letter-spacing: 0.16px;
}

.session-tools,
.actions,
.form-actions,
.row-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex-wrap: wrap;
}

.session-tools {
  flex-wrap: nowrap;
  margin-left: auto;
  gap: var(--space-md);
}

.session-tools .button_to {
  display: contents;
}

.menu-button {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: 0;
  background: var(--canvas);
  color: var(--ink);
  cursor: pointer;
}

.menu-button:hover {
  background: var(--surface-1);
  border-color: var(--ink-subtle);
}

.drawer-backdrop {
  display: none;
}

/* ---------- Main regions ---------- */

.app-main,
.auth-main {
  width: 100%;
}

.app-main {
  flex: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-xl);
}

.auth-main {
  max-width: 420px;
  padding: var(--space-lg);
}

/* ---------- Page header ---------- */

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--hairline);
}

.eyebrow {
  display: block;
  margin-bottom: var(--space-xs);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.32px;
  text-transform: uppercase;
  color: var(--accent);
}

/* ---------- Panels / cards (flat: 0px radius, 1px hairline, no shadow) ---------- */

.panel,
.login-card {
  border: 1px solid var(--hairline);
  border-radius: 0;
  background: var(--canvas);
  box-shadow: none;
}

.panel {
  padding: var(--space-lg);
}

.panel + .panel {
  margin-top: var(--space-md);
}

.login-card {
  width: 100%;
  padding: var(--space-xl);
}

.login-card h1 {
  margin-bottom: var(--space-md);
}

/* ---------- Forms ---------- */

.form-stack {
  display: grid;
  gap: var(--space-md);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-md);
}

.field {
  display: grid;
  gap: var(--space-xxs);
}

.field label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.32px;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.field input,
.field select,
.field textarea {
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: 0;
  background: var(--surface-1);
  color: var(--ink);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field textarea {
  min-height: 90px;
  resize: vertical;
}

.compact-field {
  max-width: 220px;
}

/* ---------- Buttons (square, 1px border, 12px 16px) ---------- */

.button,
.link-button,
input[type="submit"],
button[type="submit"] {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 12px 16px;
  border: 1px solid var(--hairline);
  border-radius: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.16px;
  line-height: 1.29;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.button:hover,
.link-button:hover,
input[type="submit"]:hover,
button[type="submit"]:hover {
  background: var(--surface-1);
  color: var(--ink);
  border-color: var(--ink-subtle);
}

.button.primary,
input[type="submit"].primary,
button[type="submit"].primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.button.primary:hover,
input[type="submit"].primary:hover,
button[type="submit"].primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-ink);
}

.button.ghost {
  background: var(--canvas);
  border-color: transparent;
  color: var(--accent);
}

.button.ghost:hover {
  background: var(--surface-1);
  border-color: transparent;
  color: var(--accent-deep);
}

.button.danger {
  border-color: var(--error);
  background: var(--canvas);
  color: var(--error);
}

.button.danger:hover {
  background: var(--error);
  border-color: var(--error);
  color: var(--on-primary);
}

.link-button,
button.link-button,
input[type="submit"].link-button {
  border-color: transparent;
  background: transparent;
  color: var(--accent);
}

.link-button:hover,
button.link-button:hover,
input[type="submit"].link-button:hover {
  background: var(--surface-1);
  border-color: transparent;
  color: var(--accent-deep);
}

.icon-button,
button.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.icon-button:hover,
button.icon-button:hover {
  background: var(--surface-1);
  border-color: transparent;
  color: var(--ink);
}

/* ---------- Tag / badge (Carbon eyebrow style — square, no pill) ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid var(--hairline);
  border-radius: 0;
  background: var(--surface-1);
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.32px;
  line-height: 1;
}

/* ---------- Resource list (flat hairline rows) ---------- */

.resource-list {
  display: grid;
  gap: var(--space-xs);
}

.resource-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-md);
  border: 1px solid var(--hairline);
  border-radius: 0;
  background: var(--canvas);
  transition: background 0.12s ease, border-color 0.12s ease;
}

.resource-row:hover {
  background: var(--surface-1);
  border-color: var(--ink-subtle);
}

.resource-row div {
  display: grid;
  gap: var(--space-xxs);
}

.resource-row .row-actions {
  display: flex;
  gap: var(--space-xs);
}

.resource-row span {
  color: var(--ink-muted);
}

.panel-heading {
  display: flex;
  gap: var(--space-sm);
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

/* ---------- Detail / summary grids ---------- */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-sm);
}

.detail-grid div {
  display: grid;
  gap: var(--space-xxs);
}

.detail-grid span {
  color: var(--ink-muted);
  font-size: 12px;
  letter-spacing: 0.32px;
  text-transform: uppercase;
}

.estimate-summary,
.print-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-md);
}

.estimate-summary div,
.print-grid div,
.print-total,
.notes-block {
  display: grid;
  gap: var(--space-xxs);
}

.estimate-summary span,
.print-grid span,
.print-total span,
.notes-block span {
  color: var(--ink-muted);
  font-size: 12px;
  letter-spacing: 0.32px;
  text-transform: uppercase;
}

.notes-block {
  margin-top: var(--space-md);
}

.notes-block p {
  margin: 0;
}

/* ---------- Line items ---------- */

.line-item-list {
  display: grid;
  gap: var(--space-xs);
}

.line-item-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 90px 110px 130px 80px;
  gap: var(--space-xs);
  align-items: center;
}

.line-item-heading {
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.32px;
  text-transform: uppercase;
}

.remove-field {
  justify-items: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Print sheet ---------- */

.print-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
}

.print-sheet {
  border: 1px solid var(--hairline);
  border-radius: 0;
  background: var(--canvas);
  padding: var(--space-xl);
}

.print-header {
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-xl);
}

.print-total {
  justify-items: end;
}

.print-total strong {
  font-family: var(--serif);
  font-size: 28px;
}

.print-section {
  margin-top: var(--space-xl);
}

/* ---------- Flash / errors (flat hairline banners) ---------- */

.flash,
.error-box {
  margin-bottom: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--hairline);
  border-left: 2px solid var(--ink-subtle);
  border-radius: 0;
  background: var(--surface-1);
  color: var(--ink);
}

.flash {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-sm);
  transition: opacity 0.2s ease-out;
}

.flash-dismissing {
  opacity: 0;
}

.flash-dismiss {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin: -2px -6px -2px 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.flash-dismiss:hover {
  background: var(--surface-2);
  color: var(--ink);
}

@media (prefers-reduced-motion: reduce) {
  .flash {
    transition: none;
  }
}

.flash-notice {
  border-left-color: var(--success);
}

.flash-alert,
.error-box {
  border-left-color: var(--error);
}

.error-box ul {
  margin: var(--space-xs) 0 0;
  padding-left: var(--space-lg);
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .app-main {
    padding: var(--space-lg) var(--space-md);
  }

  .page-header,
  .resource-row,
  .panel-heading,
  .print-header {
    display: grid;
    gap: var(--space-sm);
  }

  .line-item-grid {
    grid-template-columns: 1fr 80px;
  }

  .line-item-heading {
    display: none;
  }

  table {
    display: block;
    overflow-x: auto;
  }
}

/* ---------- Drawer (sidebar collapses below 672px) ---------- */

@media (max-width: 672px) {
  .app-shell {
    display: block;
  }

  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: var(--z-drawer);
    width: min(280px, 85vw);
    border-right: 1px solid var(--hairline-mid);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease-out, visibility 0.2s;
  }

  .drawer-open .app-sidebar {
    transform: none;
    visibility: visible;
  }

  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: var(--z-drawer-backdrop);
    background: rgba(12, 29, 55, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-out;
  }

  .drawer-open .drawer-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .menu-button {
    display: inline-flex;
  }

  .app-topbar {
    padding: 0 var(--space-md);
  }

  .app-topbar .current-user {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar,
  .drawer-backdrop,
  .unit-switcher-button .chevron {
    transition: none;
  }
}

/* ---------- Print ---------- */

@media print {
  body {
    background: #ffffff;
    color: #000000;
  }

  .app-sidebar,
  .app-topbar,
  .drawer-backdrop,
  .flash,
  .no-print {
    display: none;
  }

  .app-shell {
    display: block;
  }

  .app-main {
    width: 100%;
    max-width: none;
    padding: 0;
  }

  .print-sheet {
    border: 0;
    box-shadow: none;
    padding: 0;
  }
}
