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

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #d8dee6;
  --text: #1a2332;
  --muted: #5c6b7a;
  --primary: #1e4d8c;
  --primary-hover: #163a6b;
  --danger: #b42318;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(26, 35, 50, 0.08);
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

/* Password gate */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}

.auth-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
}

.auth-card p {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.auth-error {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 0.5rem;
  min-height: 1.25rem;
}

/* Main app */
#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

header.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 640px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
}

label .optional {
  font-weight: 400;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(30, 77, 140, 0.25);
  border-color: var(--primary);
}

.field {
  margin-bottom: 0.85rem;
}

/* Line items table */
.line-items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.line-items-wrap {
  overflow-x: auto;
}

table.line-items {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.line-items th,
table.line-items td {
  padding: 0.5rem 0.35rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

table.line-items th {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

table.line-items input {
  min-width: 0;
}

table.line-items textarea {
  width: 100%;
  min-width: 0;
  min-height: 2.2rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
  resize: none;
  overflow: hidden;
  line-height: 1.35;
}

table.line-items textarea:focus {
  outline: 2px solid rgba(30, 77, 140, 0.25);
  border-color: var(--primary);
}

table.line-items .col-num {
  width: 2rem;
  text-align: center;
  color: var(--muted);
}

table.line-items .col-desc {
  width: 42%;
  max-width: 18rem;
}

table.line-items .col-qty {
  width: 4.75rem;
}

table.line-items .col-qty input {
  text-align: center;
}

table.line-items .col-unit {
  width: 3.5rem;
}

table.line-items .col-price {
  width: 4.75rem;
}

table.line-items .col-price input {
  font-size: 0.85rem;
  padding: 0.4rem 0.45rem;
}

table.line-items .col-price .price-hint {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.2;
}

table.line-items .col-price .price-hint.hidden {
  display: none;
}

table.line-items .col-line-total {
  width: 5.5rem;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.btn-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.25rem 0.4rem;
  line-height: 1;
}

.btn-remove:hover {
  opacity: 0.75;
}

/* Tax mode & totals */
.tax-mode {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 1rem 0;
}

.tax-mode label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  cursor: pointer;
  font-weight: 400;
}

.tax-mode input[type="radio"] {
  width: auto;
}

.totals {
  margin-top: 1rem;
  margin-left: auto;
  max-width: 320px;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  font-variant-numeric: tabular-nums;
}

.totals-row.grand {
  border-top: 2px solid var(--text);
  margin-top: 0.5rem;
  padding-top: 0.65rem;
  font-weight: 700;
  font-size: 1.1rem;
}

.totals-row .label {
  color: var(--muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 6px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #e8edf3;
  color: var(--text);
}

.btn-secondary:hover {
  background: #dce3ec;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.5rem;
}
