:root {
  --bg: #f5f7f2;
  --panel: #ffffff;
  --ink: #1d2521;
  --muted: #657069;
  --line: #d8ded6;
  --accent: #176b57;
  --accent-dark: #115242;
  --blue: #285f8f;
  --warn: #9a4c11;
  --soft: #eef3ef;
  --shadow: 0 16px 42px rgba(29, 37, 33, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 14px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

button:hover {
  border-color: #a9b5ad;
}

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

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

button.primary:hover {
  background: var(--accent-dark);
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fbfcfa;
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(23, 107, 87, 0.16);
  border-color: var(--accent);
}

textarea {
  min-width: 180px;
  resize: vertical;
}

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

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

h2 {
  font-size: 1.05rem;
}

h3 {
  font-size: 0.98rem;
}

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

.hidden {
  display: none !important;
}

.login-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 28px;
  align-items: center;
  min-height: calc(100vh - 48px);
}

.login-copy h1 {
  max-width: 700px;
}

.hero-subtitle {
  max-width: 620px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 1.12rem;
  font-weight: 750;
  line-height: 1.4;
}

.login-panel {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.portal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 16px;
}

.portal-card {
  display: grid;
  gap: 10px;
  min-height: 180px;
  align-content: center;
  text-align: left;
  padding: 22px;
  border-color: var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.portal-card strong {
  font-size: 1.4rem;
}

.portal-card span {
  color: var(--muted);
  font-weight: 700;
  line-height: 1.35;
}

.back-home-button {
  margin-top: 18px;
}

.topbar,
.panel-header,
.invoice-header,
.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 20px;
}

.topbar-actions,
.clock-actions,
.card-actions {
  display: flex;
  gap: 8px;
}

.clock-actions {
  flex-wrap: wrap;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

.toolbar,
.summary-grid,
.panel,
.invoice {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.toolbar {
  display: grid;
  grid-template-columns: 180px minmax(220px, 1fr) auto;
  gap: 14px;
  align-items: end;
  padding: 16px;
}

.field,
.employee-form,
#manualForm {
  display: grid;
  gap: 6px;
}

label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}

.toggle input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin: 16px 0;
  overflow: hidden;
  background: var(--line);
}

.summary-grid div {
  padding: 16px;
  background: var(--panel);
}

.summary-grid span {
  display: block;
  font-size: 1.7rem;
  font-weight: 950;
}

.summary-grid p,
.employee-card p,
.invoice-meta {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
}

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

.side-stack {
  display: grid;
  gap: 16px;
  align-content: start;
}

.panel {
  overflow: hidden;
}

.panel-header {
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.employee-form {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--soft);
}

.employee-list {
  display: grid;
  gap: 1px;
  background: var(--line);
}

.employee-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel);
}

.employee-card.selected {
  border-left: 4px solid var(--accent);
}

.employee-card code {
  display: block;
  max-width: 230px;
  margin-top: 8px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
}

.logo-preview {
  display: grid;
  min-height: 86px;
  place-items: center;
  border: 1px dashed #aeb8b1;
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  overflow: hidden;
}

.logo-preview img {
  max-width: 100%;
  max-height: 82px;
  object-fit: contain;
}

.message {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
}

.message.error {
  color: var(--warn);
}

.table-wrap {
  overflow-x: auto;
}

.invoice-log {
  margin-top: 16px;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.row-actions button {
  min-height: 34px;
  padding: 6px 10px;
}

.compact-toggle {
  min-height: 34px;
  color: var(--ink);
}

.compact-toggle input {
  width: 18px;
  min-height: 18px;
}

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

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

th {
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(40, 95, 143, 0.12);
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 900;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.invoice {
  margin-top: 16px;
  padding: 24px;
}

.invoice .eyebrow {
  color: var(--accent);
}

.invoice-logo {
  display: block;
  max-width: 170px;
  max-height: 86px;
  margin-bottom: 14px;
  object-fit: contain;
}

.invoice-business {
  margin-bottom: 6px;
  font-size: 1.08rem;
  font-weight: 900;
}

.invoice-contact {
  display: grid;
  gap: 2px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.invoice-total {
  display: grid;
  justify-content: end;
  gap: 8px;
  margin-top: 20px;
}

.invoice-total p {
  display: grid;
  grid-template-columns: 120px 150px;
  gap: 12px;
  text-align: right;
}

.grand-total {
  padding-top: 10px;
  border-top: 2px solid var(--ink);
  font-size: 1.2rem;
}

dialog {
  width: min(520px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(29, 37, 33, 0.42);
}

#scannerVideo {
  width: 100%;
  aspect-ratio: 4 / 3;
  margin: 14px 0 10px;
  border-radius: 8px;
  background: #111;
  object-fit: cover;
}

#scannerHelp {
  color: var(--muted);
  font-size: 0.9rem;
}

#manualForm {
  gap: 10px;
}

@media (max-width: 980px) {
  .login-view,
  .toolbar,
  .portal-grid,
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 660px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .topbar-actions,
  .login-actions,
  .clock-actions,
  .employee-card {
    display: grid;
    grid-template-columns: 1fr;
  }

  .toolbar,
  .summary-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .topbar,
  .toolbar,
  .summary-grid,
  .layout,
  dialog {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .invoice {
    display: block;
    margin: 0;
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  table {
    min-width: 0;
  }
}
