/* ===================================================
   MOBILE-FIRST: base targets 360px (Samsung A11 ~360 CSS px @ 2x DPR)
   Breakpoints: 480px (larger phones), 768px (tablet), 960px (desktop)
=================================================== */

:root {
  --sidebar-bg:    #1a202c;
  --sidebar-width: 260px;
  --card-radius:   10px;
  --gap:           12px;
  --padding:       14px;
  --text-primary:  #2d3748;
  --text-muted:    #718096;
  --border:        #e2e8f0;
  --blue:          #4299e1;
  --green:         #38a169;
  --red:           #e53e3e;
  --shadow:        0 2px 8px rgba(0,0,0,0.10);
  --gradient:      linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  /* Touch minimum */
  --touch: 44px;
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  /* Prevent font boosting on Android */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text-primary);
  background: #f0f2f5;
  /* Disable double-tap zoom on buttons */
  touch-action: manipulation;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ====================================================
   LOGIN SCREEN
==================================================== */
.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient);
  padding: 16px;
}

.login-container {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-container h1 {
  color: white;
  font-size: 22px;
  text-align: center;
  font-weight: 700;
}

.login-form {
  background: white;
  padding: 24px 20px;
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-form input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 16px; /* 16px prevents iOS zoom-on-focus */
  transition: border-color 0.2s;
  min-height: var(--touch);
}

.login-form input:focus {
  outline: none;
  border-color: var(--blue);
}

.remember-me {
  display: flex;
  align-items: center;
  gap: 8px;
}

.remember-me input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--blue);
}

.remember-me label {
  font-size: 14px;
  color: #4a5568;
  cursor: pointer;
  user-select: none;
}

.credentials-info {
  background: white;
  padding: 16px;
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
}

.credentials-info p {
  color: #666;
  font-size: 13px;
  margin-bottom: 3px;
}

.error {
  color: var(--red);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

/* ====================================================
   APP LAYOUT — two-column on desktop, stacked on mobile
==================================================== */
.app-layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}

/* ====================================================
   CHAT SIDEBAR
==================================================== */
.chat-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  position: sticky;
  top: 0;
  overflow: hidden;
  flex-shrink: 0;
  transition: width 0.3s ease, min-width 0.3s ease;
  z-index: 10;
}

/* Desktop collapsed state */
.chat-sidebar.collapsed {
  width: 0;
  min-width: 0;
}

.chat-header {
  padding: 12px 14px;
  border-bottom: 1px solid #2d3748;
  flex-shrink: 0;
}

.chat-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.chat-header h3 {
  color: #e2e8f0;
  font-size: 15px;
  white-space: nowrap;
}

.chat-close-btn {
  background: transparent;
  color: #a0aec0;
  border: none;
  padding: 4px 6px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  border-radius: 4px;
  min-height: unset;
  flex-shrink: 0;
}

.chat-close-btn:hover {
  background: #2d3748;
  color: white;
}

.chat-clear-info {
  font-size: 10px;
  color: #4a5568;
  white-space: nowrap;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overscroll-behavior: contain;
}

.chat-messages::-webkit-scrollbar { width: 3px; }
.chat-messages::-webkit-scrollbar-track { background: var(--sidebar-bg); }
.chat-messages::-webkit-scrollbar-thumb { background: #4a5568; border-radius: 2px; }

.chat-empty {
  color: #4a5568;
  font-size: 12px;
  text-align: center;
  margin-top: 20px;
  font-style: italic;
}

.chat-msg {
  background: #2d3748;
  border-radius: 6px;
  padding: 7px 9px;
}

.chat-msg-header {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 3px;
}

.chat-role-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.role-admin    { background: #c05621; color: white; }
.role-receiver { background: #2b6cb0; color: white; }
.role-writer   { background: #276749; color: white; }

.chat-username {
  font-size: 11px;
  font-weight: 600;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-time {
  font-size: 10px;
  color: #718096;
  margin-left: auto;
  white-space: nowrap;
  flex-shrink: 0;
}

.chat-msg-text {
  font-size: 12px;
  color: #cbd5e0;
  word-break: break-word;
  line-height: 1.4;
}

.chat-msg-other {
  cursor: pointer;
  transition: background 0.15s;
}
.chat-msg-other:hover { background: #374151; }

.chat-read-indicator {
  font-size: 9px;
  color: transparent;
  text-align: right;
  margin-top: 2px;
  min-height: 12px;
  transition: color 0.2s;
}
.chat-read-indicator.read { color: #68d391; }

.chat-input-area {
  padding: 10px;
  border-top: 1px solid #2d3748;
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.chat-input-area input {
  flex: 1;
  padding: 9px 10px;
  background: #2d3748;
  border: 1px solid #4a5568;
  border-radius: 5px;
  color: #e2e8f0;
  font-size: 13px;
  min-height: var(--touch);
}

.chat-input-area input:focus {
  outline: none;
  border-color: var(--blue);
}

.chat-input-area input::placeholder { color: #718096; }

.chat-input-area button {
  padding: 9px 12px;
  font-size: 13px;
  background: var(--blue);
  min-height: var(--touch);
  flex-shrink: 0;
}

.chat-input-area button:hover { background: #3182ce; }

/* Chat toggle open-button (visible when sidebar collapsed on desktop) */
.chat-open-btn {
  display: none;
  position: fixed;
  left: 8px;
  top: 12px;
  z-index: 300;
  background: var(--sidebar-bg);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  min-height: var(--touch);
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

.chat-open-btn.visible {
  display: flex;
}

/* Overlay for mobile chat */
.chat-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 50;
  backdrop-filter: blur(2px);
}
.chat-overlay.visible { display: block; }

/* ====================================================
   MAIN CONTENT AREA
==================================================== */
.main-content {
  flex: 1;
  overflow-y: auto;
  background: var(--gradient);
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--padding);
  min-width: 0; /* prevent flex blowout */
}

.screen-panel {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ====================================================
   CARDS
==================================================== */
.card {
  background: white;
  border-radius: var(--card-radius);
  padding: var(--padding);
  box-shadow: var(--shadow);
}

/* ====================================================
   HEADER
==================================================== */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  padding: 12px var(--padding);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
  gap: 10px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

header h1 {
  color: #4a5568;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Chat toggle button (in header) */
.chat-toggle-btn {
  background: var(--sidebar-bg);
  color: white;
  border: none;
  padding: 0;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
.chat-toggle-btn:hover { background: #2d3748; }

.logout-btn {
  background: #e53e3e;
  color: white;
  border: none;
  padding: 0 14px;
  height: 40px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.2s;
}
.logout-btn:hover { background: #c53030; }

/* ====================================================
   SHARED BUTTON STYLES
==================================================== */
button {
  background: var(--blue);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  min-height: var(--touch);
  transition: background 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}

button:hover { background: #3182ce; }
button:active { opacity: 0.85; }

button.delete-btn {
  background: var(--red);
  padding: 7px 12px;
  font-size: 12px;
  min-height: 36px;
}
button.delete-btn:hover { background: #c53030; }

button.cancel-btn {
  background: #dd6b20;
  padding: 8px 12px;
  font-size: 13px;
  min-height: 38px;
}
button.cancel-btn:hover { background: #c05621; }

button.complete-btn {
  background: var(--green);
  padding: 8px 12px;
  font-size: 13px;
  min-height: 38px;
}
button.complete-btn:hover { background: #2f855a; }

.clear-history-btn {
  background: var(--red);
  padding: 8px 14px;
  font-size: 13px;
  min-height: 36px;
}
.clear-history-btn:hover { background: #c53030; }

.btn-download {
  display: inline-flex;
  align-items: center;
  background: var(--green);
  color: white;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  min-height: 36px;
  transition: background 0.2s;
}
.btn-download:hover { background: #2f855a; }

/* ====================================================
   FORMS — shared inputs
==================================================== */
input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 15px; /* prevents iOS zoom */
  font-family: inherit;
  color: var(--text-primary);
  background: white;
  transition: border-color 0.2s;
  min-height: var(--touch);
  -webkit-appearance: none;
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
}

input::placeholder, textarea::placeholder { color: #a0aec0; }

textarea {
  min-height: 70px;
  resize: vertical;
}

/* ====================================================
   SECTION HEADER WITH BUTTON
==================================================== */
.section-header-with-button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.section-header-with-button h2 { margin-bottom: 0; }

/* card-header already provides margin-bottom; don't double it */
.card-header .section-header-with-button { margin-bottom: 0; }

h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
}

h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
}

/* ====================================================
   QUICK ORDER — category groups + colour buttons
==================================================== */
.quick-order-section {
  background: white;
  border-radius: var(--card-radius);
  padding: var(--padding);
  box-shadow: var(--shadow);
}

.category-group {
  margin-bottom: 14px;
}
.category-group:last-child { margin-bottom: 0; }

.category-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid;
  opacity: 0.85;
}

.category-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}

.menu-btn {
  background: var(--green);
  color: white;
  border: none;
  padding: 12px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: filter 0.15s, transform 0.1s;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  -webkit-tap-highlight-color: transparent;
}

.menu-btn:hover  { filter: brightness(0.88); }
.menu-btn:active { transform: scale(0.96); }

.btn-name { font-size: 13px; font-weight: 600; line-height: 1.2; word-break: break-word; }
.btn-qty  { font-size: 11px; opacity: 0.85; }

/* ====================================================
   ORDER FORM (custom order)
==================================================== */
.order-form.card h2 { margin-bottom: 10px; }

.form-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.order-form.card input,
.order-form.card textarea {
  margin-bottom: 8px;
}

.order-form.card input:last-of-type,
.order-form.card textarea:last-of-type { margin-bottom: 0; }

/* ====================================================
   ORDERS LIST
==================================================== */
/* h2 inside .card-body already gets spacing from parent card-header margin */
.orders-list .card-body,
.orders-history .card-body {
  padding-top: 0;
}

.order-item {
  background: #f7fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.order-item:last-child { margin-bottom: 0; }

.order-item-main {
  flex: 1;
  min-width: 0;
}

.order-item h3 {
  color: var(--text-primary);
  margin-bottom: 4px;
  font-size: 15px;
}

.order-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #666;
  flex-wrap: wrap;
}

.quantity-highlight {
  font-weight: 800;
  font-size: 20px;
  color: var(--text-primary);
  line-height: 1;
}

.order-time {
  font-size: 11px;
  color: var(--text-muted);
}

.order-notes {
  font-size: 12px;
  font-style: italic;
  color: #666;
  margin-top: 4px;
}

.order-actions {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  padding-top: 2px;
}

.order-item.completed {
  background: #f0fff4;
  border-color: #9ae6b4;
  border-left: 3px solid var(--green);
}

/* ====================================================
   ADMIN — CATEGORY MANAGEMENT
==================================================== */
.category-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 14px;
}

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.color-picker-row label {
  font-size: 13px;
  color: var(--text-muted);
}

.color-input {
  width: 44px;
  height: 44px;
  padding: 2px;
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  background: none;
  -webkit-appearance: none;
  min-height: unset;
}

.color-input-inline {
  width: 36px;
  height: 36px;
  padding: 1px;
  flex-shrink: 0;
}

.categories-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.category-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f7fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.category-color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.1);
}

.category-item-name {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  min-width: 0;
}

/* ====================================================
   ADMIN — MENU ITEM MANAGEMENT
==================================================== */
.menu-management h2,
.menu-management h3 { margin-bottom: 12px; }

.menu-form {
  display: grid;
  grid-template-columns: 1fr 1fr 80px auto;
  gap: 8px;
  margin-bottom: 16px;
  align-items: end;
}

.category-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M6 8L0 0h12z' fill='%23718096'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 10px;
  padding-right: 32px;
}

.menu-item {
  background: #f7fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu-item-info {
  flex: 1;
  min-width: 0;
}

.menu-item-info h4 {
  color: var(--text-primary);
  margin-bottom: 2px;
  font-size: 14px;
}

.menu-item-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* ====================================================
   ORDERS OVERVIEW (admin)
==================================================== */
.orders-overview h2 { margin-bottom: 12px; }

/* ====================================================
   DAILY HISTORY PANEL
==================================================== */
.daily-history-panel h2 { margin-bottom: 12px; }

.history-accordion {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.history-accordion-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.history-accordion-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  background: #f7fafc;
  user-select: none;
  transition: background 0.15s;
  min-height: var(--touch);
}

.history-accordion-header:hover { background: #edf2f7; }

.history-accordion-item.open .history-accordion-header {
  background: #ebf8ff;
  border-bottom: 1px solid #bee3f8;
}

.history-day-arrow {
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
  width: 12px;
}

.history-day-label {
  flex: 1;
  font-weight: 600;
  color: var(--text-primary);
  font-size: 13px;
}

.history-day-badge {
  font-size: 11px;
  color: #2b6cb0;
  background: #ebf8ff;
  border: 1px solid #bee3f8;
  padding: 2px 7px;
  border-radius: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.history-day-badge.empty {
  color: var(--text-muted);
  background: #f7fafc;
  border-color: var(--border);
}

.history-accordion-body {
  padding: 10px 12px;
  background: white;
}

.history-items {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f7fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
}

.history-item-name {
  flex: 1;
  font-weight: 500;
  font-size: 13px;
  color: var(--text-primary);
  min-width: 0;
}

.history-item-qty {
  font-weight: 700;
  font-size: 14px;
  color: #2b6cb0;
  white-space: nowrap;
}

.history-item-count {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.history-delete-btn {
  padding: 4px 10px;
  font-size: 11px;
  min-height: 28px;
  margin-left: auto;
  flex-shrink: 0;
}

/* Cafe source label on order items and history rows */
.order-cafe-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
  flex-shrink: 0;
  margin-bottom: 3px;
}

.cafe-tag-cafe24 { background: #ebf8ff; color: #2b6cb0; border: 1px solid #bee3f8; }
.cafe-tag-cafe12 { background: #faf5ff; color: #6b46c1; border: 1px solid #d6bcfa; }

/* Make history-item a flex container so the cafe tag sits inline */
.history-item {
  flex-wrap: wrap;
  gap: 6px;
}
.history-item .order-cafe-tag { margin-bottom: 0; }

/* ====================================================
   COLLAPSIBLE CARDS
==================================================== */

/* card-header: flex row that holds the title + toggle/actions */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.card-header h2,
.card-header h3 { margin-bottom: 0; flex: 1; }

/* cards with action buttons: header is NOT fully-clickable; only the toggle btn is */
.card-header.card-header-actions { cursor: default; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* small toggle button (used when header has other action buttons) */
.toggle-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0 8px;
  font-size: 11px;
  min-height: 32px;
  border-radius: 5px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.toggle-btn:hover { background: #edf2f7; color: var(--text-primary); }

/* inline arrow icon inside either a plain .card-header or a .toggle-btn */
.toggle-icon {
  display: inline-block;
  font-size: 11px;
  color: var(--text-muted);
  transition: transform 0.2s;
  line-height: 1;
}

/* collapsed state: hide body, rotate icon */
.collapsed .card-body { display: none; }
.collapsed .toggle-icon { transform: rotate(-90deg); }

/* small download button variant */
.btn-sm {
  padding: 5px 9px;
  font-size: 11px;
  min-height: 32px;
}

/* ====================================================
   SECTION HINT
==================================================== */
.section-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-style: italic;
}

/* ====================================================
   KITCHEN PRODUCTION TOTALS
==================================================== */
.production-totals-section {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.production-totals-section h3 { margin-bottom: 10px; }

.production-totals {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.production-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f0fff4;
  border: 1px solid #9ae6b4;
  border-radius: 6px;
  padding: 8px 12px;
}

.production-item-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  margin-right: 8px;
}

.production-item-qty {
  font-weight: 800;
  font-size: 20px;
  color: var(--green);
  line-height: 1;
}

/* flash feedback on prod button tap */
.prod-btn-flash {
  filter: brightness(1.3) !important;
  transform: scale(0.94);
}

/* ====================================================
   WRITER PRODUCTION TABLE
==================================================== */
.prod-saved-note {
  font-size: 11px;
  color: var(--green);
  font-style: italic;
  margin-bottom: 8px;
}

/* Nightly wipe end-of-day banner (admin only) */
.nightly-wipe-banner {
  position: relative;
  background: linear-gradient(135deg, #1a365d, #2b4c7e);
  border: 1px solid #4299e1;
  border-radius: 8px;
  padding: 14px 40px 14px 16px;
  margin: 12px 0;
  animation: slideDownFade 0.4s ease;
}
.nightly-wipe-banner strong {
  display: block;
  color: #90cdf4;
  font-size: 13px;
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
.nightly-wipe-banner p {
  margin: 2px 0;
  font-size: 12px;
  color: #bee3f8;
}
.nightly-wipe-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: transparent;
  border: none;
  color: #90cdf4;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.nightly-wipe-close:hover { background: rgba(255,255,255,0.1); }
@keyframes slideDownFade {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.prod-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 4px;
}

.prod-table {
  min-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.prod-table-head,
.prod-table-row {
  display: grid;
  grid-template-columns: 1fr 56px 56px 56px 72px 56px;
  gap: 4px;
  align-items: center;
}

.prod-table-head {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 4px 8px;
  background: #f7fafc;
  border-radius: 5px;
  border: 1px solid var(--border);
}

.prod-table-head span { text-align: center; }
.prod-table-head span:first-child { text-align: left; }

.prod-table-row {
  background: #f7fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}

.prod-cell-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prod-cell-num {
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  color: var(--text-muted);
}

.prod-cell-total { color: #2b6cb0; font-weight: 700; }
.prod-cell-final { color: var(--green); font-weight: 800; font-size: 15px; }

.prod-cell-waste {
  display: flex;
  justify-content: center;
}

/* waste number input inside the table */
.waste-input {
  width: 60px;
  padding: 4px 6px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: white;
  color: #c05621;
  min-height: 32px;
  -webkit-appearance: none;
  appearance: textfield;
}

.waste-input:focus { border-color: #dd6b20; outline: none; }
.waste-input.waste-over { border-color: var(--red); background: #fff5f5; }

/* waste section below the table */
.waste-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.waste-section h3 { margin-bottom: 6px; color: #c05621; }

.save-production-btn {
  margin-top: 14px;
  width: 100%;
  background: #2b6cb0;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.2s;
}
.save-production-btn:hover { background: #2c5282; }

/* ====================================================
   WEEK TAB BAR
==================================================== */
.week-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.week-tab {
  flex: 1;
  min-width: 52px;
  padding: 8px 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  line-height: 1.3;
  transition: color 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.week-tab:hover { color: var(--text-primary); }

.week-tab.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

.week-tab.today { color: var(--green); }

.week-tab.today.active {
  color: var(--green);
  border-bottom-color: var(--green);
}

.tab-date {
  font-size: 10px;
  font-weight: 400;
  opacity: 0.75;
}

.week-tab-content { padding-top: 12px; }

.waste-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.waste-actions .save-production-btn {
  margin-top: 0;
  width: auto;
  padding: 9px 20px;
}

.prod-cell-final.negative { color: var(--red); }

.no-prod .prod-cell-name {
  color: var(--text-muted);
  font-style: italic;
}

/* ====================================================
   ADMIN WEEKLY SUMMARY TABLE
==================================================== */
.weekly-summary {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.summary-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 8px;
}

.summary-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 400px;
}

.summary-table th {
  text-align: center;
  padding: 5px 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: #f7fafc;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.summary-table th:first-child { text-align: left; }

.summary-table td {
  padding: 4px 5px;
  border: 1px solid var(--border);
  text-align: center;
  vertical-align: middle;
}

.summary-table td:first-child { text-align: left; }

.summary-table .today-col { background: #f0fff4; }
.summary-table th.today-col { color: var(--green); }
.summary-table .total-col { background: #ebf8ff; }
.summary-table th.total-col { color: #2b6cb0; }

.sum-item {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.sum-prod { color: #2b6cb0; font-weight: 700; font-size: 13px; }
.sum-waste { color: var(--red); font-size: 11px; }
.sum-waste-empty { color: var(--text-muted); font-size: 11px; opacity: 0.35; }
.sum-net { color: var(--green); font-weight: 700; font-size: 12px; }
.sum-net.negative { color: var(--red); }

.summary-table .totals-row td {
  background: #f7fafc;
  border-top: 2px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.summary-table .totals-row td.today-col { background: #f0fff4; }
.summary-table .totals-row td.total-col { background: #ebf8ff; }

.summary-legend {
  display: flex;
  gap: 14px;
  margin-top: 7px;
  font-size: 11px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.legend-prod::before { content: "■ "; color: #2b6cb0; }
.legend-waste::before { content: "■ "; color: var(--red); }
.legend-net::before { content: "■ "; color: var(--green); }

/* ====================================================
   CAFE TAB BAR (receiver / admin)
==================================================== */
.cafe-tabs {
  display: flex;
  gap: 6px;
  background: white;
  border-radius: var(--card-radius);
  padding: 8px;
  box-shadow: var(--shadow);
}

.cafe-tab {
  flex: 1;
  padding: 10px 8px;
  border-radius: 6px;
  border: 2px solid var(--border);
  background: white;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  min-height: var(--touch);
  letter-spacing: 0.02em;
  -webkit-tap-highlight-color: transparent;
}

.cafe-tab:hover {
  background: #f7fafc;
  color: var(--text-primary);
  border-color: #cbd5e0;
}

.cafe-tab.active {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

/* ====================================================
   EMPTY STATE
==================================================== */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: 16px;
  font-size: 14px;
}

/* ====================================================
   MOBILE: < 768px (Samsung A11 primary target)
==================================================== */
@media (max-width: 767px) {
  :root {
    --gap: 10px;
    --padding: 12px;
  }

  /* On mobile, chat is a full-height overlay from the left */
  .chat-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    height: 100dvh;
    width: 85vw;
    max-width: 300px;
    min-width: unset;
    transform: translateX(-105%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 60;
    box-shadow: 4px 0 20px rgba(0,0,0,0.4);
  }

  .chat-sidebar.open {
    transform: translateX(0);
  }

  /* Hide desktop collapsed state on mobile */
  .chat-sidebar.collapsed {
    width: 85vw;
    min-width: unset;
    transform: translateX(-105%);
  }

  /* Chat open button: floating bottom-right on mobile */
  .chat-open-btn {
    display: none !important; /* handled by header toggle button */
  }

  /* Main content takes full width on mobile */
  .main-content {
    width: 100%;
    padding: var(--padding);
    min-height: 100dvh;
  }

  header h1 { font-size: 16px; }

  /* Form rows stack on mobile */
  .menu-form {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
  }

  .menu-form input:first-child {
    grid-column: 1 / -1;
  }

  .menu-form button {
    grid-column: 1 / -1;
  }

  .category-form {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
  }

  .category-form input[type="text"] {
    grid-column: 1 / -1;
  }

  .form-row {
    grid-template-columns: 80px 1fr;
  }

  /* Larger touch targets for order actions */
  .order-item {
    padding: 10px;
  }

  .quantity-highlight {
    font-size: 22px;
  }

  /* Category buttons: 2 columns on small phones */
  .category-buttons {
    grid-template-columns: repeat(2, 1fr);
  }

  .menu-btn {
    min-height: 60px;
  }

  /* Stack history badge on smaller screens */
  .history-day-label { font-size: 12px; }
  .history-day-badge { font-size: 10px; }
}

/* ====================================================
   SMALL MOBILE: < 400px (very narrow phones)
==================================================== */
@media (max-width: 399px) {
  :root {
    --padding: 10px;
    --gap: 8px;
  }

  .category-buttons {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .menu-btn {
    font-size: 12px;
    padding: 10px 6px;
    min-height: 54px;
  }

  header h1 { font-size: 15px; }

  .history-accordion-header {
    padding: 8px 10px;
  }

  .history-day-label { font-size: 11px; }
}

/* ====================================================
   TABLET / LARGE PHONE: 480px+
==================================================== */
@media (min-width: 480px) {
  .category-buttons {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
}

/* ====================================================
   DESKTOP: 768px+
==================================================== */
@media (min-width: 768px) {
  /* Chat is a regular sidebar, not an overlay */
  .chat-sidebar {
    position: sticky;
    top: 0;
    transform: none;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    box-shadow: none;
    transition: width 0.3s ease, min-width 0.3s ease;
    height: 100vh;
  }

  .chat-sidebar.collapsed {
    width: 0;
    min-width: 0;
  }

  /* Show open-button when sidebar is collapsed on desktop */
  .chat-open-btn {
    display: none;
    left: 8px;
    top: 12px;
  }

  .chat-open-btn.visible {
    display: flex;
  }

  /* Overlay not needed on desktop */
  .chat-overlay { display: none !important; }

  .menu-form {
    grid-template-columns: 1fr 1fr 90px auto;
  }

  .category-form {
    grid-template-columns: 1fr auto auto;
  }

  .form-row {
    grid-template-columns: 100px 1fr;
  }
}

/* ====================================================
   LARGE DESKTOP: 960px+
==================================================== */
@media (min-width: 960px) {
  :root {
    --padding: 20px;
    --gap: 16px;
    --sidebar-width: 280px;
  }

  header h1 { font-size: 20px; }

  .category-buttons {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .menu-btn {
    min-height: 64px;
    font-size: 14px;
  }

  .menu-form {
    grid-template-columns: 1.5fr 1fr 100px auto;
  }
}

/* --- Waste Insights (admin) --- */
.insights-cafe { font-weight: 400; color: var(--text-muted); font-size: 0.85em; }
.insights-empty, .insights-note { color: var(--text-muted); margin: 8px 0 12px; }
.insights-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 12px; font-size: 0.85rem; color: var(--text-muted); }
.insights-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.insights-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.insights-row:last-child { border-bottom: none; }
.insights-row.flagged .insights-item { color: var(--red); }
.insights-row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.insights-item { font-weight: 600; }
.insights-total { font-size: 0.85rem; color: var(--text-muted); }
.insights-bar-line { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.insights-bar { height: 10px; border-radius: 0 4px 4px 0; min-width: 2px; }
.insights-bar-val { font-size: 0.75rem; color: var(--text-muted); }
.insights-suggestion { border: 1px solid var(--border); border-left: 4px solid var(--red); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.insights-action { font-weight: 600; margin-bottom: 2px; }
.insights-why { font-size: 0.85rem; color: var(--text-muted); }
.insights-badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 10px; background: #fed7d7; color: var(--red); }

.production-item-input {
  flex: 0 0 120px;
  width: 120px;
  margin-left: auto;
  padding: 4px 6px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  border: 1px solid #9ae6b4;
  border-radius: 6px;
  background: #fff;
}

.btn-save-production {
  margin-top: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: #38a169;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.btn-save-production:hover { background: #2f855a; }
