:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #f7f8fa;
  --line: #d6dce3;
  --line-strong: #b6c0cb;
  --text: #13212f;
  --muted: #637487;
  --accent: #1f4f7a;
  --accent-strong: #173c5c;
  --success-bg: #ecf8ef;
  --success-text: #206437;
  --error-bg: #fff1f1;
  --error-text: #9d2b2b;
  --warning-bg: #fff8e6;
  --warning-text: #8a6400;
  --included-bg: #edf7ff;
  --included-text: #1c587c;
  --excluded-bg: #f1f3f5;
  --excluded-text: #546274;
  --voided-bg: #fff0f0;
  --voided-text: #8f3030;
  --shadow: 0 8px 20px rgba(19, 33, 47, 0.06);
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: #f4f5f7;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

body.calculator-open {
  overflow: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select {
  font: inherit;
}

.page-shell {
  max-width: 1500px;
  margin: 0 auto;
  padding: 14px 16px 22px;
}

.page-content {
  display: grid;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.login-topbar {
  justify-content: center;
  padding-top: 18px;
}

.brand-block {
  display: grid;
  gap: 4px;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand-block h1,
.panel-header h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.08;
  letter-spacing: -0.02em;
}

.section-eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.page-note,
.panel-note,
.form-hint,
.login-help,
.empty-state {
  color: var(--muted);
  font-size: 12px;
}

.panel-copy {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.button.tip-rules-button {
  min-height: 32px;
  padding: 0 13px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 800;
  border-color: #ff9a14;
  background: #ffb020;
  color: #ffffff;
  box-shadow: 0 0 0 1px rgba(255, 154, 20, 0.2), 0 0 16px rgba(255, 176, 32, 0.34);
}

.button.tip-rules-button:hover,
.button.tip-rules-button:focus-visible,
.button.tip-rules-button:active {
  border-color: #f08b00;
  background: #ff9900;
  color: #ffffff;
}

.header-actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  transform: translateX(-20px);
}

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

.flat-panel {
  box-shadow: none;
}

.narrow-panel {
  width: min(460px, 100%);
  margin: 18px auto 0;
}

.login-panel {
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 0;
}

.compact-header {
  align-items: end;
}

.panel-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.panel-meta span {
  border: 1px solid var(--line);
  background: var(--surface-alt);
  padding: 4px 8px;
  border-radius: 999px;
}

.tip-table-meta-row {
  display: flex;
  justify-content: flex-start;
  padding: 0 12px 2px;
}

.tip-table-meta {
  justify-content: flex-start;
}

.sheet-form,
.login-form {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.inline-form {
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
}

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

.toolbar-row {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
}

.compact-field {
  min-width: 190px;
}

.grow-field {
  flex: 1 1 280px;
}

.field {
  display: grid;
  gap: 4px;
}

.field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.field input,
.field select,
.table-input,
.table-select {
  width: 100%;
  min-height: 28px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
}

.field input:focus,
.field select:focus,
.table-input:focus,
.table-select:focus {
  outline: 2px solid rgba(31, 79, 122, 0.12);
  border-color: var(--accent);
}

.table-input,
.table-select {
  min-height: 22px;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 10px;
}

.eligible-select.eligible-yes {
  color: #9d2b2b;
  font-weight: 700;
}

.pin-input-row {
  display: flex;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.summary-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.summary-row span {
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-alt);
}

.dense-summary {
  margin-top: 2px;
  width: 100%;
  justify-content: flex-start;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.12s ease, border-color 0.12s ease;
  font-size: 12px;
  font-weight: 600;
}

.button:hover,
.button:focus-visible {
  border-color: var(--accent);
  background: #f6f9fc;
  text-decoration: none;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.button.primary:hover,
.button.primary:focus-visible {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.button.subtle {
  background: var(--surface-alt);
}

.button.ghost {
  background: transparent;
}

.button.danger {
  background: #9d2b2b;
  border-color: #9d2b2b;
  color: #fff;
}

.button.danger:hover,
.button.danger:focus-visible {
  background: #7f1f1f;
  border-color: #7f1f1f;
}

.button.wide {
  width: 100%;
}

.calc-launch-button {
  min-width: 108px;
}

.calc-launch-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 12px;
}

.compact-dashboard {
  align-items: start;
}

.single-wide {
  grid-template-columns: 1fr;
}

.bottom-grid {
  align-items: start;
}

.reports-stack {
  grid-template-columns: 1fr;
}

.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.login-flash-stack {
  padding: 0 12px;
  margin: 0 0 4px;
}

.flash {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 12px;
}

.flash-success {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: #b6e4c2;
}

.flash-error {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: #f0c8c8;
}

.sheet-table-wrapper {
  overflow: auto;
  border-top: 1px solid var(--line);
}

.compact-table {
  max-height: 300px;
}

.reports-compact-table {
  max-height: 260px;
}

.sheet-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 740px;
}

.sheet-table thead th {
  position: sticky;
  top: 0;
  background: #f0f2f5;
  z-index: 1;
  color: #294058;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sortable-header {
  cursor: ns-resize;
  user-select: none;
  position: sticky;
}

.sortable-header::after {
  content: "";
  display: inline-block;
  min-width: 10px;
  margin-left: 5px;
  text-align: center;
  line-height: 1;
  vertical-align: middle;
}

.sortable-header.is-sorted-asc::after {
  content: "▲";
  color: var(--accent);
}

.sortable-header.is-sorted-desc::after {
  content: "▼";
  color: var(--accent);
}

.sheet-table th,
.sheet-table td {
  padding: 2px 3px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: left;
  font-size: 11px;
  vertical-align: middle;
  white-space: nowrap;
  line-height: 1.16;
}

.sheet-table th:first-child,
.sheet-table td:first-child {
  border-left: 1px solid var(--line);
}

.sheet-table tbody tr:nth-child(even) td {
  background: #fcfdfe;
}

.sheet-table tbody tr:hover td {
  background: #f7fbff;
}

.sheet-table tbody tr.is-selected td {
  background: #eef6ff;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
  padding: 12px 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 700;
}

.status-ready,
.status-finalized {
  background: var(--included-bg);
  color: var(--included-text);
}

.status-included {
  background: #e9f8ed;
  color: #237246;
}

.status-excluded {
  background: var(--excluded-bg);
  color: var(--excluded-text);
}

.status-voided {
  background: var(--voided-bg);
  color: var(--voided-text);
}

.actions-cell {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.mini-button {
  min-height: 22px;
  padding: 0 7px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
}

.sheet-mini-title {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.summary-card-grid {
  padding-left: 0;
  padding-right: 0;
}

.stat-card {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-alt);
}

.stat-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.stat-card strong {
  font-size: 18px;
  line-height: 1.1;
}

.split-tables {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 12px 12px;
}

.stats-filter-form {
  padding-bottom: 0;
}

.pin-menu {
  position: relative;
}

.pin-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 300px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
  z-index: 50;
}

.pin-menu-panel[hidden] {
  display: none;
}

.pin-menu-title {
  margin-bottom: 8px;
}

.pin-popup-form {
  display: grid;
  gap: 8px;
}

.calculator-modal[hidden] {
  display: none;
}

.calculator-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
}

.calculator-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 23, 35, 0.46);
}

.calculator-dialog {
  position: relative;
  width: min(380px, calc(100vw - 28px));
  margin: 70px auto 0;
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 42px rgba(10, 20, 30, 0.24);
  padding: 14px;
}

.time-pin-dialog {
  width: min(360px, calc(100vw - 28px));
  margin-top: 90px;
}

.tip-rules-dialog {
  width: min(980px, calc(100vw - 28px));
  margin-top: 38px;
}

.tip-rules-toolbar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0 0;
}

.download-csv-button {
  min-height: 36px;
  padding: 0 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 800;
  background: #1d76ff;
  border-color: #1d76ff;
  box-shadow: 0 0 0 1px rgba(29, 118, 255, 0.14), 0 0 14px rgba(29, 118, 255, 0.2);
}

.download-csv-button:hover,
.download-csv-button:focus-visible {
  background: #0e63e6;
  border-color: #0e63e6;
}

.tip-rules-upload-form {
  display: flex;
  margin-left: auto;
}

.tip-rules-upload-panel {
  display: grid;
  justify-items: end;
  gap: 5px;
}

.tip-rules-upload-title {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tip-rules-upload-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.upload-submit-button {
  min-width: 82px;
}

.file-picker-button {
  min-width: 104px;
}

.tip-rules-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.tip-rules-file-name {
  min-width: 170px;
  max-width: 230px;
  padding: 6px 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tip-rules-table-wrapper {
  max-height: 420px;
}

.calculator-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.calculator-title {
  font-size: 18px;
  font-weight: 700;
}

.calculator-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.calculator-screen {
  margin: 12px 0;
  padding: 12px;
  background: #f5f8fb;
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 84px;
  display: grid;
  gap: 8px;
  align-items: end;
}

.calculator-expression {
  color: var(--muted);
  font-size: 13px;
  word-break: break-all;
}

.calculator-result {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.05;
  word-break: break-all;
}

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

.calculator-key {
  min-height: 46px;
  font-size: 16px;
}

.calculator-zero {
  grid-column: span 2;
}

.calculator-equals {
  grid-row: span 2;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.login-screen .page-shell {
  width: min(680px, 100%);
  padding-top: 36px;
}

.login-help {
  padding: 0 12px 12px;
}

.empty-state {
  padding: 0 12px 12px;
}

.workflow-panel {
  border-style: dashed;
}

.workflow-bar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 10px 12px;
  flex-wrap: wrap;
}

.workflow-steps {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.workflow-follow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.workflow-step {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.workflow-text {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.dense-sheet {
  min-width: 0;
}

.finalize-inline-form {
  border-top: 1px solid var(--line);
}

.finalize-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.finalize-strip .dense-summary {
  justify-content: flex-start;
}

.save-report-button {
  min-width: 110px;
}

.compact-hint {
  line-height: 1.35;
}

.fetch-form {
  gap: 6px;
}

.fetch-controls-row {
  display: flex;
  align-items: end;
  gap: 6px;
  flex-wrap: wrap;
}

.fetch-date-field {
  width: 132px;
}

.fetch-pin-field {
  width: 118px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.fetch-actions {
  gap: 6px;
}

.fetch-actions .button {
  min-width: 64px;
}

.compact-toolbar-row {
  gap: 6px;
}

.total-tip-field {
  min-width: 124px;
  max-width: 150px;
}

.fixed-sheet {
  width: max-content;
  min-width: 0;
  table-layout: fixed;
}

.fixed-sheet .table-input,
.fixed-sheet .table-select {
  width: 100%;
}

.col-code {
  width: 82px;
}

.col-name {
  width: 118px;
}

.col-group {
  width: 68px;
}

.col-num {
  width: 64px;
}

.col-small {
  width: 52px;
}

.col-eligible {
  width: 68px;
}

.col-multiplier {
  width: 74px;
}

.col-tip {
  width: 78px;
}

.col-status {
  width: 70px;
}

.col-updated {
  width: 112px;
}

.profile-sheet .col-name {
  width: 104px;
}

.profile-sheet .col-group {
  width: 72px;
}

.tight-rows th,
.tight-rows td {
  padding: 2px 3px;
  font-size: 10px;
  line-height: 1.12;
}

.reports-table th {
  font-size: 10px;
}

.reports-table td {
  font-size: 10px;
}

.reports-table .status-pill {
  min-width: 42px;
  padding: 0 4px;
  font-size: 9px;
}

.reports-table .actions-cell {
  gap: 3px;
  flex-wrap: nowrap;
}

@media (max-width: 1120px) {
  .dashboard-grid,
  .split-tables,
  .form-grid,
  .stats-cards {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .page-shell {
    padding: 12px;
  }

  .topbar {
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
    transform: none;
  }

  .sheet-table {
    min-width: 980px;
  }

  .brand-block h1,
  .panel-header h2 {
    font-size: 22px;
  }

  .toolbar-row {
    align-items: stretch;
  }

  .workflow-bar,
  .finalize-strip {
    align-items: stretch;
  }
}

body.report-detail-page .page-shell {
  max-width: 1420px;
  padding: 10px 12px 16px;
}

body.report-detail-page .page-content {
  gap: 8px;
}

body.report-detail-page .topbar {
  gap: 10px;
  margin-bottom: 8px;
  align-items: center;
}

body.report-detail-page .brand-block {
  gap: 2px;
}

body.report-detail-page .brand-block h1,
body.report-detail-page .panel-header h2 {
  font-size: 20px;
  line-height: 1.02;
}

body.report-detail-page .section-eyebrow {
  font-size: 10px;
}

body.report-detail-page .page-note,
body.report-detail-page .panel-copy,
body.report-detail-page .field span {
  font-size: 11px;
}

body.report-detail-page .brand-title-row {
  gap: 8px;
}

body.report-detail-page .header-actions {
  gap: 6px;
  transform: none;
}

body.report-detail-page .button {
  min-height: 26px;
  padding: 0 8px;
  border-radius: 7px;
  font-size: 11px;
}

body.report-detail-page .calc-launch-button {
  min-width: 92px;
}

body.report-detail-page .panel {
  border-radius: 7px;
}

body.report-detail-page .panel-header {
  gap: 8px;
  padding: 8px 10px 0;
}

body.report-detail-page .panel-meta {
  gap: 4px;
  font-size: 11px;
}

body.report-detail-page .panel-meta span {
  padding: 3px 7px;
}

body.report-detail-page .dashboard-grid {
  grid-template-columns: 1.45fr 0.95fr;
  gap: 8px;
}

body.report-detail-page .stats-cards {
  gap: 6px;
  padding: 8px 10px;
}

body.report-detail-page .summary-card-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding-left: 0;
  padding-right: 0;
}

body.report-detail-page .stat-card {
  gap: 2px;
  padding: 7px 8px;
  border-radius: 7px;
}

body.report-detail-page .stat-label {
  font-size: 10px;
}

body.report-detail-page .stat-card strong {
  font-size: 14px;
}

body.report-detail-page .toolbar-actions {
  gap: 6px;
  padding: 0 10px 10px;
}

body.report-detail-page .sheet-form {
  gap: 8px;
  padding: 10px;
}

body.report-detail-page .toolbar-row {
  gap: 6px;
}

body.report-detail-page .field input,
body.report-detail-page .field select {
  min-height: 26px;
  padding: 3px 6px;
  font-size: 11px;
}

body.report-detail-page .compact-field {
  min-width: 160px;
}

body.report-detail-page .grow-field {
  flex-basis: 220px;
}

body.report-detail-page .sheet-table th,
body.report-detail-page .sheet-table td {
  padding: 2px 4px;
  font-size: 11px;
}

body.report-detail-page .table-input,
body.report-detail-page .table-select {
  min-height: 21px;
  font-size: 10px;
}

@media (max-width: 1120px) {
  body.report-detail-page .dashboard-grid {
    grid-template-columns: 1.45fr 0.95fr;
  }

  body.report-detail-page .stats-cards {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  body.report-detail-page .dashboard-grid {
    grid-template-columns: 1fr;
  }

  body.report-detail-page .stats-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  body.report-detail-page .page-shell {
    padding: 10px;
  }

  body.report-detail-page .stats-cards {
    grid-template-columns: 1fr;
  }
}
