:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-soft: #f0f5f3;
  --text: #1d252c;
  --muted: #66717d;
  --line: #d9e0e6;
  --brand: #126b5a;
  --brand-dark: #0b4d42;
  --accent: #b15b2a;
  --danger: #a43a3a;
  --shadow: 0 12px 30px rgba(25, 39, 52, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

button,
.secondary-button {
  border: 0;
  background: var(--brand);
  color: white;
  border-radius: 6px;
  padding: 0.65rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

button:hover,
.secondary-button:hover {
  background: var(--brand-dark);
}

.secondary-button {
  background: #e6ecea;
  color: var(--text);
}

.secondary-button:hover {
  background: #d8e2df;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

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

.app-header h1 {
  margin-bottom: 0.2rem;
  font-size: 1.35rem;
}

.app-header p {
  margin-bottom: 0;
  color: var(--muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.connection-status {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.connection-status.connected {
  color: var(--brand);
}

.connection-status.needs-setup {
  color: var(--accent);
}

.app-tabs {
  display: flex;
  gap: 0.4rem;
  padding: 0.75rem 1rem 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.tab-button {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  padding: 0.65rem 0.95rem;
}

.tab-button:hover {
  background: #e6ecea;
  color: var(--text);
}

.tab-button.active {
  background: var(--panel);
  color: var(--brand);
  border-color: var(--line);
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr) minmax(260px, 340px);
  gap: 1rem;
  padding: 1rem;
  min-height: calc(100vh - 78px);
}

.layout.queue-work-layout {
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
}

.queue-panel,
.work-panel,
.dashboard-panel,
.user-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.queue-panel,
.dashboard-panel,
.user-panel {
  padding: 1rem;
}

.dashboard-panel.dashboard-full,
.user-panel {
  grid-column: 1 / -1;
}

.work-panel {
  padding: 1.2rem;
}

.section-heading,
.workspace-header,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.section-heading h2,
.section-heading h3 {
  margin-bottom: 0;
}

select,
textarea,
input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
}

select,
input {
  min-height: 2.45rem;
  padding: 0 0.65rem;
}

textarea {
  padding: 0.7rem;
  resize: vertical;
}

.invoice-list {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
}

.invoice-row {
  width: 100%;
  display: grid;
  gap: 0.35rem;
  text-align: left;
  background: white;
  color: var(--text);
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 6px;
  padding: 0.8rem;
}

.invoice-row.active {
  border-color: var(--brand);
  background: var(--panel-soft);
}

.invoice-row:hover {
  color: white;
}

.invoice-row:hover .row-meta,
.invoice-row:hover .queue-badge,
.invoice-row:hover .queue-total,
.invoice-row:hover .queue-meta-line,
.invoice-row:hover .invoice-count,
.invoice-row:hover .presence {
  color: white;
}

.invoice-row:hover .queue-badge,
.invoice-row:hover .invoice-count {
  background: rgba(255, 255, 255, 0.18);
}

.invoice-row.active:hover {
  color: var(--text);
}

.invoice-row.active:hover .queue-total,
.invoice-row.active:hover .invoice-count {
  color: var(--text);
}

.invoice-row.active:hover .row-meta,
.invoice-row.active:hover .queue-meta-line {
  color: var(--muted);
}

.invoice-row.active:hover .queue-badge {
  background: #e6ecea;
  color: var(--text);
}

.invoice-row.active:hover .invoice-count {
  background: #f0f5f3;
}

.invoice-row.active:hover .presence {
  color: var(--accent);
}

.invoice-row.locked,
.invoice-row:disabled {
  cursor: not-allowed;
  opacity: 0.62;
  border-left-color: var(--accent);
}

.invoice-row.locked:hover,
.invoice-row:disabled:hover {
  background: white;
  color: var(--text);
}

.invoice-row.locked:hover .row-meta,
.invoice-row:disabled:hover .row-meta,
.invoice-row.locked:hover .queue-badge,
.invoice-row:disabled:hover .queue-badge,
.invoice-row.locked:hover .queue-total,
.invoice-row:disabled:hover .queue-total,
.invoice-row.locked:hover .queue-meta-line,
.invoice-row:disabled:hover .queue-meta-line,
.invoice-row.locked:hover .invoice-count,
.invoice-row:disabled:hover .invoice-count {
  color: var(--text);
}

.invoice-row.locked:hover .queue-badge,
.invoice-row:disabled:hover .queue-badge {
  background: #e6ecea;
}

.invoice-row.locked:hover .invoice-count,
.invoice-row:disabled:hover .invoice-count {
  background: #f0f5f3;
}

.invoice-row.locked:hover .presence,
.invoice-row:disabled:hover .presence {
  color: var(--accent);
}

.invoice-row strong,
.metric strong {
  font-size: 1.05rem;
}

.queue-group {
  gap: 0.5rem;
}

.queue-group-header,
.queue-total,
.queue-meta-line,
.invoice-count {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.queue-badge {
  border-radius: 999px;
  background: #e6ecea;
  color: var(--text);
  padding: 0.15rem 0.5rem;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.queue-total {
  color: var(--text);
  font-weight: 800;
}

.queue-total .row-meta {
  font-weight: 700;
}

.queue-meta-line {
  color: var(--muted);
  font-size: 0.9rem;
}

.invoice-count {
  border-radius: 999px;
  background: #f0f5f3;
  color: var(--text);
  padding: 0.15rem 0.5rem;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1;
}

.single-card-icon,
.stack-icon {
  position: relative;
  width: 0.9rem;
  height: 0.75rem;
  display: inline-block;
}

.single-card-icon::before {
  content: "";
  position: absolute;
  left: 0.11rem;
  top: 0.14rem;
  width: 0.68rem;
  height: 0.48rem;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  background: currentColor;
}

.stack-icon::before,
.stack-icon::after {
  content: "";
  position: absolute;
  width: 0.68rem;
  height: 0.48rem;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  background: currentColor;
}

.stack-icon::before {
  left: 0.18rem;
  top: 0;
  opacity: 0.68;
}

.stack-icon::after {
  left: 0;
  top: 0.18rem;
}

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

.presence {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.85rem;
}

.empty-state {
  display: grid;
  min-height: 320px;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.hidden {
  display: none !important;
}

.eyebrow {
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.workspace-header {
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1rem;
}

.workspace-header h2 {
  margin-bottom: 0.2rem;
}

.contact-line,
.phone-edit {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.contact-line {
  color: var(--muted);
}

.phone-edit input {
  flex: 1 1 160px;
}

.call-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.1rem;
  border-radius: 6px;
  background: var(--brand);
  color: white;
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
}

.call-link:hover {
  background: var(--brand-dark);
}

.invoice-facts,
.customer-facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.invoice-facts {
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
}

.customer-facts {
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  margin: 0 0 1rem;
}

.invoice-fact-card,
.customer-facts div,
.metric,
.user-row,
.history-item {
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.75rem;
}

dt {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
}

dd {
  margin: 0;
  font-weight: 800;
}

.fact-note {
  display: block;
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.customer-editor {
  margin: 1rem 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

.customer-editor .section-heading {
  align-items: baseline;
  margin-bottom: 0.8rem;
}

.customer-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  align-items: end;
}

.customer-form .email-field {
  min-width: 0;
}

.invite-user-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.3fr) minmax(150px, 0.7fr) auto;
  gap: 0.8rem;
  align-items: end;
  margin: 1rem 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

.customer-form .form-actions {
  justify-content: flex-end;
}

.customer-form .form-actions button {
  white-space: nowrap;
}

.invoice-tabs-section {
  margin: 1rem 0;
}

.invoice-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.invoice-tab {
  min-width: 128px;
  display: grid;
  gap: 0.15rem;
  text-align: left;
  background: white;
  color: var(--text);
  border: 1px solid var(--line);
  border-bottom: 3px solid transparent;
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
}

.invoice-tab:hover {
  background: var(--panel-soft);
}

.invoice-tab.active {
  border-color: var(--brand);
  border-bottom-color: var(--brand);
  background: var(--panel-soft);
}

.invoice-tab span,
.invoice-tab em {
  color: var(--muted);
  font-size: 0.85rem;
}

.invoice-tab em {
  font-style: normal;
  font-weight: 800;
}

.invoice-tab.worked-today {
  background: #f3f5f4;
  border-color: #cfd8d5;
  color: var(--muted);
}

.invoice-tab.worked-today.active {
  border-color: var(--brand);
  border-bottom-color: var(--brand);
  color: var(--text);
}

.invoice-open-slot {
  display: flex;
  align-items: stretch;
}

.invoice-open-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100%;
}

.status-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, auto);
  gap: 0.75rem;
  align-items: end;
}

.promised-pay-field {
  min-width: 0;
}

.promised-pay-field input:disabled {
  background: #eef2f1;
  color: var(--muted);
}

.dialog-promised-pay-field input:disabled {
  background: #eef2f1;
  color: var(--muted);
}

button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.activity-form {
  display: grid;
  gap: 0.8rem;
}

.note-entry-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(150px, auto);
  gap: 0.75rem;
  align-items: end;
}

.note-field textarea {
  min-height: 9rem;
}

.activity-actions {
  display: grid;
  gap: 0.55rem;
  align-self: end;
}

.activity-actions button {
  min-height: 2.45rem;
  white-space: nowrap;
}

.activity-form label,
.status-row label,
.note-field,
.customer-form label,
.invite-user-form label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-weight: 700;
}

.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;
}

.history-heading {
  margin-top: 1.25rem;
}

.history-list,
.user-activity,
.metrics,
.dashboard-sections {
  display: grid;
  gap: 0.65rem;
}

.dashboard-sections {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 1rem;
  gap: 1rem;
}

.dashboard-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  background: #f9fafb;
}

.dashboard-section h3 {
  margin-bottom: 0.8rem;
}

.users-list {
  overflow-x: auto;
}

.admin-tool-panel {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.admin-tool-panel .section-heading {
  align-items: flex-start;
}

.users-table,
.note-writes-table {
  display: grid;
  min-width: 760px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.note-writes-list {
  overflow-x: auto;
  margin-top: 1rem;
}

.users-table-row,
.note-writes-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(220px, 1.4fr) minmax(150px, 0.7fr) minmax(170px, 0.8fr);
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem;
  border-bottom: 1px solid var(--line);
  background: white;
}

.note-writes-row {
  grid-template-columns: minmax(120px, 0.7fr) minmax(180px, 1fr) minmax(110px, 0.6fr) minmax(90px, 0.5fr) minmax(260px, 2fr);
}

.users-table-row:last-child,
.note-writes-row:last-child {
  border-bottom: 0;
}

.users-table-heading,
.note-writes-heading {
  background: #f0f5f3;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.6rem;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  background: #e6ecea;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 800;
}

.status-pill.sent {
  background: #dfeee8;
  color: var(--brand-dark);
}

.status-pill.pending {
  background: #f3e7df;
  color: var(--accent);
}

.status-pill.failed {
  background: #f7dddd;
  color: var(--danger);
}

.error-cell {
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

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

.metric span,
.history-item span {
  color: var(--muted);
  font-size: 0.85rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: 420px;
  background: var(--text);
  color: white;
  padding: 0.8rem 1rem;
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.call-attempt-dialog {
  width: min(420px, calc(100vw - 2rem));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0;
}

.call-attempt-dialog::backdrop {
  background: rgba(29, 37, 44, 0.35);
}

.call-attempt-dialog form {
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.call-attempt-dialog h2 {
  margin-bottom: 0;
}

.call-attempt-dialog label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-weight: 700;
}

.call-attempt-dialog textarea {
  min-height: 8rem;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 320px 1fr;
  }

  .dashboard-panel,
  .dashboard-panel.dashboard-full,
  .user-panel {
    grid-column: 1 / -1;
  }

  .dashboard-sections {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-header,
  .app-tabs,
  .layout,
  .workspace-header,
  .form-actions,
  .header-actions {
    display: grid;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .invoice-facts,
  .customer-facts,
  .customer-form,
  .invite-user-form,
  .status-row,
  .note-entry-row,
  .metrics {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .customer-form {
    grid-template-columns: 1fr;
  }

  .customer-form .form-actions {
    justify-content: stretch;
  }

  .customer-form .form-actions button {
    width: 100%;
  }
}
