/* Hallmark · pre-emit critique: P4 H5 E4 S4 R5 V4 */
/* Hallmark · genre: editorial · macrostructure: Workbench (app pages) · design-system: design.md · designed-as-app
   WhatsApp Claims — "Counting House": dark green chrome band, warm ledger paper,
   serif display, mono numerals. Tokens live in /tokens.css. */

@import url("https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400&family=Fraunces:ital,opsz,wght@0,9..144,500;0,9..144,600;0,9..144,700;1,9..144,400&display=swap");
@import url("/tokens.css?v=6");

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--ink);
  background: var(--app-bg, #e9e3d4);
  background-image: var(
    --app-bg-image,
    radial-gradient(ellipse 90% 70% at 8% 0%, rgba(15, 77, 72, 0.06) 0%, transparent 55%),
    radial-gradient(ellipse 70% 50% at 100% 100%, rgba(196, 92, 38, 0.05) 0%, transparent 50%),
    linear-gradient(170deg, #efe9da 0%, #e5dfcd 100%)
  );
  min-height: 100vh;
  min-height: 100dvh;
}

body.auth-body {
  --app-bg: #11231f;
  --app-bg-image: radial-gradient(ellipse 80% 60% at 20% 20%, rgba(15, 77, 72, 0.5) 0%, transparent 50%),
    radial-gradient(ellipse 60% 50% at 100% 80%, rgba(196, 92, 38, 0.16) 0%, transparent 45%),
    linear-gradient(155deg, #0c1714 0%, #142823 45%, #0f1d19 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

a {
  color: var(--brand);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ——— Brand / type ——— */
.brandword {
  font-family: var(--font-display);
  font-weight: 600;
  font-optical-sizing: auto;
  letter-spacing: -0.02em;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--ink);
}

h1 {
  font-size: clamp(1.35rem, 3.5vw, 1.75rem);
}

h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--edge);
}

/* ——— Auth (login) ——— */
.auth-card {
  width: 100%;
  max-width: 22rem;
  min-width: 0;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--edge);
  border-top: 3px solid var(--accent);
  animation: rise 0.55s ease-out;
}

.auth-card h1 {
  text-align: center;
  color: var(--brand);
  margin-bottom: 0.35rem;
  font-size: 1.65rem;
}
.auth-card h1 .brand-accent {
  color: var(--accent);
}

.auth-sub {
  text-align: center;
  color: var(--ink-muted);
  font-size: var(--text-sm);
  margin-bottom: 1.6rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.form-hint {
  display: block;
  color: var(--ink-faint);
  font-size: var(--text-xs);
  margin-top: 0.3rem;
}

.form-group {
  margin-bottom: 1.1rem;
}

.form-group label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: 0.35rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  font-family: var(--font-ui);
  font-size: 1rem;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--ink);
  transition: border-color 0.2s, box-shadow 0.2s;
}
input::placeholder,
textarea::placeholder {
  color: var(--ink-faint);
}
input:hover,
select:hover,
textarea:hover {
  border-color: var(--edge-strong);
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

/* ——— App chrome ——— */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.8rem 1.25rem;
  padding-top: max(0.8rem, env(safe-area-inset-top));
  background: var(--chrome);
  border-bottom: 2px solid var(--accent);
  box-shadow: var(--shadow-md);
}

.app-header h1 {
  font-size: clamp(1rem, 3vw, 1.2rem);
  color: var(--chrome-ink);
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-width: 0;
  flex-wrap: wrap;
}

.app-header__home {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--chrome-ink);
  white-space: nowrap;
}
.app-header__home .brand-accent {
  color: var(--accent);
}
a.app-header__home {
  text-decoration: none;
}
a.app-header__home:hover {
  text-decoration: none;
  color: var(--chrome-ink);
}

.app-header__divider {
  width: 1px;
  height: 1.35rem;
  background: var(--chrome-edge);
  flex: 0 0 auto;
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

.app-nav a {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 0.85rem;
  border-radius: 7px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--chrome-faint);
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
}
.app-nav a:hover {
  background: var(--chrome-raised);
  color: var(--chrome-ink);
  text-decoration: none;
}
.app-nav a.active {
  background: var(--chrome-raised);
  color: var(--chrome-ink);
  box-shadow: inset 0 -2px 0 var(--accent);
  text-decoration: none;
}

/* ——— Layout ——— */
.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
  animation: rise 0.5s ease-out 0.05s both;
}
.app-container--wide {
  max-width: 1400px;
}

/* ——— Cards ——— */
.card {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
  min-width: 0;
}
.card--tight {
  padding: 1.25rem;
}
.card h2 {
  font-size: 1.1rem;
  border-bottom: 0;
  margin-bottom: 1rem;
  padding-bottom: 0;
}
.card__lead {
  margin-bottom: 1rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
  min-width: 0;
}
@media (max-width: 900px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

.field {
  margin-bottom: 0.9rem;
}
.field label {
  display: block;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--ink-faint);
  margin-bottom: 0.25rem;
}
.field .value {
  font-size: var(--text-md);
  color: var(--ink);
  font-weight: 600;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* ——— Filters / toolbar ——— */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.1rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 0.85rem 1rem 0.75rem;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.stat__value {
  display: block;
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.stat__label {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
  font-weight: 700;
}
.stat--review {
  border-left: 3px solid var(--accent);
}
.stat--review .stat__value {
  color: var(--accent);
}
.stat--ok .stat__value {
  color: var(--success);
}
.stat--bad .stat__value {
  color: var(--danger);
}

.filter-bar {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: 1.1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  box-shadow: var(--shadow-sm);
}
.filter-bar__left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
  min-width: 0;
}
.filter-bar label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-muted);
  white-space: nowrap;
}
.filter-bar select {
  min-width: 0;
  max-width: 100%;
  flex: 1 1 11rem;
}

/* ——— Tables ——— */
.table-panel {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  max-width: 100%;
  container-type: inline-size;
  container-name: panel;
}

/* Admin Settings: .table-wrap lives in .card (not .table-panel) — register same container for stacked layout */
.app-container--wide .card--table-host {
  container-type: inline-size;
  container-name: panel;
}
/* Wrapper: no horizontal scroll; admin tables stack on narrow viewports */
.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow: visible;
}

/* Employee "My Claims": no stacked mobile layout — same tabular view as desktop; scroll horizontally on narrow viewports if needed */
.table-wrap--employee-desktop {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.table-wrap--employee-desktop .data-table {
  table-layout: auto;
  min-width: 35rem;
  width: max(100%, 35rem);
}

.data-table {
  width: 100%;
  table-layout: auto;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.data-table th,
.data-table td {
  padding: 0.9rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--edge);
  vertical-align: top;
  min-width: 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: manual;
}
/* Don’t break button labels letter-by-letter when the column is narrow */
.data-table .btn {
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 3.75rem;
  max-width: 100%;
  word-break: normal;
  overflow-wrap: normal;
  box-sizing: border-box;
  margin: 0.15rem 0.45rem 0.15rem 0;
  font-size: 0.8125rem;
  padding: 0.5rem 0.85rem;
}
.data-table th {
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 0.69rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-faint);
  font-weight: 600;
  white-space: normal;
  border-bottom: 2px solid var(--edge-strong);
}
.data-table tbody tr {
  transition: background 0.15s;
}
.data-table tbody tr:hover {
  background: var(--brand-soft);
}
.data-table tr.is-clickable {
  cursor: pointer;
}
.data-table .cell-muted {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

/* Ledger numerals — amounts and IDs */
.data-table td.cell-num,
.data-table th.cell-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.data-table td.cell-num {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
}
.data-table td.cell-id {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--ink-muted);
}

/* Stacked cards when the table panel is too narrow (split panes, sidebars) — not viewport-only */
@container panel (max-width: 1280px) {
  .table-wrap:not(.table-wrap--employee-desktop) .data-table,
  .table-wrap:not(.table-wrap--employee-desktop) .data-table tbody,
  .table-wrap:not(.table-wrap--employee-desktop) .data-table thead,
  .table-wrap:not(.table-wrap--employee-desktop) .data-table tr,
  .table-wrap:not(.table-wrap--employee-desktop) .data-table th,
  .table-wrap:not(.table-wrap--employee-desktop) .data-table td {
    display: block;
  }
  .table-wrap:not(.table-wrap--employee-desktop) .data-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(100%);
  }
  .table-wrap:not(.table-wrap--employee-desktop) .data-table tr:not(.data-table__message) {
    border: 1px solid var(--edge);
    border-radius: 10px;
    margin-bottom: 0.75rem;
    padding: 0.35rem 0.9rem 0.6rem;
    background: var(--surface);
  }
  .table-wrap:not(.table-wrap--employee-desktop) .data-table tr.data-table__message {
    background: transparent;
    border: none;
  }
  .table-wrap:not(.table-wrap--employee-desktop) .data-table tr.data-table__message td {
    border: 0;
    text-align: center;
    padding: 2.5rem 1rem;
  }
  .table-wrap:not(.table-wrap--employee-desktop) .data-table tr:not(.data-table__message) td {
    border: 0;
    border-bottom: 1px solid var(--edge);
    padding: 0.5rem 0;
  }
  .table-wrap:not(.table-wrap--employee-desktop) .data-table tr:not(.data-table__message) td:last-of-type {
    border-bottom: 0;
  }
  /* Stacked cards read top-to-bottom — numerals go back to the left edge */
  .table-wrap:not(.table-wrap--employee-desktop) .data-table td.cell-num {
    text-align: left;
  }
  .table-wrap:not(.table-wrap--employee-desktop) .data-table tr:not(.data-table__message) td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-faint);
    font-weight: 700;
    margin-bottom: 0.2rem;
  }
  .table-wrap:not(.table-wrap--employee-desktop) .data-table tr.data-table__message td::before {
    display: none !important;
  }
  .table-wrap:not(.table-wrap--employee-desktop) .data-table td[data-label="Actions"] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.6rem;
  }
  .table-wrap:not(.table-wrap--employee-desktop) .data-table td[data-label="Actions"]::before {
    flex: 0 0 100%;
  }
}

/* ——— Status ——— */
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: capitalize;
  letter-spacing: 0.02em;
}
.status::before {
  content: "";
  width: 0.45em;
  height: 0.45em;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.status.draft {
  background: var(--draft-bg);
  color: var(--draft-text);
}
.status.submitted {
  background: var(--submitted-bg);
  color: var(--submitted-text);
}
.status.approved {
  background: var(--ok-bg);
  color: var(--ok-text);
}
.status.rejected {
  background: var(--bad-bg);
  color: var(--bad-text);
}

/* ——— Buttons ——— */
button,
.btn {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  transition: background 0.2s, transform 0.12s, box-shadow 0.2s;
}
button:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
button:disabled,
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn--primary,
.btn-primary {
  background: var(--brand);
  color: #fff;
}
.btn--primary:hover:not(:disabled),
.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
}

.btn--ghost {
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--edge-strong);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--brand-soft);
}

.btn--danger {
  background: var(--danger);
  color: #fff;
}
.btn--danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

/* Logout lives in the dark chrome band — quiet ghost until hovered */
.logout-btn {
  background: transparent;
  color: var(--chrome-faint);
  border: 1px solid var(--chrome-edge);
}
.logout-btn:hover:not(:disabled) {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.logout-btn:focus-visible {
  outline-color: var(--chrome-ink);
}

.btn--success {
  background: var(--success);
  color: #fff;
}
.btn--success:hover:not(:disabled) {
  background: var(--success-hover);
}

.w-full {
  width: 100%;
}

/* ——— Login primary ——— */
.btn-login {
  width: 100%;
  padding: 0.8rem;
  font-size: 1rem;
  margin-top: 0.25rem;
  background: var(--brand);
  color: #fff;
  border-radius: 8px;
  font-weight: 700;
}
.btn-login:hover:not(:disabled) {
  background: var(--brand-hover);
}

.error {
  color: var(--danger);
  text-align: center;
  margin-top: 1rem;
  font-size: var(--text-sm);
  font-weight: 600;
}

/* ——— Empty / loading ——— */
.empty-state,
.loading {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--ink-faint);
  font-size: var(--text-sm);
}

/* ——— Claim detail / receipt ——— */
.receipt-image {
  width: 100%;
  max-height: 400px;
  object-fit: contain;
  border: 1px solid var(--edge);
  border-radius: 8px;
  margin-top: 0.5rem;
  background: var(--surface-raised);
}
.receipt-pdf {
  width: 100%;
  height: 400px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  margin-top: 0.5rem;
  background: #f5f5f4;
}
.receipt-link {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--brand);
  color: #fff !important;
  text-decoration: none !important;
  border-radius: 8px;
  font-weight: 600;
  font-size: var(--text-sm);
}
.receipt-link:hover {
  background: var(--brand-hover);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}
.approve-btn {
  background: var(--success);
  color: #fff;
  padding: 0.7rem 1.25rem;
  font-size: 1rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-family: var(--font-ui);
}
.approve-btn:hover:not(:disabled) {
  background: var(--success-hover);
}
.reject-btn {
  background: var(--danger);
  color: #fff;
  padding: 0.7rem 1.25rem;
  font-size: 1rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-family: var(--font-ui);
}
.reject-btn:hover:not(:disabled) {
  background: var(--danger-hover);
}
.approve-btn:disabled,
.reject-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

textarea {
  min-height: 5rem;
  resize: vertical;
}

.ai-data {
  background: var(--surface-raised);
  border: 1px solid var(--edge);
  padding: 1rem;
  border-radius: 8px;
  margin-top: 0.5rem;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: 100%;
  overflow-x: hidden;
  line-height: 1.45;
  color: var(--ink-muted);
}

/* ——— WhatsApp connect page ——— */
.whatsapp-hero {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
}
.wa-card {
  width: 100%;
  max-width: 32rem;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 16px;
  padding: 2.25rem 1.75rem;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: rise 0.55s ease-out;
}
.wa-card h1 {
  font-size: 1.55rem;
  color: var(--brand);
  margin-bottom: 0.35rem;
}
.wa-card .subtitle {
  color: var(--ink-muted);
  font-size: var(--text-sm);
  margin-bottom: 1.5rem;
}
.wa-status {
  padding: 0.65rem 1rem;
  border-radius: 8px;
  margin-bottom: 1.25rem;
  font-weight: 600;
  font-size: var(--text-sm);
}
.wa-status.connected {
  background: var(--ok-bg);
  color: var(--ok-text);
  border: 1px solid rgba(21, 128, 61, 0.25);
}
.wa-status.connecting {
  background: #fff8e6;
  color: var(--warning-text);
  border: 1px solid rgba(124, 74, 12, 0.2);
}
.wa-status.waiting-for-scan {
  background: #e3f2fd;
  color: #0d47a1;
  border: 1px solid rgba(13, 71, 161, 0.2);
}
.wa-status.disconnected {
  background: var(--bad-bg);
  color: var(--bad-text);
  border: 1px solid rgba(185, 28, 28, 0.2);
}
.qr-container {
  background: var(--surface-raised);
  border: 1px dashed var(--edge-strong);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  margin-bottom: 1.25rem;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.qr-container img {
  max-width: 280px;
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--edge);
}
.qr-placeholder {
  color: var(--ink-faint);
  font-size: var(--text-sm);
}
.wa-instructions {
  text-align: left;
  background: var(--surface-raised);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  margin-bottom: 1.1rem;
}
.wa-instructions h3 {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
  margin-bottom: 0.5rem;
  font-weight: 700;
}
.wa-instructions ol {
  margin-left: 1.1rem;
  color: var(--ink-muted);
  font-size: var(--text-sm);
  line-height: 1.7;
}
.wa-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}
.wa-btn {
  padding: 0.55rem 1.1rem;
  font-size: var(--text-sm);
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-family: var(--font-ui);
  transition: background 0.2s, transform 0.1s;
}
.wa-btn--primary {
  background: var(--brand);
  color: #fff;
}
.wa-btn--primary:hover {
  background: var(--brand-hover);
}
.wa-btn--danger {
  background: var(--danger);
  color: #fff;
}
.wa-btn--danger:hover {
  background: var(--danger-hover);
}
.wa-btn--muted {
  background: var(--surface-raised);
  color: var(--ink);
  border: 1px solid var(--edge-strong);
}
.wa-btn--muted:hover {
  background: var(--edge);
}
.connected-icon {
  font-size: 3.25rem;
  line-height: 1;
  color: var(--success);
  margin-bottom: 0.35rem;
}
.spinner {
  border: 3px solid var(--edge);
  border-top-color: var(--brand);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: wa-spin 0.85s linear infinite;
  margin: 0 auto 0.5rem;
}
@keyframes wa-spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ——— Settings: tabs, toggle, modal ——— */
.tab-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.tab {
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 8px;
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-muted);
  font-family: var(--font-ui);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.tab:hover {
  background: var(--surface-raised);
  border-color: var(--edge-strong);
}
.tab.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
  animation: rise 0.35s ease-out;
}
.toggle {
  width: 48px;
  height: 26px;
  background: #ccc;
  border-radius: 13px;
  position: relative;
  cursor: pointer;
  transition: background 0.3s;
  flex-shrink: 0;
}
.toggle.enabled {
  background: var(--success);
}
.toggle::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.3s;
  box-shadow: var(--shadow-sm);
}
.toggle.enabled::after {
  transform: translateX(22px);
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0.5rem;
  max-height: 18rem;
  overflow-y: auto;
  padding: 0.25rem;
}
.permission-option {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.65rem;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--surface-raised);
}
.permission-option input {
  width: auto;
  margin-top: 0.15rem;
  flex-shrink: 0;
}
.permission-option__key {
  display: block;
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.permission-option__desc {
  display: block;
  color: var(--ink-faint);
  font-size: var(--text-xs);
  line-height: 1.35;
  margin-top: 0.15rem;
}
.permission-summary {
  color: var(--ink-muted);
  font-size: var(--text-sm);
  line-height: 1.4;
  max-width: 28rem;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  padding-top: max(1.25rem, env(safe-area-inset-top));
  overflow-y: auto;
}
.modal.active {
  display: flex;
  animation: fadeIn 0.2s ease-out;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 16, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.modal-content {
  position: relative;
  background: var(--surface);
  width: 100%;
  max-width: 34rem;
  max-height: 90dvh;
  padding: 0;
  border-radius: 16px;
  border: 1px solid var(--edge);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: modalSlide 0.3s ease-out;
}
.modal-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem 1.75rem 1.25rem;
  border-bottom: 1px solid var(--edge);
  background: linear-gradient(135deg, var(--brand) 0%, #0a3834 100%);
  border-radius: 16px 16px 0 0;
}
.modal-header__icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.modal-header__text {
  flex: 1;
  min-width: 0;
}
.modal-header h3 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 0.25rem 0;
  border: 0;
  padding: 0;
  color: #fff;
}
.modal-header__subtitle {
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.85);
  margin: 0;
}
.modal-header .close-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.9);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  line-height: 0;
  padding: 0;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.modal-header .close-btn svg {
  display: block;
}
.modal-header .close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.25);
  color: #fff;
}
.modal-content form {
  padding: 1.75rem;
}
.modal-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 0;
}
.modal-form-grid .form-group {
  margin-bottom: 0;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--edge);
}
.modal .btn {
  min-width: 7rem;
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes modalSlide {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
@media (max-width: 600px) {
  .modal-form-grid {
    grid-template-columns: 1fr;
  }
  .modal-header {
    padding: 1.25rem 1.5rem 1rem;
  }
  .modal-content form {
    padding: 1.5rem;
  }
  .modal-actions {
    flex-direction: column;
  }
  .modal .btn {
    width: 100%;
  }
}

/* ——— Danger Modal Variant ——— */
.modal-content--danger {
  border-color: rgba(185, 28, 28, 0.3);
}

.modal-header--danger {
  background: linear-gradient(135deg, var(--danger) 0%, #991b1b 100%);
}

.modal-header__icon--danger {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

.modal-body {
  padding: 1.5rem 1.75rem;
  color: var(--ink);
  font-size: var(--text-sm);
  line-height: 1.5;
}

/* FAQ edit dialog */
#faqModal .modal-content {
  max-width: 32rem;
  border-radius: 12px;
  border-color: #d7cfc2;
  background: #fffdfa;
  box-shadow: 0 24px 70px rgba(18, 22, 24, 0.22);
  overflow: hidden;
}

#faqModal .modal-content::before {
  content: "";
  display: block;
  height: 5px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}

#faqModal .modal-header {
  padding: 1.3rem 1.45rem 1.1rem;
  background: #fffdfa;
  border-bottom: 1px solid #e6ded3;
  border-radius: 0;
  color: var(--ink);
}

#faqModal .modal-header__icon {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 8px;
  color: var(--brand);
  background: var(--brand-soft);
  border-color: rgba(15, 77, 72, 0.2);
}

#faqModal .modal-header h3 {
  color: var(--ink);
  font-size: 1.2rem;
  margin-bottom: 0.15rem;
}

#faqModal .modal-header__subtitle {
  color: var(--ink-muted);
  font-size: 0.86rem;
}

#faqModal .modal-header .close-btn {
  width: 2.35rem;
  height: 2.35rem;
  color: var(--ink-muted);
  background: var(--surface-raised);
  border: 1px solid #d8cfc3;
}

#faqModal .modal-header .close-btn:hover {
  color: var(--ink);
  background: #eee8df;
  border-color: #c9beae;
}

#faqModal .modal-content form {
  padding: 1.45rem;
}

#faqModal .form-group {
  margin-bottom: 1rem;
}

#faqModal .form-group label {
  color: var(--ink);
  font-size: 0.82rem;
  margin-bottom: 0.45rem;
}

#faqModal input,
#faqModal textarea {
  background: #fbfaf7;
  border-color: #d8cfc3;
  border-radius: 7px;
  padding: 0.78rem 0.85rem;
}

#faqModal textarea {
  min-height: 7rem;
}

#faqModal .modal-actions {
  margin-top: 1.25rem;
  padding: 1.1rem 0 0;
  border-top-color: #e6ded3;
}

/* ——— Back link in the dark chrome band ——— */
.back-btn {
  display: inline-flex;
  align-items: center;
  background: transparent;
  color: var(--chrome-ink) !important;
  text-decoration: none !important;
  padding: 0.5rem 1rem;
  border-radius: 7px;
  font-size: var(--text-sm);
  font-weight: 600;
  border: 1px solid var(--chrome-edge);
  cursor: pointer;
  font-family: var(--font-ui);
  transition: background 0.2s, border-color 0.2s;
}
.back-btn:hover {
  background: var(--chrome-raised);
  border-color: var(--chrome-faint);
}
.back-btn:focus-visible {
  outline: 2px solid var(--chrome-ink);
  outline-offset: 2px;
}

/* ——— Responsive ——— */
@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    text-align: center;
  }
  .app-header__brand {
    justify-content: center;
  }
  .app-nav {
    justify-content: center;
  }
  .stat-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .app-container {
    padding: 1rem 0.9rem 2rem;
  }
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-bar__left {
    width: 100%;
  }
  .filter-bar select {
    flex: none;
    max-width: none;
  }
  .data-table.employee-table th,
  .data-table.employee-table td {
    padding: 0.65rem 0.5rem;
    font-size: 0.8125rem;
  }
  .export-wide {
    width: 100%;
  }
  .actions {
    flex-direction: column;
  }
  .actions .approve-btn,
  .actions .reject-btn {
    width: 100%;
  }
  .receipt-image,
  .receipt-pdf {
    max-height: min(50vh, 280px);
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .tab-strip {
    flex-wrap: wrap;
    justify-content: center;
  }
  .tab {
    flex: 1 1 auto;
    min-width: min(100%, 8rem);
  }
  .wa-actions {
    flex-direction: column;
  }
  .wa-actions .wa-btn {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .auth-card {
    padding: 1.75rem 1.25rem;
  }
}

/* ——— Toast notifications ——— */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-top: max(1rem, env(safe-area-inset-top));
}

.toast {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  min-width: 280px;
  max-width: 400px;
  animation: slideIn 0.3s ease-out;
}

.toast.success {
  border-left: 4px solid var(--success);
}

.toast.error {
  border-left: 4px solid var(--danger);
}

.toast.info {
  border-left: 4px solid var(--brand);
}

.toast-icon {
  flex-shrink: 0;
  font-size: 1.25rem;
  line-height: 1;
}

.toast.success .toast-icon {
  color: var(--success);
}

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

.toast.info .toast-icon {
  color: var(--brand);
}

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

.toast-message {
  font-size: var(--text-sm);
  color: var(--ink);
  line-height: 1.4;
  word-wrap: break-word;
}

.toast-close {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--ink-faint);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.toast-close:hover {
  background: var(--surface-raised);
  color: var(--ink);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

@media (max-width: 768px) {
  .toast-container {
    left: 1rem;
    right: 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
  }

  .toast {
    min-width: auto;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ——— Knowledge Base ——— */
.kb-hero {
  background: #f8f4ec;
  border: 1px solid #d8cdbd;
  border-left: 6px solid var(--brand);
  border-radius: 10px;
  padding: 1.4rem 1.5rem;
  margin-bottom: 1.25rem;
  color: #fff;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  box-shadow: var(--shadow-sm);
  animation: rise 0.5s ease-out;
}

.kb-hero__content {
  flex: 1;
  min-width: 0;
}

.kb-hero__title {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
  margin: 0 0 0.35rem 0;
  color: var(--brand);
  border: 0;
  padding: 0;
}

.kb-hero__subtitle {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  margin: 0;
  line-height: 1.5;
}

.kb-hero__stats {
  display: flex;
  gap: 0.75rem;
  flex-shrink: 0;
}

.kb-stat {
  min-width: 6.25rem;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
}

.kb-stat__value {
  display: block;
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  margin-bottom: 0.25rem;
}

.kb-stat__label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  font-weight: 600;
}

.kb-workbench {
  display: grid;
  grid-template-columns: minmax(20rem, 1.2fr) minmax(16rem, 0.9fr) minmax(16rem, 0.9fr);
  gap: 1.25rem;
  margin-bottom: 1.5rem;
  animation: rise 0.5s ease-out 0.1s both;
  align-items: stretch;
}

.kb-panel,
.kb-test-card,
.kb-maintenance-card {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.kb-panel--faq {
  border-color: rgba(15, 77, 72, 0.26);
  box-shadow: 0 10px 26px rgba(15, 77, 72, 0.08);
}

.kb-panel__header {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.kb-panel__icon {
  width: 2.5rem;
  height: 2.5rem;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
  background: var(--brand-soft);
  border: 1px solid rgba(15, 77, 72, 0.18);
  border-radius: 8px;
}

.kb-panel__title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
  color: var(--ink);
}

.kb-panel__desc {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  margin: 0;
  line-height: 1.4;
}

.kb-panel__form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.kb-panel__form .form-group {
  margin-bottom: 0;
}

.kb-panel__form input,
.kb-panel__form textarea {
  font-size: var(--text-sm);
  padding: 0.65rem 0.75rem;
}

.kb-panel__form textarea {
  min-height: 6rem;
  resize: vertical;
}

.btn--full {
  width: 100%;
}

.kb-lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 0.35fr);
  gap: 1.25rem;
  margin-bottom: 1.5rem;
  animation: rise 0.5s ease-out 0.16s both;
}

.kb-maintenance-card {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  justify-content: space-between;
}

.kb-maintenance-card .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.kb-source-title {
  font-weight: 700;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.kb-type-pill {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-pill);
  padding: 0.25rem 0.65rem;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: capitalize;
  background: var(--surface-raised);
  color: var(--ink-muted);
  border: 1px solid var(--edge);
}

.kb-type-pill--faq {
  background: var(--brand-soft);
  color: var(--brand);
  border-color: rgba(15, 77, 72, 0.18);
}

.kb-type-pill--document {
  background: #fff4e6;
  color: var(--warning-text);
  border-color: rgba(124, 74, 12, 0.18);
}

.kb-file-input {
  display: block;
  position: relative;
}

.kb-file-input input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.kb-file-input__text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  background: var(--surface-raised);
  border: 1px solid var(--edge);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  text-align: center;
}

.kb-file-input__text:hover {
  border-color: var(--edge-strong);
  background: var(--edge);
}

.kb-file-input input[type="file"]:focus + .kb-file-input__text {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.kb-file-input input[type="file"]:valid + .kb-file-input__text {
  color: var(--ink);
  border-color: var(--brand);
}

.kb-test-card__header {
  margin-bottom: 1.25rem;
}

.kb-test-card__title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 0.35rem 0;
  color: var(--ink);
}

.kb-test-card__desc {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  margin: 0;
}

.kb-test-card__form {
  margin-bottom: 0;
}

.kb-test-input-group {
  display: flex;
  gap: 0.75rem;
}

.kb-test-input-group input {
  flex: 1;
  min-width: 0;
}

.kb-test-input-group .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.kb-test-answer {
  margin-top: 1rem;
  padding: 1rem;
  background: #f8f4ec;
  border: 1px solid #d8cdbd;
  border-radius: 8px;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--ink);
  animation: rise 0.3s ease-out;
}

.kb-sources-section {
  animation: rise 0.5s ease-out 0.22s both;
}

.kb-sources-card {
  margin-bottom: 0;
}

.kb-sources-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--edge);
}

.kb-sources-header h2 {
  border: 0;
  padding: 0;
  margin: 0;
}

.kb-sources-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.kb-sources-table th,
.kb-sources-table td {
  vertical-align: middle;
}

.kb-sources-table th:first-child,
.kb-sources-table td:first-child {
  width: 40%;
}

.kb-sources-table th:nth-child(2),
.kb-sources-table td:nth-child(2) {
  width: 15%;
}

.kb-sources-table th:nth-child(3),
.kb-sources-table td:nth-child(3) {
  width: 10%;
}

.kb-sources-table th:nth-child(4),
.kb-sources-table td:nth-child(4) {
  width: 20%;
}

.kb-sources-table th:nth-child(5),
.kb-sources-table td:nth-child(5) {
  width: 15%;
}

@media (max-width: 1024px) {
  .kb-workbench,
  .kb-lower-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .kb-hero {
    flex-direction: column;
    align-items: stretch;
    padding: 1.5rem;
  }

  .kb-hero__stats {
    width: 100%;
    justify-content: space-around;
    gap: 1rem;
  }

  .kb-test-input-group {
    flex-direction: column;
  }

  .kb-test-input-group .btn {
    width: 100%;
  }

  .kb-sources-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
