/* Stack & Track — visuals refresh */
:root {
  --brand-red: #dc2626;
  --brand-red-dark: #991b1b;
  --brand-navy: #253a5c;
  --brand-cream: #fdf7ec;
  --brand-wood: #6b4423;
  --brand-wood-soft: #8a6238;
  --text-strong: #211610;
  --text-soft: #6b6355;
  --line: #e8ddc9;
  --stat-blue: #e0edff;
  --stat-amber: #fff2cc;
  --stat-green: #dff5e0;
  --stat-rose: #fde2e2;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(220, 38, 38, 0.06), transparent 45%),
    radial-gradient(circle at 88% 6%, rgba(37, 58, 92, 0.06), transparent 45%),
    var(--brand-cream);
  color: var(--text-strong);
  margin: 0;
  padding: 0 0 60px;
  min-height: 100vh;
}

/* ---------- Header ---------- */
header {
  background: linear-gradient(90deg, var(--brand-navy) 0%, #17233b 60%, var(--brand-red) 100%);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  position: sticky;
  top: 0;
  z-index: 20;
}
header h1 {
  margin: 0;
  font-size: 1.45rem;
  flex: 1;
  min-width: 120px;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}
.brand-logo {
  height: 42px;
  width: auto;
  background: #fff;
  padding: 4px 8px;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.header-actions { margin-left: 8px; }
#user-info {
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.15);
  padding: 4px 10px;
  border-radius: 999px;
}

main { max-width: 1200px; margin: 22px auto; padding: 0 16px; }

/* ---------- Cards ---------- */
.card {
  background: #fff;
  border-radius: 12px;
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: 0 4px 14px rgba(60, 40, 20, 0.08);
  border: 1px solid var(--line);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.card:hover { box-shadow: 0 8px 22px rgba(60, 40, 20, 0.12); }

/* ---------- Hero ---------- */
.hero {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 22px 28px;
  background:
    radial-gradient(circle at 100% 50%, rgba(220, 38, 38, 0.08), transparent 55%),
    linear-gradient(135deg, #fff8ea 0%, #ffe9d1 100%);
  border: 1px solid #f2d9b3;
}
.hero-text { flex: 1; min-width: 200px; }
.hero-text h2 {
  margin: 0 0 6px;
  font-size: 1.7rem;
  color: var(--brand-red-dark);
  letter-spacing: 0.02em;
}
.hero-text p {
  margin: 0;
  font-size: 1rem;
  color: var(--text-soft);
  max-width: 520px;
}
.hero-mascot {
  height: 130px;
  width: auto;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.12));
  transition: transform 0.3s ease;
}
.hero-mascot:hover { transform: translateY(-4px) rotate(-2deg); }

/* ---------- Dashboard tiles ---------- */
.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  padding: 18px;
}
.stat {
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  border: 1px solid rgba(0, 0, 0, 0.04);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.stat:hover { transform: translateY(-3px); box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08); }
.stat-today   { background: var(--stat-blue); }
.stat-pending { background: var(--stat-amber); }
.stat-sheets  { background: var(--stat-green); }
.stat-age     { background: var(--stat-rose); }
.stat-value { font-size: 1.9rem; font-weight: 700; color: var(--brand-navy); line-height: 1.1; }
.stat-label { font-size: 0.85rem; color: var(--text-soft); margin-top: 6px; font-weight: 600; }

/* ---------- Form ---------- */
#form-card h2 {
  margin: 0 0 14px;
  color: var(--brand-navy);
  border-left: 4px solid var(--brand-red);
  padding-left: 10px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  font-weight: 600;
  gap: 4px;
  color: #3d2a1a;
}
label.full { grid-column: 1 / -1; }
label.inline-date { flex-direction: row; align-items: center; gap: 6px; }

input, select, textarea, button {
  font-size: 1rem;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid #d5c7ae;
  font-family: inherit;
  min-height: 42px;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-red);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

button, a#export-link {
  background: linear-gradient(180deg, var(--brand-red) 0%, var(--brand-red-dark) 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  padding: 10px 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 3px 8px rgba(153, 27, 27, 0.25);
}
button:hover:not(:disabled), a#export-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 12px rgba(153, 27, 27, 0.35);
}
button.secondary {
  background: #fff;
  color: var(--brand-navy);
  border: 1px solid var(--brand-navy);
  box-shadow: none;
}
button.secondary:hover:not(:disabled) {
  background: var(--brand-navy);
  color: #fff;
}
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

a#export-link {
  display: inline-block;
  text-decoration: none;
  padding: 9px 14px;
  border-radius: 8px;
  min-height: 42px;
  line-height: 24px;
}

.form-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; justify-content: flex-end; }

.error { color: var(--brand-red-dark); font-weight: 600; }
.warning {
  background: #fff8e1;
  border: 1px solid #f2c94c;
  color: #7a5b00;
  padding: 12px 14px;
  border-radius: 8px;
  margin-top: 12px;
  font-weight: 600;
}
.hidden { display: none !important; }

/* ---------- Toolbar / table ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar h2 {
  margin: 0 auto 0 0;
  color: var(--brand-navy);
  border-left: 4px solid var(--brand-red);
  padding-left: 10px;
}
.toolbar input[type="search"] { min-width: 220px; flex: 1 1 220px; }

.table-wrap {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
}
table { width: 100%; border-collapse: collapse; margin-top: 0; font-size: 0.9rem; background: #fff; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #f0e6d1; white-space: nowrap; }
thead th {
  position: sticky;
  top: 0;
  background: #f7ebd3;
  color: var(--brand-navy);
  font-weight: 700;
  border-bottom: 2px solid var(--brand-wood-soft);
}
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { background: #f3e0be; }
th[data-sort] .arrow { font-size: 0.75rem; margin-left: 4px; color: var(--brand-red); }
tbody tr { transition: background 0.15s ease; }
tbody tr:nth-child(even) { background: #fdfaf1; }
tbody tr:hover { background: #fff2d8; }
td .row-btn { padding: 4px 10px; min-height: 32px; font-size: 0.85rem; margin-right: 4px; border-radius: 6px; }

/* Priority + status colouring */
td.priority-P0 { color: var(--brand-red-dark); font-weight: 700; }
td.priority-P1 { color: #9a6b00; font-weight: 700; }
td.priority-P2 { color: #4b4b4b; }
td.status-Ready { color: #167a2a; font-weight: 700; }
td.status-Delivered { color: #6b6355; font-weight: 700; text-decoration: line-through; }

/* Due-date badges */
td.due-overdue {
  color: #fff;
  background: var(--brand-red);
  font-weight: 700;
  border-radius: 4px;
  padding: 6px 8px;
  text-align: center;
}
td.due-today {
  color: var(--brand-red-dark);
  font-weight: 700;
}

/* Row actions layout */
td.row-actions { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.row-btn.success {
  background: linear-gradient(180deg, #22a34e 0%, #167a2a 100%);
  color: #fff;
  border: none;
  box-shadow: 0 2px 6px rgba(22, 122, 42, 0.25);
}
.row-btn.success:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(22, 122, 42, 0.35); }
.row-btn.wa {
  background: #25d366;
  border-color: #128c7e;
  color: #fff;
  padding: 4px 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(37, 211, 102, 0.35);
}
.row-btn.wa:hover { background: #128c7e; transform: translateY(-1px); }

.pagination { display: flex; align-items: center; gap: 12px; margin-top: 14px; justify-content: center; }
#summary { font-weight: 600; margin-top: 8px; text-align: center; color: var(--text-soft); }

/* ---------- Empty state ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 22px 12px;
  color: var(--text-soft);
  font-weight: 600;
}
.empty-mascot { height: 130px; width: auto; opacity: 0.9; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1)); }

/* ---------- Delete modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 10, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fade 0.15s ease;
}
.modal-card {
  background: #fff;
  border-radius: 12px;
  padding: 22px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  border-top: 4px solid var(--brand-red);
}
.modal-card h3 { margin: 0 0 8px; color: var(--brand-red-dark); }
.modal-card textarea { width: 100%; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 16px; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

/* ---------- Login ---------- */
.login-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}
.login-shell {
  display: flex;
  gap: 24px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 780px;
}
.login-hero {
  flex: 0 1 300px;
  text-align: center;
  color: var(--text-soft);
}
.login-hero-img {
  max-width: 260px;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.15));
}
.login-hero blockquote {
  margin: 12px 0 0;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--brand-navy);
  border-left: 3px solid var(--brand-red);
  padding-left: 10px;
  text-align: left;
}
.login-card {
  width: 340px;
  text-align: center;
  border-top: 4px solid var(--brand-red);
}
.login-card h1 {
  margin: 6px 0 0;
  color: var(--brand-navy);
  letter-spacing: 0.03em;
}
.login-card p { color: var(--text-soft); margin: 4px 0 8px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.login-logo { max-width: 210px; height: auto; margin-bottom: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 700px) {
  header {
    flex-wrap: nowrap;
    gap: 8px;
    padding: 10px 14px;
  }
  header h1 { font-size: 1.05rem; min-width: 0; letter-spacing: 0.01em; }
  .brand-logo { height: 32px; padding: 3px 5px; }
  #user-info { display: none; }
  #logout-btn { padding: 6px 10px; font-size: 0.85rem; margin-left: auto; }
  .hero { flex-direction: column-reverse; text-align: center; }
  .hero-text p { margin-left: auto; margin-right: auto; }
  .hero-mascot { height: 110px; }

  /* Stacked-card view for the orders table on phones. */
  .table-wrap { border: none; overflow: visible; }
  #orders-table thead { display: none; }
  #orders-table, #orders-table tbody, #orders-table tr, #orders-table td {
    display: block;
    width: 100%;
    white-space: normal;
  }
  #orders-table tr {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 3px 10px rgba(60, 40, 20, 0.08);
    padding: 12px 14px;
    margin-bottom: 14px;
    border-left: 4px solid transparent;
    border-bottom: none;
  }
  #orders-table tr.row-overdue { border-left-color: var(--brand-red); }
  #orders-table tr:nth-child(even) { background: #fff; }
  #orders-table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 0;
    border: none;
    gap: 12px;
  }
  #orders-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-soft);
    flex: 0 0 40%;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  #orders-table td:empty, #orders-table td[data-label=""]:empty { display: none; }
  #orders-table td.row-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    padding-top: 10px;
    margin-top: 6px;
    border-top: 1px solid var(--line);
    gap: 6px;
  }
  #orders-table td.row-actions::before { display: none; }
  #orders-table td.due-overdue {
    background: transparent;
    color: var(--brand-red);
    padding: 4px 0;
  }

  /* Sticky "Save Order" bar on phones */
  #form-card .form-actions {
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, transparent, #fff 30%);
    padding: 12px 0 0;
    margin-left: -22px;
    margin-right: -22px;
    padding-left: 22px;
    padding-right: 22px;
    z-index: 5;
  }
}
@media (max-width: 600px) {
  .grid { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar h2 { margin: 0 0 6px; }
  .toolbar input[type="search"] { flex: none; min-width: 0; width: 100%; }
  .form-actions { justify-content: stretch; }
  .form-actions button { flex: 1; }
  .login-shell { flex-direction: column; }
  td .row-btn { min-height: 40px; padding: 6px 10px; }
  .stat-value { font-size: 1.5rem; }
  input, select, textarea, button { min-height: 44px; font-size: 16px; }
}

/* ---------- Toasts ---------- */
.toast-host {
  position: fixed;
  top: 76px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 340px;
  pointer-events: none;
}
.toast {
  background: #253a5c;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  transform: translateX(120%);
  transition: transform 0.25s ease;
  pointer-events: auto;
}
.toast-show { transform: translateX(0); }
.toast-success { background: linear-gradient(135deg, #22a34e, #167a2a); }
.toast-error   { background: linear-gradient(135deg, #dc2626, #991b1b); }
.toast-info    { background: linear-gradient(135deg, #253a5c, #17233b); }

/* ---------- Login password toggle ---------- */
.password-wrap { position: relative; display: block; }
.password-wrap input { width: 100%; padding-right: 44px; }
.password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  min-height: 32px;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 10px;
  box-shadow: none;
  color: var(--text-soft);
}
.password-toggle:hover { background: transparent; color: var(--brand-navy); transform: translateY(-50%); box-shadow: none; }

