/* =========================================================
   ADMIN PORTAL — staff dashboard
   Shares design tokens with styles.css
   ========================================================= */

/* The HTML [hidden] attribute must always win over any `display: flex`
   set by component selectors below. Without this, panels with display:flex
   keep rendering even when we set hidden=true. */
[hidden] { display: none !important; }

.admin-body { background: var(--velvet); }

/* ---------- LOGIN ---------- */
.admin-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background:
    radial-gradient(circle at 20% 30%, rgba(225, 6, 0, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(225, 6, 0, 0.06) 0%, transparent 40%),
    var(--velvet);
}
.admin-login__panel {
  background: var(--burgundy);
  border: 1px solid var(--black);
  border-radius: var(--r-feature);
  padding: 56px 48px;
  width: 100%;
  max-width: 440px;
  text-align: center;
}
.admin-login__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-bottom: 40px;
}
.admin-login__brand-text {
  font-family: var(--font-display);
  font-size: 24px;
  letter-spacing: 0.04em;
  color: var(--red);
}
.admin-login__brand-text span { color: var(--white); }
.admin-login__brand-sub {
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--blush);
  text-transform: uppercase;
}
.admin-login__title {
  font-family: var(--font-display);
  font-size: 56px;
  text-transform: uppercase;
  line-height: 0.95;
  letter-spacing: 0.04em;
  color: var(--white);
  margin: 0 0 32px;
}
.admin-login__title .accent { color: var(--red); }

/* Form */
.admin-login__form {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.admin-login__field { margin-bottom: 16px; }
.admin-login__field .field__label {
  text-align: left;
  color: var(--blush);
  margin-bottom: 6px;
}
.admin-login__password-row {
  position: relative;
  display: flex;
}
.admin-login__password-row .field__input {
  padding-right: 48px;
}
.admin-login__pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--blush);
  transition: var(--t-fast);
}
.admin-login__pw-toggle:hover { background: var(--black); color: var(--white); }
.admin-login__pw-toggle[aria-pressed="true"] { background: var(--red); color: var(--white); }

.admin-login__err {
  margin: 16px 0 0;
  padding: 12px 16px;
  background: rgba(225, 6, 0, 0.15);
  border: 1px solid var(--red);
  border-radius: var(--r-btn);
  color: var(--white);
  font-size: 13px;
  text-align: center;
  line-height: 1.4;
}
.admin-login__err::before {
  content: "Notice: ";
  margin-right: 4px;
}
.admin-login__locked {
  margin: 16px 0 0;
  padding: 16px;
  background: var(--black);
  border: 2px solid var(--red);
  border-radius: var(--r-btn);
  color: var(--white);
  font-size: 14px;
  text-align: center;
  line-height: 1.5;
}
.admin-login__locked strong {
  display: block;
  font-family: var(--font-display);
  font-size: 32px;
  color: var(--red);
  margin: 4px 0;
  letter-spacing: 0.04em;
}

/* Demo creds */
.admin-login__demo {
  margin-top: 24px;
  padding: 16px;
  background: var(--velvet);
  border: 1px solid var(--black);
  border-radius: var(--r-btn);
  text-align: left;
  font-size: 12px;
  color: var(--blush);
}
.admin-login__demo summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  user-select: none;
}
.admin-login__demo summary:hover { color: var(--white); }
.admin-login__demo p { margin: 8px 0 0; line-height: 1.5; }
.admin-login__demo code {
  background: var(--black);
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--red);
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
  word-break: break-all;
}
.admin-login__demo strong { color: var(--white); font-weight: 500; }

.admin-login__back {
  display: inline-block;
  margin-top: 24px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--blush);
  transition: var(--t-fast);
}
.admin-login__back:hover { color: var(--red); }

/* ---------- DASHBOARD ---------- */
.admin-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px var(--gutter);
  background: var(--black);
  border-bottom: 1px solid var(--burgundy);
}
.admin-nav__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}
.admin-nav__divider { color: var(--burgundy); font-size: 20px; }
.admin-nav__sub {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--blush);
}
.admin-nav__right { display: flex; gap: 12px; align-items: center; }
.admin-nav__user {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--burgundy);
  border-radius: var(--r-btn);
  font-size: 13px;
  color: var(--white);
}
.admin-nav__user-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6ec27a;
  box-shadow: 0 0 0 3px rgba(110, 194, 122, 0.25);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(110, 194, 122, 0.25); }
  50% { box-shadow: 0 0 0 5px rgba(110, 194, 122, 0.1); }
}
.admin-nav__timer {
  margin-left: 4px;
  padding-left: 8px;
  border-left: 1px solid var(--black);
  color: var(--blush);
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
  letter-spacing: 0.04em;
}
.admin-nav__timer.is-warning { color: var(--red); }

.admin-dash__container {
  padding-top: 32px;
  padding-bottom: 80px;
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}
@media (max-width: 768px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
.stat {
  background: var(--burgundy);
  border: 1px solid var(--black);
  border-radius: var(--r-btn);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stat__label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--blush);
  font-weight: 600;
}
.stat__value {
  font-family: var(--font-display);
  font-size: 40px;
  color: var(--red);
  letter-spacing: 0.02em;
  line-height: 1;
}

/* Controls */
.dash-controls {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.dash-tools {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.field--inline {
  display: inline-block;
  margin: 0;
}
.field--inline .field__input {
  background: var(--burgundy);
  border: 1px solid var(--black);
  padding: 10px 14px;
  font-size: 13px;
  min-width: 180px;
}

/* Orders table */
.orders {
  background: var(--burgundy);
  border: 1px solid var(--black);
  border-radius: var(--r-btn);
  overflow: hidden;
}
.orders__empty {
  text-align: center;
  padding: 80px 24px;
}
.orders__empty h2 {
  font-family: var(--font-display);
  font-size: 32px;
  text-transform: uppercase;
  color: var(--red);
  margin: 0 0 12px;
}
.orders__empty p {
  color: var(--blush);
  margin: 0 0 8px;
  font-size: 14px;
}
.orders__empty a {
  color: var(--red);
  text-decoration: underline;
}

.orders__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.orders__table thead th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--blush);
  font-weight: 600;
  padding: 16px;
  background: var(--velvet);
  border-bottom: 1px solid var(--black);
}
.orders__table tbody td {
  padding: 16px;
  border-bottom: 1px solid var(--black);
  vertical-align: top;
}
.orders__table tbody tr {
  transition: background var(--t-fast);
}
.orders__table tbody tr:hover { background: var(--velvet); }
.orders__table tbody tr:last-child td { border-bottom: 0; }
.orders__table .col-code {
  font-family: var(--font-display);
  color: var(--red);
  font-size: 16px;
  letter-spacing: 0.04em;
}
.orders__table .col-cust strong {
  display: block;
  color: var(--white);
  font-weight: 600;
  margin-bottom: 2px;
}
.orders__table .col-cust span {
  color: var(--blush);
  font-size: 12px;
}
.orders__table .col-type,
.orders__table .col-branch,
.orders__table .col-time {
  color: var(--blush);
}
.orders__table .col-time strong {
  display: block;
  color: var(--white);
  font-weight: 600;
  font-size: 14px;
}
.orders__table .col-items {
  color: var(--white);
  max-width: 220px;
}
.orders__table .col-total {
  font-family: var(--font-display);
  color: var(--red);
  font-size: 18px;
  letter-spacing: 0.02em;
}

/* Status pill */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.status-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.status--received { background: var(--velvet); color: var(--blush); border: 1px solid var(--black); }
.status--preparing { background: rgba(225, 6, 0, 0.15); color: var(--red); border: 1px solid var(--red); }
.status--ready { background: rgba(255, 199, 198, 0.15); color: var(--blush); border: 1px solid var(--blush); }
.status--out_for_delivery { background: rgba(255, 199, 198, 0.15); color: var(--white); border: 1px solid var(--white); }
.status--completed { background: rgba(40, 167, 69, 0.15); color: #6ec27a; border: 1px solid #6ec27a; }

/* Actions */
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.act-btn {
  padding: 6px 12px;
  border-radius: var(--r-btn);
  background: var(--red);
  color: var(--white);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: var(--t-fast);
  white-space: nowrap;
}
.act-btn:hover { background: #ff1a14; }
.act-btn--ghost {
  background: transparent;
  border: 1px solid var(--blush);
  color: var(--blush);
}
.act-btn--ghost:hover { background: var(--blush); color: var(--velvet); border-color: var(--blush); }
.act-btn--danger {
  background: transparent;
  border: 1px solid var(--burgundy);
  color: var(--blush);
}
.act-btn--danger:hover { background: var(--black); color: var(--red); }

/* Mobile table -> cards */
@media (max-width: 960px) {
  .orders__table thead { display: none; }
  .orders__table, .orders__table tbody, .orders__table tr, .orders__table td { display: block; width: 100%; }
  .orders__table tr {
    border-bottom: 1px solid var(--black);
    padding: 16px;
  }
  .orders__table tbody td {
    border-bottom: 0;
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
  }
  .orders__table tbody td::before {
    content: attr(data-label);
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--blush);
    font-weight: 600;
  }
  .orders__table .col-code::before { content: "Code · "; }
  .orders__table .col-cust::before { content: "Customer · "; }
  .orders__table .col-cust strong::before { content: ""; }
  .orders__table .col-type::before { content: "Type · "; }
  .orders__table .col-branch::before { content: "Branch · "; }
  .orders__table .col-time::before { content: "Time · "; }
  .orders__table .col-items::before { content: "Items · "; }
  .orders__table .col-total::before { content: "Total · "; }
  .orders__table .col-status::before { content: "Status · "; }
  .orders__table .col-actions::before { content: "Actions · "; }
  .orders__table .col-actions { padding-top: 12px; }
  .actions { width: 100%; justify-content: flex-end; }
}

/* ---------- MODAL ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}
.modal__panel {
  position: relative;
  background: var(--burgundy);
  border: 1px solid var(--black);
  border-radius: var(--r-feature);
  padding: 40px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal__close {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 20px;
  color: var(--blush);
  padding: 4px 10px;
  border-radius: 6px;
  transition: var(--t-fast);
}
.modal__close:hover { background: var(--black); color: var(--white); }

.modal-detail {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.modal-detail__head {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--black);
}
.modal-detail__code {
  font-family: var(--font-display);
  font-size: 48px;
  color: var(--red);
  letter-spacing: 0.04em;
  line-height: 1;
}
.modal-detail__sub {
  font-size: 13px;
  color: var(--blush);
  margin-top: 8px;
  letter-spacing: 0.04em;
}
.modal-detail__section h4 {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--red);
  font-weight: 600;
  margin: 0 0 8px;
}
.modal-detail__row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--black);
}
.modal-detail__row:last-child { border-bottom: 0; }
.modal-detail__row span:first-child { color: var(--blush); }
.modal-detail__row span:last-child { color: var(--white); text-align: right; }
.modal-detail__items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modal-detail__item {
  display: flex;
  justify-content: space-between;
  color: var(--white);
  font-size: 14px;
}
.modal-detail__total {
  display: flex;
  justify-content: space-between;
  padding-top: 12px;
  margin-top: 4px;
  border-top: 1px solid var(--black);
  font-family: var(--font-display);
  font-size: 24px;
}
.modal-detail__total span:last-child { color: var(--red); }
.modal-detail__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Live updates flash */
@keyframes flash {
  0% { background: rgba(225, 6, 0, 0.15); }
  100% { background: transparent; }
}
.orders__table tbody tr.is-new { animation: flash 2s ease-out; }

/* ---------- AUDIT LOG ---------- */
.audit-log {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--velvet);
  border-radius: var(--r-btn);
  padding: 16px;
  border: 1px solid var(--black);
}
.audit-log__entry {
  display: grid;
  grid-template-columns: 170px 100px 1fr;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--black);
  color: var(--blush);
}
.audit-log__entry:last-child { border-bottom: 0; }
.audit-log__entry .ts { color: var(--blush); opacity: 0.7; }
.audit-log__entry .type { font-weight: 600; }
.audit-log__entry .type--success { color: #6ec27a; }
.audit-log__entry .type--fail { color: var(--red); }
.audit-log__entry .type--lockout { color: var(--red); background: rgba(225, 6, 0, 0.08); padding: 2px 6px; border-radius: 4px; }
.audit-log__entry .type--logout { color: var(--blush); }
.audit-log__empty {
  text-align: center;
  padding: 32px;
  color: var(--blush);
}
.audit-log__empty strong {
  display: block;
  color: var(--white);
  font-family: var(--font-display);
  font-size: 18px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* =========================================================
   MOBILE — admin dashboard + login
   ========================================================= */
@media (max-width: 768px) {
  /* ---------- ADMIN NAV ---------- */
  .admin-nav { flex-wrap: wrap; gap: 8px; padding: 12px var(--gutter); }
  .admin-nav__right { flex-wrap: wrap; gap: 8px; width: 100%; }
  .admin-nav__user { padding: 4px 10px; font-size: 12px; flex: 1; min-width: 0; }
  .admin-nav__user #adminUserName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .admin-nav__timer { font-size: 11px; }
  .admin-nav__right .btn { padding: 6px 10px; font-size: 12px; min-height: 36px; }

  /* ---------- STATS ---------- */
  .stats { grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 24px; }
  .stat { padding: 16px; }
  .stat__value { font-size: 28px; }

  /* ---------- DASHBOARD CONTROLS ---------- */
  .dash-controls { flex-direction: column; align-items: stretch; gap: 16px; }
  .dash-tools { flex-direction: column; gap: 12px; }
  .dash-tools .field { margin: 0; }
  .field--inline .field__input { min-width: 0; width: 100%; }

  /* ---------- FILTER PILLS — horizontal scroll on small screens */
  #statusFilters {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .filter { white-space: nowrap; flex-shrink: 0; }

  /* ---------- ORDER TABLE (already becomes cards via 960px rule) ---------- */
  .orders__table tr { padding: 16px 12px; }
  .orders__table tbody td { padding: 6px 0; font-size: 13px; }
  .orders__table .col-code { font-size: 18px; }

  /* ---------- LOGIN SCREEN ---------- */
  .admin-login { padding: 24px 16px; }
  .admin-login__panel { padding: 40px 28px; }
  .admin-login__title { font-size: 44px; }
  .admin-login__demo p { font-size: 12px; }
  .admin-login__back { padding: 12px 0; min-height: 44px; display: inline-flex; align-items: center; }

  /* ---------- MODAL ---------- */
  .modal { padding: 12px; }
  .modal__panel { padding: 32px 20px; max-height: 85vh; border-radius: var(--r-card); }
  .modal-detail__code { font-size: 36px; }
  .modal-detail__actions { flex-direction: column-reverse; }
  .modal-detail__actions .btn { width: 100%; justify-content: center; }
}

@media (max-width: 380px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat__value { font-size: 24px; }
  .admin-nav__right { flex-direction: column; align-items: stretch; }
  .admin-nav__user { justify-content: center; }
}
