:root {
  --red: #df1f26;
  --yellow: #ffd324;
  --ink: #202020;
  --muted: #686868;
  --line: #d7d7d7;
  --surface: #ffffff;
  --background: #f4f4f4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--background);
  color: var(--ink);
  font: 14px Arial, sans-serif;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 84px;
  padding: 7px 20px;
  background: #050505;
  border-bottom: 4px solid var(--red);
}

.logo {
  width: 190px;
  height: 68px;
  object-fit: contain;
  flex: none;
}

nav {
  display: flex;
  gap: 5px;
  flex: 0 1 auto;
  min-width: 0;
}

button,
input,
select { font: inherit; }

button {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  cursor: pointer;
}

button:hover { background: #ededed; }
button:disabled { opacity: .45; cursor: not-allowed; }
.button-link {
  display: inline-block;
  padding: 9px 12px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 5px;
  text-decoration: none;
}

.nav-button {
  display: inline-flex;
  align-items: center;
  flex: none;
  padding: 9px 12px;
  border: 1px solid #444;
  border-radius: 5px;
  text-decoration: none;
  white-space: nowrap;
  color: white;
  background: #202020;
  border-color: #444;
}

.nav-button.active,
.accent {
  color: #111;
  background: var(--yellow);
  border-color: var(--yellow);
  font-weight: bold;
}

.primary {
  color: white;
  background: var(--red);
  border-color: var(--red);
  font-weight: bold;
}

.danger { color: #b3191f; }
.app-header #auction-select {
  width: 320px;
  min-width: 220px;
  max-width: 320px;
  flex: 0 1 320px;
}

main {
  width: min(1500px, 100%);
  margin: auto;
  padding: 22px;
}

.login-page {
  width: min(520px, calc(100% - 32px));
  min-height: calc(100vh - 90px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12px;
}

.login-panel {
  width: 100%;
}

.login-logo {
  display: block;
  width: 250px;
  max-width: 100%;
  height: 90px;
  margin: 0 auto 6px;
  object-fit: contain;
  background: #050505;
}

.login-title {
  text-align: center;
}

.view { display: none; }
.view.active { display: block; }

h1 { margin: 0 0 4px; font-size: 23px; }
h2 { margin: 0 0 14px; font-size: 17px; }
.muted { margin: 0; color: var(--muted); font-size: 12px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toolbar > div:first-child { margin-right: auto; }
.search { width: 220px; }

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  padding: 9px 10px;
  border: 1px solid #c7c7c7;
  border-radius: 5px;
  background: white;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat,
.panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.stat { padding: 14px; }
.stat span { display: block; color: var(--muted); font-size: 11px; }
.stat strong { font-size: 22px; }
.panel { padding: 18px; margin-bottom: 17px; }

.table-shell {
  overflow: auto;
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.panel .table-shell { border-radius: 4px; }

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th,
td {
  padding: 10px;
  text-align: left;
  border-bottom: 1px solid #e8e8e8;
}

th {
  color: #555;
  background: #fafafa;
  font-size: 11px;
  text-transform: uppercase;
}

.number { text-align: right; }
.empty { padding: 38px; color: var(--muted); text-align: center; }
.allocation { display: block; margin: 2px 0; font-size: 12px; }

.status,
.notice {
  margin-bottom: 15px;
  padding: 12px 15px;
  border-radius: 5px;
}

.status {
  color: #145c35;
  background: #e3f5ea;
  border: 1px solid #9bc8ac;
}

.notice {
  color: #6a4100;
  background: #fff5d2;
  border: 1px solid #e4c967;
}

.sale-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 17px;
}

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

label {
  display: block;
  font-size: 12px;
  font-weight: bold;
}

label input,
label select { margin-top: 5px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.full-width { grid-column: 1 / -1; }
.button-field { padding-top: 20px; }
.button-field button { width: 100%; }
.form-actions { margin-top: 16px; text-align: right; }
.sale-preview strong { display: block; margin: 10px 0; color: var(--red); font-size: 28px; }

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
}

.badge.paid { color: #17653b; background: #dff3e7; }
.badge.unpaid { color: #805000; background: #fff0d8; }
.email-sent-button {
  color: white;
  background: #198754;
  border-color: #198754;
  font-weight: bold;
}
.email-sent-button:hover {
  color: white;
  background: #146c43;
}

dialog {
  width: min(760px, 94vw);
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 20px 60px #0005;
}

dialog::backdrop { background: #0008; }
.confirmation-dialog {
  width: min(440px, 92vw);
}
.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 { flex: 1; margin: 0; }
.dialog-body { padding: 18px; }
.dialog-actions { justify-content: flex-end; border-top: 1px solid var(--line); border-bottom: 0; }
.icon-button { width: 34px; padding: 7px; }

#print-area { display: none; }
.app-footer {
  padding: 18px 22px;
  color: #777;
  font-size: 12px;
  text-align: center;
}
.invoice-header { display: flex; justify-content: space-between; border-bottom: 3px solid var(--red); }
.invoice-logo {
  display: block;
  width: 220px;
  max-height: 90px;
  object-fit: contain;
  object-position: left center;
}
.invoice-totals { width: 320px; margin: 20px 0 0 auto; }
.invoice-totals div { display: flex; justify-content: space-between; padding: 6px; }
.invoice-totals .grand { border-top: 2px solid #222; font-size: 18px; font-weight: bold; }
.invoice-terms {
  clear: both;
  margin-top: 35px;
  padding-top: 15px;
  border-top: 1px solid #bbb;
  font-size: 12px;
  line-height: 1.5;
}

.logo-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  font-size: 12px;
  font-weight: bold;
}

.logo-preview img {
  width: 150px;
  height: 60px;
  padding: 4px;
  object-fit: contain;
  background: #050505;
  border-radius: 4px;
}

@media (max-width: 980px) {
  .app-header { align-items: stretch; flex-direction: column; }
  .logo { align-self: center; }
  nav { overflow-x: auto; }
  .app-header #auction-select {
    width: min(100%, 320px);
    min-width: 0;
    max-width: 320px;
    flex: none;
    align-self: center;
  }
  .stats { grid-template-columns: 1fr 1fr; }
  .form-grid,
  .sale-layout { grid-template-columns: 1fr; }
  .span-2,
  .span-3 { grid-column: span 1; }
}

@media print {
  body {
    background: white;
  }
  .app-header { display: none !important; }
  .app-footer { display: none !important; }
  main {
    display: block !important;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
  }
  main > * { display: none !important; }
  main > .invoice-print {
    display: block !important;
    margin: 0;
    padding: 0;
    border: 0;
  }
  .invoice-print .form-actions { display: none !important; }
  .invoice-print table {
    margin-top: 20px;
  }
}
