:root {
  --red: #c8102e;
  --red-dark: #9e0c24;
  --black: #111111;
  --ink: #1a1a1a;
  --muted: #5c5c5c;
  --line: #d8d8d8;
  --bg: #f3f3f3;
  --card: #ffffff;
  --silver: #e8e8e8;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  --radius: 10px;
  --font: "Barlow", sans-serif;
  --display: "Barlow Condensed", "Barlow", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(200, 16, 46, 0.08), transparent 40%),
    linear-gradient(180deg, #fafafa 0%, var(--bg) 100%);
}

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

.hidden {
  display: none !important;
}

.lock-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(200, 16, 46, 0.12), transparent 40%),
    #f3f3f3;
}

.lock-card {
  width: min(100%, 400px);
  background: #fff;
  border: 2px solid #111;
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
  text-align: center;
}

.lock-logo {
  width: 96px;
  height: 96px;
  object-fit: contain;
  border-radius: 50%;
  background: #000;
}

.lock-card h1 {
  margin: 14px 0 6px;
  font-family: var(--display);
  font-size: 1.8rem;
  letter-spacing: 0.02em;
}

.lock-card > p {
  color: var(--muted);
  margin: 0 0 16px;
}

#lock-form {
  display: block;
  width: 100%;
  text-align: left;
}

#error,
.error {
  color: var(--red);
  font-size: 0.95rem;
  font-weight: 600;
  margin: 10px 0 0;
  text-align: center;
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 18px 40px;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding: 12px 16px;
  background: var(--black);
  color: #fff;
  border-radius: 14px;
  border-bottom: 3px solid var(--red);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-right: auto;
}

.brand-logo {
  width: 54px;
  height: 54px;
  object-fit: contain;
  border-radius: 50%;
  background: #000;
}

.brand strong {
  display: block;
  font-family: var(--display);
  font-size: 1.35rem;
  letter-spacing: 0.04em;
}

.brand span {
  color: #cfcfcf;
  font-size: 0.85rem;
}

.tabs {
  display: flex;
  gap: 6px;
  background: rgba(255, 255, 255, 0.08);
  padding: 4px;
  border-radius: 999px;
}

.tab {
  border: 0;
  background: transparent;
  color: #ddd;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}

.tab.active {
  background: var(--red);
  color: #fff;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

#tab-create.active {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.1fr);
  gap: 18px;
  align-items: start;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.card {
  margin: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 16px 8px;
  box-shadow: var(--shadow);
}

.card legend {
  float: left;
  width: calc(100% + 32px);
  margin: 0 -16px 14px;
  padding: 12px 16px;
  font-family: var(--display);
  font-size: 1.25rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  background: var(--black);
  border-bottom: 3px solid var(--red);
  border-radius: var(--radius) var(--radius) 0 0;
}

.card legend + * {
  clear: both;
}

.hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  font-size: 0.9rem;
  font-weight: 600;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid rgba(200, 16, 46, 0.25);
  border-color: var(--red);
}

.plate {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.row {
  display: flex;
  gap: 12px;
}

.grow {
  flex: 1;
}

.field-hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.field-hint.error-hint {
  color: var(--red);
}

.service-lines {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.service-line {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #fafafa;
}

.service-line-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.service-line-top strong {
  font-family: var(--display);
  letter-spacing: 0.03em;
}

.line-remove {
  padding: 6px 10px;
  font-size: 0.85rem;
}

.add-line-btn {
  width: 100%;
  margin-bottom: 12px;
  background: #fff5f6;
  color: var(--red);
  border: 2px dashed var(--red);
  font-size: 1.05rem;
  font-weight: 700;
}

.add-line-btn:hover {
  background: var(--red);
  color: #fff;
  border-style: solid;
}

.totals-live {
  min-width: 160px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-content: center;
  background: #111;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.invoice-live-totals {
  margin-top: 4px;
}

.totals-live span {
  color: #cfcfcf;
  font-size: 0.85rem;
}

.totals-live strong:last-of-type {
  color: #ffb3be;
}

@media (max-width: 640px) {
  .actions {
    flex-direction: column;
  }
}

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

.btn {
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 600;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--red-dark);
}

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

.btn-ghost {
  background: transparent;
  color: inherit;
  border: 1px solid currentColor;
}

.app-header .btn-ghost {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
}

.preview-wrap {
  position: sticky;
  top: 14px;
}

.preview-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.invoice-sheet {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-height: 520px;
  overflow: hidden;
}

.invoice-sheet.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 24px;
}

.invoice {
  padding: 22px 24px 18px;
  color: var(--ink);
}

.invoice-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 3px solid var(--red);
}

.invoice-logo {
  width: 88px;
  height: 88px;
  object-fit: contain;
  border-radius: 50%;
  background: #000;
}

.invoice-garage h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.7rem;
  letter-spacing: 0.04em;
}

.invoice-garage h1 span {
  color: var(--red);
}

.invoice-garage p {
  margin: 4px 0 0;
  font-size: 0.86rem;
  color: var(--muted);
  line-height: 1.45;
}

.invoice-meta {
  text-align: right;
}

.invoice-meta .badge {
  display: inline-block;
  background: var(--black);
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-family: var(--display);
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.invoice-meta strong {
  color: var(--red);
}

.invoice-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 18px 0 14px;
}

.party {
  background: #f7f7f7;
  border-left: 3px solid var(--red);
  padding: 12px 14px;
  border-radius: 0 8px 8px 0;
}

.party h2 {
  margin: 0 0 8px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.party p {
  margin: 0;
  line-height: 1.45;
  font-size: 0.92rem;
}

.vehicle-box {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px dashed #bbb;
  border-radius: 8px;
  font-size: 0.92rem;
}

.vehicle-box strong {
  color: var(--red);
}

table.lines {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 14px;
  font-size: 0.92rem;
}

table.lines th {
  background: var(--black);
  color: #fff;
  text-align: left;
  padding: 10px 8px;
  font-weight: 600;
}

table.lines th:not(:first-child),
table.lines td:not(:first-child) {
  text-align: right;
  white-space: nowrap;
}

table.lines td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.totals {
  width: min(280px, 100%);
  margin-left: auto;
  margin-bottom: 16px;
}

.totals div {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.95rem;
}

.totals .grand {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 2px solid var(--black);
  font-size: 1.1rem;
  font-weight: 700;
}

.totals .grand span:last-child {
  color: var(--red);
}

.legal {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  font-size: 0.75rem;
  color: #555;
  line-height: 1.45;
}

.legal p {
  margin: 0 0 6px;
}

.history-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.history-toolbar h2 {
  margin: 0;
  font-family: var(--display);
  letter-spacing: 0.03em;
}

.sync-status {
  margin: 4px 0 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.sync-status.ok {
  color: #1a7f37;
}

.sync-status.warn {
  color: #9a6700;
}

.sync-status.err {
  color: var(--red);
}

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

.history-layout {
  display: grid;
  grid-template-columns: minmax(280px, 320px) 1fr;
  gap: 16px;
  align-items: start;
}

.calendar-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 14px;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.calendar-header h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.2rem;
  letter-spacing: 0.03em;
  text-transform: capitalize;
}

.cal-nav {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 1.4rem;
  line-height: 1;
  border-color: var(--line);
  color: var(--ink);
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 6px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

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

.cal-day {
  aspect-ratio: 1;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  position: relative;
  padding: 0;
}

.cal-day:disabled {
  color: #ccc;
  cursor: default;
}

.cal-day.has-invoice {
  background: rgba(200, 16, 46, 0.1);
  border-color: rgba(200, 16, 46, 0.35);
  color: var(--red-dark);
}

.cal-day.has-invoice::after {
  content: "";
  position: absolute;
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--red);
}

.cal-day.selected {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.cal-day.selected::after {
  background: #fff;
}

.cal-day.today:not(.selected) {
  border-color: var(--black);
}

.calendar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.cal-filter-label {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.cal-hint {
  margin: 10px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}

.history-list {
  display: grid;
  gap: 10px;
}

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

  .calendar-card {
    position: static;
  }
}

.history-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  box-shadow: var(--shadow);
}

.history-item h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.history-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.history-item .amount {
  font-weight: 700;
  color: var(--red);
  font-size: 1.05rem;
  text-align: right;
}

.history-item .item-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  grid-column: 1 / -1;
}

.empty-history {
  background: var(--card);
  border: 1px dashed #bbb;
  border-radius: 10px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 960px) {
  #tab-create.active {
    grid-template-columns: 1fr;
  }

  .preview-wrap {
    position: static;
  }
}

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

  .app-header,
  .form-grid,
  .preview-toolbar,
  .no-print,
  #tab-history {
    display: none !important;
  }

  #tab-create.active {
    display: block !important;
  }

  .preview-wrap,
  .invoice-sheet {
    box-shadow: none;
    border: 0;
    border-radius: 0;
    margin: 0;
    width: 100%;
  }

  .invoice {
    padding: 0;
  }
}
