:root {
  --bg: #fbf6ef;
  --bg-2: #f4ede3;
  --card: #ffffff;
  --text: #2b2018;
  --muted: #6f5b4a;
  --accent: #8b5a2b;
  --accent-2: #b27a4a;
  --line: #eadfd3;
  --shadow: 0 12px 30px rgba(43, 32, 24, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family:
    'Rubik',
    system-ui,
    -apple-system,
    sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, #fff8f1 0%, var(--bg) 45%, var(--bg-2) 100%);
}

body.order-modal-open {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  overflow: hidden;
}

.order-page {
  width: min(860px, 94vw);
  margin: 0 auto;
  padding: 1.2rem 0 2.4rem;
  display: grid;
  gap: 1rem;
}

.order-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
}

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

h1 {
  margin: 0.2rem 0 0;
  font-size: clamp(1.5rem, 3.4vw, 2.1rem);
}

.back-link {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  text-decoration: none;
  color: var(--accent);
  background: #fff;
  white-space: nowrap;
}

.delivered-warning {
  display: grid;
  gap: 0.55rem;
  border-color: #ecd8c3;
  background: linear-gradient(145deg, #fff7ee, #fff);
}

.delivered-warning strong {
  color: #5d4938;
}

.delivered-warning a {
  justify-self: start;
  border: 1px solid #d6c0a8;
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  color: var(--accent);
  text-decoration: none;
  background: #fff;
  font-weight: 500;
}

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

.not-found {
  text-align: center;
}

.not-found h2 {
  margin-top: 0;
}

.status-card {
  display: grid;
  gap: 0.75rem;
}

.status-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.label {
  margin: 0 0 0.2rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 130px;
  border-radius: 999px;
  padding: 0.45rem 1rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
}

.status-badge.new {
  background: #1b7e45;
}

.status-badge.in_progress {
  background: #a56a00;
}

.status-badge.ready {
  background: #0b6fa3;
}

.status-badge.delivered {
  background: #4d4d4d;
}

.status-badge.cancelled {
  background: #9b2f2f;
}

.live-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.cancelled-note {
  margin: 0;
  background: #fde7e7;
  color: #8f1e1e;
  border: 1px solid #f3caca;
  border-radius: 12px;
  padding: 0.55rem 0.7rem;
  font-weight: 500;
}

.status-timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.status-timeline li {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.4rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  background: #fff8f1;
}

.status-timeline li.is-complete {
  border-color: #d5c1ad;
  color: #5d4938;
  background: #f4e6d7;
}

.status-timeline li.is-current {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.info-grid {
  display: grid;
  gap: 0.7rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.items-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
}

.item-row {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 0.65rem;
}

.item-top {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: flex-start;
}

.item-sub {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.total-row {
  margin-top: 0.75rem;
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.05rem;
}

.replies-card {
  display: grid;
  gap: 0.62rem;
}

.replies-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.replies-head h2 {
  margin: 0;
  font-size: 1.12rem;
}

.chat-head-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.replies-live-note {
  color: var(--muted);
  font-size: 0.86rem;
}

.chat-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 0.62rem;
  border-radius: 999px;
  background: #8f1e1e;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
}

.replies-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.chat-thread .replies-empty {
  padding: 0.7rem;
}

.chat-thread {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdf9;
  overflow: hidden;
}

.chat-messages-list {
  list-style: none;
  margin: 0;
  padding: 0.7rem;
  display: grid;
  gap: 0.5rem;
  max-height: 280px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.chat-message-item {
  display: grid;
  gap: 0.22rem;
}

.chat-message-bubble {
  max-width: min(100%, 430px);
  border-radius: 14px;
  border: 1px solid #e2d6ca;
  padding: 0.52rem 0.66rem;
  background: #fff;
  justify-self: end;
}

.chat-message-item.customer .chat-message-bubble {
  background: #f4ebe0;
  border-color: #e0cdb8;
  justify-self: start;
}

.chat-message-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-message-meta {
  color: var(--muted);
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.chat-compose {
  border-top: 1px solid var(--line);
  background: #fff;
  padding: 0.62rem;
  display: grid;
  gap: 0.4rem;
}

.chat-compose label {
  font-size: 0.86rem;
  color: var(--muted);
}

.chat-compose textarea {
  width: 100%;
  min-height: 78px;
  resize: vertical;
  font: inherit;
  border-radius: 10px;
  border: 1px solid #d9cdbf;
  padding: 0.5rem 0.62rem;
  background: #fff;
}

.chat-compose-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
}

#chatCharCount {
  color: var(--muted);
  font-size: 0.82rem;
}

#chatCharCount.is-limit {
  color: #8f1e1e;
  font-weight: 600;
}

#chatSendBtn {
  border: 0;
  border-radius: 999px;
  min-height: 40px;
  padding: 0.35rem 0.95rem;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

#chatSendBtn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.chat-error {
  margin: 0;
  min-height: 1.1rem;
  color: #8f1e1e;
  font-size: 0.84rem;
}

.delivered-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 23, 16, 0.48);
  opacity: 0;
  transition: opacity 0.22s ease;
  z-index: 89;
}

.delivered-modal-backdrop.show {
  opacity: 1;
}

.delivered-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -44%);
  width: min(430px, calc(100vw - 2rem));
  background: #fff;
  border: 1px solid #e3d2c0;
  border-radius: 18px;
  box-shadow: 0 20px 48px rgba(43, 32, 24, 0.28);
  padding: 1rem;
  z-index: 90;
  opacity: 0;
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
}

.delivered-modal.show {
  opacity: 1;
  transform: translate(-50%, -50%);
}

.delivered-modal h2 {
  margin: 0 0 0.35rem;
  font-size: 1.4rem;
}

.delivered-modal p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.delivered-modal-actions {
  margin-top: 0.95rem;
  display: flex;
  gap: 0.55rem;
}

.delivered-modal-actions button {
  flex: 1;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.delivered-modal-actions .btn-primary {
  background: var(--accent);
  color: #fff;
}

.delivered-modal-actions .btn-secondary {
  background: #fff;
  color: var(--accent);
  border-color: #d8c3ad;
}

.delivered-modal-actions button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(139, 90, 43, 0.3);
}

.order-toast {
  position: fixed;
  left: 50%;
  bottom: calc(0.8rem + env(safe-area-inset-bottom));
  transform: translate(-50%, 10px);
  background: #2b2018;
  color: #fff;
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  font-size: 0.92rem;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
  z-index: 95;
}

.order-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.new-reply-toast {
  position: fixed;
  top: calc(0.9rem + env(safe-area-inset-top));
  left: 50%;
  transform: translate(-50%, -10px);
  z-index: 97;
  background: #2b2018;
  color: #fff;
  border-radius: 14px;
  padding: 0.55rem 0.7rem;
  min-width: min(320px, calc(100vw - 1.2rem));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  box-shadow: 0 18px 40px rgba(24, 18, 13, 0.3);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.new-reply-toast.show {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.new-reply-toast p {
  margin: 0;
  font-size: 0.9rem;
}

.new-reply-toast button {
  border: 1px solid #ccb299;
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  font: inherit;
  font-size: 0.88rem;
  padding: 0.3rem 0.72rem;
  cursor: pointer;
}

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

  .order-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .status-timeline {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .replies-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .chat-compose-foot {
    flex-direction: column;
    align-items: stretch;
  }

  .new-reply-toast {
    min-width: calc(100vw - 1.2rem);
  }
}
