:root {
  color-scheme: light;
  --bg: #efebe4;
  --surface: #ffffff;
  --surface-subtle: #f8f5f0;
  --text: #111111;
  --muted: #6d6861;
  --line: #d9d0c3;
  --accent: #d90000;
  --accent-strong: #a80000;
  --gunmetal: #3e4347;
  --ivory: #ddd2c3;
  --danger: #a83d3d;
  --success: #2f6b46;
  --warning: #9a6418;
  --shadow: 0 18px 44px rgba(17, 17, 17, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #f7f4ef 0%, var(--bg) 56%, #e8e1d7 100%);
  color: var(--text);
  font-family: Aptos, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar,
.panel-header,
.report-main,
.report-title-line,
.manager-actions,
.user-card,
.admin-area {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--text);
  padding-bottom: 18px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.1rem);
  line-height: 1;
  font-weight: 800;
}

h2 {
  font-size: 1.05rem;
}

h3 {
  font-size: 1rem;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.brand-wordmark {
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  margin-bottom: 8px;
}

.role-switcher {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 4px;
  box-shadow: var(--shadow);
}

.user-card {
  justify-content: space-between;
  gap: 14px;
  min-width: min(100%, 340px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--text);
  color: white;
  padding: 10px;
  box-shadow: var(--shadow);
}

.user-card span,
.employee-profile strong,
.person-row strong {
  display: block;
  font-weight: 800;
}

.user-card small,
.employee-profile span,
.person-row span {
  color: var(--muted);
}

.user-card small {
  color: var(--ivory);
}

.loading-view {
  display: grid;
  min-height: 60vh;
  place-items: center;
}

.loading-brand {
  text-align: center;
  display: grid;
  gap: 10px;
  justify-items: center;
}

.loading-brand h1 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
}

.loading-spinner {
  margin-top: 24px;
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.login-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 48px;
  min-height: 62vh;
  align-items: center;
  padding: 32px 0;
}

@media (max-width: 680px) {
  .login-view {
    grid-template-columns: 1fr;
    gap: 24px;
    min-height: unset;
  }
  .login-brand {
    display: none;
  }
}

.login-brand {
  display: grid;
  gap: 16px;
  padding: 40px;
  background: var(--text);
  border-radius: 12px;
  color: white;
  min-height: 340px;
  align-content: center;
}

.login-brand .brand-wordmark {
  color: var(--accent);
}

.login-brand h1 {
  font-size: clamp(2.4rem, 4vw, 3.4rem);
  line-height: 1;
  color: white;
}

.login-brand-tagline {
  color: var(--ivory);
  font-size: 1rem;
  line-height: 1.6;
  margin-top: 8px;
}

.login-panel {
  display: grid;
  gap: 20px;
  width: 100%;
  max-width: 460px;
}

.sso-login-wrapper {
  display: grid;
  gap: 28px;
}

.sso-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 auto;
  width: fit-content;
}

.role-button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
}

.role-button.active {
  background: var(--accent);
  color: white;
}

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

.metric,
.panel,
.report-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  border-top: 4px solid var(--accent);
  padding: 18px;
}

.metric span,
.muted {
  color: var(--muted);
}

.metric strong {
  display: block;
  font-size: 1.45rem;
  margin-top: 8px;
}

.metric.metric-actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  border-top-color: var(--line);
}

.layout {
  display: grid;
  grid-template-columns: 0.95fr 1.25fr;
  gap: 18px;
  align-items: start;
}

.panel {
  padding: 20px;
}

.panel-header {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.expense-form,
.report-list,
.limits-editor,
.airfare-editor,
.people-editor {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-subtle);
  color: var(--text);
  min-height: 42px;
  padding: 10px 12px;
}

input[readonly] {
  color: var(--muted);
  background: #eee8df;
}

textarea {
  resize: vertical;
}

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

.form-actions {
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) minmax(180px, 1fr);
  gap: 10px;
}

.primary-action,
.secondary-action,
.manager-actions button {
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 750;
  min-height: 42px;
  padding: 0 15px;
}

.primary-action {
  background: var(--accent);
  color: white;
  box-shadow: 0 10px 24px rgba(217, 0, 0, 0.18);
}

.primary-action:hover {
  background: var(--accent-strong);
}

.secondary-action,
.manager-actions button {
  background: var(--surface-subtle);
  color: var(--text);
  border: 1px solid var(--line);
}

.limit-hint {
  min-height: 36px;
  border-radius: 7px;
  padding: 10px 12px;
  color: var(--muted);
  background: #f5eee8;
}

.time-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-subtle);
  padding: 14px;
}

.time-rows {
  display: grid;
  gap: 8px;
}

.time-grid {
  display: grid;
  grid-template-columns: minmax(118px, 1fr) repeat(4, minmax(84px, 0.7fr)) minmax(54px, 0.45fr) minmax(62px, 0.45fr) minmax(130px, 1fr);
  gap: 8px;
  align-items: center;
}

.time-grid-head {
  color: var(--muted);
  font-size: 0.78rem;
}

.time-grid span {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  font-weight: 750;
}

.time-totals,
.time-summary,
.time-review {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.time-review {
  flex-basis: 100%;
  width: 100%;
}

.time-totals div,
.time-summary span {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  padding: 8px 10px;
}

.time-review-grid {
  display: grid;
  grid-template-columns: 90px 58px 58px 68px 72px 62px 72px minmax(104px, auto) minmax(110px, 1fr) auto;
  gap: 8px;
  align-items: center;
  flex-basis: 100%;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-subtle);
  padding: 10px;
}

.time-review-head {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  padding-bottom: 0;
}

.time-totals span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.employee-profile {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-subtle);
  padding: 12px;
}

.manual-employee {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-subtle);
  display: grid;
  gap: 12px;
  padding: 12px;
}

.line-editor {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-subtle);
  padding: 14px;
}

.panel-header.compact {
  margin-bottom: 0;
}

.limit-hint.over {
  background: #fff2ee;
  color: var(--danger);
}

.form-error {
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 700;
}

.report-card {
  padding: 16px;
}

.report-main {
  justify-content: space-between;
  gap: 14px;
}

.report-title-line {
  flex-wrap: wrap;
  gap: 8px;
}

.status-pill,
.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 750;
  min-height: 24px;
  padding: 0 9px;
}

.status-pill.pending {
  background: #fff1d8;
  color: var(--warning);
}

.status-pill.approved {
  background: #e7f5e9;
  color: var(--success);
}

.status-pill.approved,
.status-pill.reimbursed {
  background: #e7f5e9;
  color: var(--success);
}

.status-pill.rejected,
.tag.over {
  background: #fae7e4;
  color: var(--danger);
}

.status-pill.draft {
  background: #f0e8de;
  color: var(--gunmetal);
}

.tag.ok {
  background: #e7f5e9;
  color: var(--success);
}

.tag {
  background: #f0e8de;
}

.report-meta,
.report-details {
  color: var(--muted);
  font-size: 0.9rem;
}

.report-meta {
  margin-top: 6px;
}

.report-amount {
  white-space: nowrap;
}

.report-details {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.item-list {
  display: grid;
  gap: 8px;
  flex-basis: 100%;
  width: 100%;
  margin-top: 8px;
}

.item-row {
  display: grid;
  grid-template-columns: 90px minmax(100px, 1fr) 90px minmax(130px, 1.2fr) minmax(120px, 1.5fr) auto auto auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-subtle);
  padding: 10px;
  color: var(--muted);
}

.item-row strong {
  color: var(--text);
}

.item-list.draft .item-row {
  grid-template-columns: 90px minmax(100px, 1fr) 90px minmax(120px, 1.2fr) minmax(120px, 1fr) auto auto;
}

.item-list.draft .item-row.editing {
  border-color: var(--perazzi-red);
  box-shadow: 0 0 0 2px rgba(217, 0, 0, 0.08);
}

.inline-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.over-text {
  color: var(--danger);
  font-weight: 750;
}

.mini-action {
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 34px;
  padding: 0 10px;
  background: #f0e8de;
  color: var(--text);
  cursor: pointer;
}

.receipt-preview {
  margin-top: 12px;
}

.receipt-preview img {
  width: 100%;
  max-height: 210px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.receipt-link {
  color: var(--accent);
  font-weight: 750;
  text-decoration: none;
}

.manager-actions {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.admin-area {
  align-items: stretch;
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 18px;
  margin-top: 18px;
}

.limit-row {
  display: grid;
  grid-template-columns: 160px repeat(8, minmax(76px, 1fr));
  gap: 10px;
  align-items: end;
}

.meal-limit-row {
  display: grid;
  grid-template-columns: 160px repeat(3, minmax(90px, 1fr));
  gap: 10px;
  align-items: end;
}

.limit-note {
  color: var(--muted);
  font-weight: 800;
  margin-top: 8px;
}

.limit-row strong {
  padding-bottom: 12px;
}

.person-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(150px, 200px) minmax(110px, 140px) minmax(130px, 190px) auto auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.person-row.person-disabled {
  opacity: 0.5;
}

.person-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.person-email-input {
  font-size: 0.78rem;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-subtle);
  color: var(--text);
  width: 100%;
  min-width: 0;
}

.person-enabled-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.82rem;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.person-delete-btn {
  font-size: 0.8rem;
  padding: 4px 10px;
  white-space: nowrap;
}

.danger-action {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 6px 14px;
  transition: background 0.15s, color 0.15s;
}

.danger-action:hover {
  background: var(--danger);
  color: #fff;
}

.add-user-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  background: var(--surface-subtle);
}

.add-user-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.add-user-actions {
  display: flex;
  gap: 10px;
}

.airfare-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 110px minmax(140px, 180px) minmax(90px, 120px);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-subtle);
}

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

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
}

.compact-empty {
  padding: 14px;
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .topbar,
  .layout,
  .admin-area,
  .summary-grid,
  .form-row,
  .form-actions,
  .employee-profile,
  .add-user-fields,
  .person-row,
  .airfare-row,
  .time-grid,
  .time-review-grid,
  .item-row,
  .meal-limit-row,
  .limit-row {
    grid-template-columns: 1fr;
  }

  .time-grid-head {
    display: none;
  }

  .time-review-head {
    display: none;
  }

  .topbar {
    display: grid;
  }

  .role-switcher {
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .panel,
  .metric,
  .report-card {
    padding: 14px;
  }

  .panel-header,
  .report-main {
    align-items: stretch;
    display: grid;
  }
}
