/* ============================================================
   public/styles.css
   Screen styles + print rules for 2-3 slips per letter page.
   ============================================================ */

:root {
  --bg: #f6f7f9;
  --bg-elevated: #ffffff;
  --border: #e2e6ec;
  --border-strong: #cbd2da;
  --text: #1a1f2b;
  --text-muted: #5b6573;
  --text-soft: #7a8492;
  --accent: #2f5fe8;
  --accent-hover: #2350cc;
  --accent-soft: #eaf0fd;
  --success: #047857;
  --error: #b91c1c;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 1px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.06);
  --radius: 8px;
  --radius-sm: 6px;
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 0% 0%, #eef2fb 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #f0ebfa 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Control panel ---------- */
.control-panel {
  padding: 1.75rem 1.5rem 1rem;
}
.control-panel__inner {
  max-width: 1100px;
  margin: 0 auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 1.5rem 1.75rem 1.25rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.panel-header__title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
.panel-header__title .accent {
  color: var(--accent);
  font-weight: 800;
}
.panel-header__subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.15rem 0 0 0;
}

/* ---------- Filter rows ---------- */
.filters {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}
.filters__row {
  display: grid;
  gap: 1rem 1.1rem;
  align-items: end;
}
/* Date row: single full-width column so date inputs + quick buttons can spread */
.filters__row--date {
  grid-template-columns: 1fr;
}
/* Filter row: 3 dropdowns + actions, all roughly equal */
.filters__row--filters {
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
}

@media (max-width: 760px) {
  .filters__row--filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .filter-group--actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
  position: relative; /* anchor for multi-select panel */
}
.filter-group label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

input[type="date"] {
  font-family: inherit;
  font-size: 0.92rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  min-height: 2.4rem;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input[type="date"]:hover { border-color: #a9b3c1; }
input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Date row: input | "to" | input | buttons — all on one line */
.date-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.date-row input[type="date"] {
  /* Generous min-width so MM/DD/YYYY is fully visible */
  min-width: 9rem;
}
.date-sep {
  color: var(--text-soft);
  font-size: 0.85rem;
  font-weight: 500;
}

.quick-buttons {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-left: 0.5rem;
}
.quick-btn {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.35rem 0.8rem;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.12s ease;
}
.quick-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.quick-btn:active { transform: translateY(1px); }

.filter-group--actions {
  flex-direction: row;
  gap: 0.5rem;
  align-self: end;
}

.btn {
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 2.4rem;
  transition: all 0.12s ease;
  white-space: nowrap;
}
.btn--primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(47, 95, 232, 0.25);
}
.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 2px 8px rgba(47, 95, 232, 0.3);
}
.btn--primary:active:not(:disabled) { transform: translateY(1px); }
.btn--secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn--secondary:hover:not(:disabled) {
  background: var(--bg);
  border-color: #a9b3c1;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* ============================================================
   MULTI-SELECT DROPDOWN
   ============================================================ */
.multi-select { position: relative; }

.multi-select__button {
  font-family: inherit;
  font-size: 0.92rem;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  min-height: 2.4rem;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.multi-select__button:hover { border-color: #a9b3c1; }
.multi-select__button[aria-expanded="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.multi-select__button-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.multi-select__button--placeholder .multi-select__button-text {
  color: var(--text-soft);
}
.multi-select__chevron {
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.multi-select__button[aria-expanded="true"] .multi-select__chevron {
  transform: rotate(180deg);
}

.multi-select__panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  max-height: 320px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.multi-select__panel[hidden] { display: none !important; }

.multi-select__toolbar {
  padding: 0.5rem 0.55rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.multi-select__search {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: #fff;
  width: 100%;
}
.multi-select__search:focus {
  outline: none;
  border-color: var(--accent);
}
.multi-select__quick {
  display: flex;
  gap: 0.5rem;
  font-size: 0.75rem;
}
.multi-select__link {
  font-family: inherit;
  font-size: 0.75rem;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.1rem 0.2rem;
  font-weight: 500;
}
.multi-select__link:hover { text-decoration: underline; }

.multi-select__options {
  overflow-y: auto;
  flex: 1;
  padding: 0.2rem 0;
}
.multi-select__option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.7rem;
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.08s ease;
}
.multi-select__option:hover { background: var(--accent-soft); }
.multi-select__option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
  flex-shrink: 0;
  margin: 0;
}
.multi-select__option-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.multi-select__empty {
  padding: 0.75rem 0.7rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  font-style: italic;
}
.multi-select__option--hidden { display: none; }

/* ---------- Status & summary ---------- */
.status {
  margin-top: 1rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  min-height: 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.status::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-soft);
  flex-shrink: 0;
}
.status:empty::before { display: none; }
.status--error { color: var(--error); }
.status--error::before { background: var(--error); }
.status--success { color: var(--success); }
.status--success::before { background: var(--success); }
.status--loading::before {
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.result-summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.result-summary__count {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.3rem 0.7rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
}
.result-summary__chip {
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 0.25rem 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
}

/* ---------- Slips container & empty state ---------- */
.slips-container {
  max-width: 8.5in;
  margin: 1.5rem auto 3rem;
  padding: 0 0.5rem;
}
.empty-state {
  background: var(--bg-elevated);
  border: 1px dashed var(--border-strong);
  padding: 3.5rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  border-radius: var(--radius);
  font-size: 0.95rem;
}
.empty-state strong { color: var(--text); }

/* ============================================================
   THE SLIP
   ============================================================ */
.slip {
  background: #fff;
  border: 1.5px solid #1a1f2b;
  border-radius: 6px;
  padding: 0.5in 0.55in 0.45in;
  margin-bottom: 0.3in;
  display: flex;
  flex-direction: column;
  min-height: 5.5in;
  page-break-inside: avoid;
  break-inside: avoid;
  font-size: 13pt;
  color: #000;
  box-shadow: var(--shadow-sm);
}

.slip__header {
  border-bottom: 1.5px solid #1a1f2b;
  padding-bottom: 0.13in;
  margin-bottom: 0.13in;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.3in;
}
.slip__title-block { flex: 1; min-width: 0; }
.slip__title {
  font-size: 19pt;
  font-weight: 700;
  margin: 0 0 0.06in 0;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.slip__time {
  font-size: 14pt;
  font-weight: 600;
  margin: 0;
  color: #2a2f3b;
  display: flex;
  align-items: center;
  gap: 0.08in;
}
.slip__time-icon {
  font-size: 13pt;
  opacity: 0.7;
}
.slip__source-line {
  font-size: 11pt;
  font-weight: 500;
  margin: 0.04in 0 0 0;
  color: #4a4f5a;
}
.slip__stage {
  font-size: 11pt;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1.5px solid #1a1f2b;
  border-radius: 999px;
  padding: 0.06in 0.2in;
  white-space: nowrap;
  align-self: flex-start;
  background: #fff;
}
.slip__stage--success {
  background: #1a1f2b;
  color: #fff;
}
.slip__stage--warning {
  background: #fff;
  border-style: dashed;
}
.slip__stage--danger {
  background: #fff;
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
  opacity: 0.85;
}

.slip__body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3in;
  flex: 1;
}

.slip__section {
  margin-bottom: 0.1in;
}
.slip__section:last-child { margin-bottom: 0; }

.slip__section-title {
  font-size: 10pt;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #555;
  margin: 0 0 0.07in 0;
  padding-bottom: 0.03in;
  border-bottom: 1px solid #c9ccd1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.1in;
}
.slip__source-tag {
  font-size: 8pt;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: #8a6d00;
  background: #fff8d6;
  border: 1px solid #e6d36a;
  border-radius: 3px;
  padding: 0.01in 0.08in;
  font-style: italic;
}

.slip__field {
  margin: 0 0 0.05in 0;
  font-size: 12pt;
  line-height: 1.4;
}
.slip__field-label {
  font-weight: 600;
  color: #4a4f5a;
  font-size: 11pt;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: inline-block;
  min-width: 0.7in;
  margin-right: 0.05in;
}
.slip__name {
  font-size: 13.5pt;
  font-weight: 600;
  margin: 0 0 0.03in 0;
}
.slip__name + .slip__name {
  font-weight: 500;
  color: #2a2f3b;
}
.slip__name-amp {
  color: #888;
  font-weight: 400;
  margin-right: 0.04in;
}
.slip__address {
  font-size: 12.5pt;
  white-space: pre-line;
  margin: 0;
  line-height: 1.4;
}
.slip__address-icon {
  display: inline-block;
  margin-right: 0.04in;
  opacity: 0.6;
}
.slip__notes-text {
  font-size: 12pt;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-style: italic;
  color: #2a2f3b;
  line-height: 1.5;
  margin: 0;
}
.slip__empty {
  color: #999;
  font-style: italic;
  font-size: 12pt;
}

.slip__scribble {
  margin-top: 0.2in;
  padding-top: 0.1in;
  border-top: 1px dashed #888;
  flex: 1; /* fill remaining vertical space on the page */
  display: flex;
  flex-direction: column;
  min-height: 1.8in;
}
.slip__scribble-label {
  font-size: 10pt;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #555;
  margin-bottom: 0.1in;
  display: block;
}
.slip__scribble-lines {
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 0.32in,
    #c9ccd1 0.32in,
    #c9ccd1 calc(0.32in + 1px)
  );
  flex: 1;
  min-height: 1.5in;
}

/* ============================================================
   PRINT RULES
   ============================================================ */
@media print {
  @page {
    size: letter;
    margin: 0.4in;
  }

  html, body {
    background: #fff !important;
    color: #000 !important;
  }

  .no-print { display: none !important; }

  .slips-container {
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .slip {
    /* One slip per page: hard break after each. The slip's natural height
       fills based on content + flex-grow on the scribble area. Works in both
       portrait and landscape. */
    margin: 0;
    border: 1.5px solid #000 !important;
    background: #fff !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    page-break-inside: avoid;
    break-inside: avoid;
    page-break-after: always;
    break-after: page;
    /* In print, let the slip fill the available page height so the notes
       area has maximum room for handwriting. 100vh maps to the printable
       page height in modern browsers. */
    min-height: 100vh;
  }
  .slip:last-of-type {
    page-break-after: auto;
    break-after: auto;
  }
}
