:root {
  color-scheme: dark;
  --cedar: #72b58c;
  --cedar-dark: #10241f;
  --cedar-soft: rgba(114, 181, 140, 0.14);
  --ink: #edf5ef;
  --muted: #a8b8b0;
  --line: rgba(185, 207, 195, 0.2);
  --surface: #15251f;
  --surface-strong: #1b2f27;
  --page: #08110f;
  --panel: rgba(18, 34, 29, 0.94);
  --warning: #ffc36e;
  --danger: #ff9a9a;
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: start center;
  padding: calc(clamp(280px, 38vh, 420px) + 48px) 24px 32px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(7, 12, 18, 0.44), rgba(8, 16, 24, 0.7)),
    url('./assets/login-bg.svg?v=20260627top') center top / cover no-repeat,
    #091018;
}

body.app-active {
  display: block;
  padding: 0;
  background:
    radial-gradient(circle at 50% -10%, rgba(114, 181, 140, 0.22), rgba(8, 17, 15, 0) 380px),
    linear-gradient(180deg, rgba(16, 36, 31, 0.88), rgba(8, 17, 15, 0.98)),
    var(--page);
}

body.app-active.has-test-banner .app-shell {
  padding-top: 68px;
}

button,
input {
  font: inherit;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.test-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10050;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #8a1f2d;
  color: #fff;
  text-align: center;
  font: 800 13px/1.2 Arial, Helvetica, sans-serif;
  letter-spacing: .12em;
  padding: 12px 16px;
  box-shadow: 0 10px 24px #0004;
}

.test-banner-btn {
  appearance: none;
  -webkit-appearance: none;
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  padding: 6px 12px;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  line-height: 1.1;
  text-transform: uppercase;
  white-space: nowrap;
}

.test-banner-btn[data-enabled="false"],
.test-banner-btn.off {
  background: rgba(0, 0, 0, 0.24);
  border-color: rgba(255, 255, 255, 0.22);
}

.login-shell {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  display: grid;
  gap: 0;
  justify-items: center;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.35);
  text-align: center;
  backdrop-filter: blur(18px);
}

.login-shell {
  border-color: #2a394a;
  background: rgba(18, 27, 37, 0.96);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
}

.login-icon {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: 10px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #7fa8d6;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(19px, 3.6vw, 26px);
  line-height: 1.15;
}

.login-subtitle,
.login-copy {
  color: #a6b7ca;
  text-align: center;
  line-height: 1.5;
}

.login-subtitle {
  margin: 0;
  font-size: 14px;
}

.login-copy {
  margin: 14px 0 0;
  font-size: 13px;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.primary-button {
  width: 100%;
  padding: 14px 18px;
  background: var(--cedar);
  color: #08110f;
  font-weight: 700;
  line-height: 1.15;
}

.login-shell .primary-button {
  border: 0;
  border-radius: 12px;
  background: #1d6ec8;
  color: #fff;
  font-size: 16px;
}

.login-shell .primary-button:hover {
  background: #165ba7;
}

.primary-button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.secondary-button,
.icon-button {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

.secondary-button {
  padding: 0 14px;
}

.icon-button {
  width: 42px;
  display: grid;
  place-items: center;
  text-decoration: none;
  font-size: 1.8rem;
}

.error-message {
  margin: 0;
  color: var(--danger);
  font-size: 0.92rem;
}

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.app-header {
  min-height: 74px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 12px 0 22px;
}

.app-icon {
  width: auto;
  height: 2.15em;
  object-fit: contain;
  border-radius: 10px;
}

.title-block {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}

.header-spacer {
  min-width: 0;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
  align-items: center;
}

.auth-chip {
  position: relative;
}

.auth-chip-trigger {
  max-width: min(calc(100vw - 32px), 420px);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.35);
}

.auth-chip-trigger:hover,
.auth-chip-trigger:focus-visible {
  border-color: rgba(114, 181, 140, 0.62);
  background: var(--surface-strong);
  outline: none;
}

.auth-avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: linear-gradient(135deg, #254638, #0d1f1a);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: #eaf7ef;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  overflow: hidden;
  text-transform: uppercase;
}

.auth-identity {
  min-width: 0;
  display: grid;
  gap: 1px;
  text-align: left;
}

.auth-name-row {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-name,
.auth-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-name {
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.auth-email {
  color: var(--muted);
  font-size: 0.76rem;
}

.auth-role-chip {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(114, 181, 140, 0.16);
  color: #b7e7c8;
  font-size: 0.74rem;
  font-weight: 800;
}

.auth-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  min-width: 180px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.35);
}

.auth-menu button {
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.auth-menu button:hover,
.auth-menu button:focus-visible {
  background: var(--surface-strong);
  outline: none;
}

.email-log-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 14, 0.72);
}

.email-log-card {
  width: min(760px, 100%);
  max-height: min(80vh, 760px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1722;
  color: #e8eef8;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
}

.email-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid #203044;
}

.email-log-head h2,
.email-log-head p,
.email-log-status,
.email-log-meta,
.email-log-reason {
  margin: 0;
}

.email-log-head h2 {
  font-size: 1rem;
}

.email-log-head p,
.email-log-meta,
.email-log-reason {
  color: #a8bad0;
  font-size: 0.82rem;
  line-height: 1.5;
}

.email-log-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #c7d4e8;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 800;
}

.email-log-close:hover,
.email-log-close:focus-visible {
  background: #162434;
  outline: none;
}

.email-log-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid #203044;
}

.email-log-filter {
  display: grid;
  gap: 4px;
  color: #9eb2ca;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.email-log-filter input {
  min-height: 38px;
  min-width: 150px;
  border: 1px solid #223247;
  border-radius: 8px;
  background: #111c28;
  color: #e8eef8;
  padding: 0 10px;
}

.email-log-status {
  padding: 10px 18px;
  color: #9eb2ca;
  font-size: 0.82rem;
  font-weight: 700;
}

.email-log-list {
  display: grid;
  gap: 12px;
  padding: 0 18px 18px;
  overflow: auto;
}

.email-log-entry {
  display: grid;
  gap: 6px;
  border: 1px solid #223247;
  border-radius: 8px;
  padding: 12px 14px;
  background: #121c28;
}

.email-log-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.email-log-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.email-log-pill {
  min-height: 20px;
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: #16304d;
  color: #8ec3ff;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.email-log-pill[data-status="suppressed"] {
  background: #4d2916;
  color: #ffbf8e;
}

.email-log-pill[data-status="cancellation"],
.email-log-pill[data-status="po-cancelled"] {
  background: #4d1620;
  color: #ff9aa8;
}

.email-log-pill[data-status="change_order"] {
  background: #2c2440;
  color: #c4adff;
}

.email-log-pill[data-status="goods_receipt"] {
  background: #16402c;
  color: #8effc0;
}

.email-log-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #9eb2ca;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
}

.email-log-checkbox input {
  width: 16px;
  height: 16px;
  accent-color: #ff9aa8;
}

/* --- View nav (Orders / Date Changes) --- */
.app-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.app-nav-tab {
  position: relative;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 800;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.app-nav-tab:hover {
  color: var(--ink);
}

.app-nav-tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--cedar);
}

.app-nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin-left: 8px;
  padding: 0 5px;
  border-radius: 999px;
  background: #c2410c;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  vertical-align: middle;
}

/* --- Date Change Approvals page --- */
.dc-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.dc-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.dc-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.dc-toolbar {
  margin-bottom: 4px;
}

.dc-status {
  margin: 8px 0 12px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.dc-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.dc-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  background: var(--surface);
  color: var(--ink);
}

.dc-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dc-card-head strong {
  font-size: 1rem;
}

.dc-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.dc-pill-pending {
  background: rgba(255, 195, 110, 0.16);
  color: var(--warning);
}

.dc-pill-rejected {
  background: rgba(255, 107, 107, 0.16);
  color: #ff6b6b;
}

.dc-pill-approved {
  background: var(--cedar-soft);
  color: var(--cedar);
}

.dc-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.dc-dates {
  display: grid;
  gap: 6px;
  padding: 8px 0;
  border-top: 1px dashed var(--line);
  border-bottom: 1px dashed var(--line);
}

.dc-date {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
}

.dc-date-label {
  color: var(--muted);
  font-weight: 700;
}

.dc-date.is-moved {
  color: var(--warning);
}

.dc-date.is-moved strong {
  color: var(--warning);
}

.dc-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 2px;
}

.dc-actions .secondary-button,
.dc-actions .primary-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.82rem;
}

/* --- App-native dialog --- */
.rcs-dialog-card {
  width: min(620px, 100%);
  max-height: min(82vh, 720px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0f1722;
  color: #e8eef8;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
}

.rcs-dialog-body {
  padding: 16px 18px;
  overflow: auto;
  color: #cdd9ea;
  font-size: 0.9rem;
  line-height: 1.5;
}

.rcs-dialog-body p {
  margin: 0 0 8px;
}

.rcs-dialog-pre {
  margin: 8px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #0b1320;
  color: #d8e4f5;
  white-space: pre-wrap;
  word-break: break-word;
  font: 500 0.76rem/1.5 Consolas, Monaco, monospace;
}

.rcs-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid #203044;
}

.rcs-dialog-btn {
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid #30445d;
  border-radius: 8px;
  background: #162434;
  color: #e8eef8;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.rcs-dialog-btn:hover {
  background: #1d3147;
}

.rcs-dialog-btn.primary {
  background: #1f6feb;
  border-color: #1f6feb;
  color: #fff;
}

.rcs-dialog-btn.primary:hover {
  background: #2d7bf5;
}

.email-log-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.email-log-toggle {
  min-height: 32px;
  border: 1px solid #30445d;
  border-radius: 8px;
  background: #162434;
  color: #e8eef8;
  padding: 0 10px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
}

.email-log-details {
  display: none;
}

.email-log-entry.is-open .email-log-details {
  display: block;
}

.email-log-details pre {
  margin: 4px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #0b1320;
  color: #d8e4f5;
  white-space: pre-wrap;
  word-break: break-word;
  font: 500 0.78rem/1.5 Consolas, Monaco, monospace;
}

.email-log-frame {
  display: block;
  width: 100%;
  min-height: 320px;
  margin: 4px 0 0;
  border: 1px solid #30445d;
  border-radius: 8px;
  background: #ffffff;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.summary-grid article {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.summary-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 1.9rem;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr) minmax(260px, 360px);
  gap: 12px;
  align-items: end;
  margin: 18px 0 12px;
}

.search-field {
  display: grid;
  gap: 6px;
}

.search-field label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.search-field input {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink);
}

.segmented {
  max-width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  justify-self: center;
}

.toolbar-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  justify-self: end;
  width: 100%;
}

.toolbar-actions .primary-button,
.toolbar-actions .secondary-button {
  width: 100%;
  min-width: 0;
  padding: 0 12px;
}

.segment {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
}

.segment.active {
  background: var(--cedar-soft);
  border-color: var(--cedar);
  color: #c8f0d5;
  font-weight: 700;
}

.table-shell {
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.92rem;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  letter-spacing: inherit;
  padding: 0;
  text-align: left;
  text-transform: inherit;
}

.sort-button::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0.38;
}

.sort-button.active {
  color: var(--ink);
}

.sort-button.active[data-direction="asc"]::after {
  border-top: 0;
  border-bottom: 5px solid currentColor;
  opacity: 0.9;
}

.sort-button.active[data-direction="desc"]::after {
  opacity: 0.9;
}

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

.select-col {
  width: 44px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--cedar-soft);
  color: #c8f0d5;
  font-size: 0.78rem;
  font-weight: 700;
}

.status-pill.warning {
  background: rgba(255, 195, 110, 0.14);
  color: var(--warning);
}

.status-pill.danger {
  background: rgba(255, 91, 91, 0.16);
  color: #ff8f8f;
}

.status-pill.changed {
  background: rgba(91, 141, 239, 0.16);
  color: #9fbdf8;
}

.status-pill.muted {
  background: rgba(168, 184, 176, 0.14);
  color: #c8d5cf;
}

.date-change-cell {
  background: rgba(91, 141, 239, 0.10);
  box-shadow: inset 3px 0 0 #5b8def;
}

.date-change-marker,
.change-summary {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  margin-left: 8px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(91, 141, 239, 0.14);
  color: #b8ccfa;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}

.change-summary {
  margin-top: 6px;
  margin-left: 0;
}

.date-group-row td {
  padding: 10px 12px;
  background: rgba(114, 181, 140, 0.12);
  color: #b7e7c8;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.project-group-row td {
  padding: 10px 12px;
  background: var(--surface-strong);
  border-top: 2px solid rgba(114, 181, 140, 0.35);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 800;
}

.project-group-count {
  margin-left: 10px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.empty-state {
  margin: 0;
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 840px) {
  .app-header,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .app-header {
    align-items: start;
    justify-items: center;
  }

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

  .header-actions {
    justify-content: center;
  }

  .toolbar-actions {
    justify-self: stretch;
  }

  .header-spacer {
    display: none;
  }
}

@media (max-height: 640px) {
  body {
    place-items: end center;
    padding: 72px 24px clamp(32px, 8vh, 72px);
  }
}
