/* ============================================
   ADMIN DASHBOARD — Design Tokens
   ============================================ */
:root {
  --bg:             #FAF8F5;
  --bg-white:       #FFFFFF;
  --surface:        #F2EBE3;
  --text-primary:   #1A1410;
  --text-secondary: #6B5E54;
  --accent:         #F64900;
  --accent-hover:   #D43E00;
  --gold:           #C9953C;
  --green:          #00b894;
  --blue:           #0984e3;
  --red:            #d63031;
  --radius:         8px;
  --font-display:   'Playfair Display', Georgia, serif;
  --font-body:      'Source Sans 3', 'Source Sans Pro', sans-serif;
  --shadow-sm:      0 2px 20px rgba(28,20,16,0.06);
  --shadow-md:      0 4px 24px rgba(28,20,16,0.08), 0 8px 32px rgba(28,20,16,0.04);
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Screens */
.screen { display: none; }
.screen.active { display: block; }

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
  text-decoration: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border: 1.5px solid rgba(28,20,16,0.15);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn-sm { padding: 8px 16px; font-size: 0.8rem; }

.btn-success { background: var(--green); color: #fff; }
.btn-success:hover:not(:disabled) { background: #00a381; }

.btn-blue { background: var(--blue); color: #fff; }
.btn-blue:hover:not(:disabled) { background: #0770c2; }

/* ============================================
   LOGIN
   ============================================ */
#login-screen {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

#login-screen.active {
  display: flex;
}

.login-card {
  background: var(--bg-white);
  border-radius: 12px;
  padding: 48px 40px;
  max-width: 400px;
  width: 100%;
  margin: 20px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.login-card h1 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 32px;
}

.field {
  text-align: left;
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid rgba(28,20,16,0.15);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus { border-color: var(--accent); }

.login-error {
  color: var(--red);
  font-size: 0.8rem;
  min-height: 1.2em;
  margin-bottom: 8px;
}

#login-form .btn { width: 100%; margin-top: 8px; }

/* ============================================
   DASHBOARD HEADER
   ============================================ */
.dash-header {
  background: var(--bg-white);
  border-bottom: 1px solid rgba(28,20,16,0.06);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.dash-header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.dash-header h1 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
}

.dash-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-email {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ============================================
   DASHBOARD MAIN
   ============================================ */
.dash-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* Stats */
.dash-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-white);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

@media (max-width: 768px) {
  .dash-stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .dash-stats { grid-template-columns: 1fr; }
}

/* Filter tabs */
.filter-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px;
  overflow-x: auto;
}

.tab {
  padding: 8px 20px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.tab.active {
  background: var(--bg-white);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

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

/* Table */
.table-wrap {
  background: var(--bg-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.orders-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.orders-table th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--surface);
  white-space: nowrap;
}

.orders-table td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(28,20,16,0.04);
  vertical-align: middle;
}

.orders-table tbody tr:hover { background: rgba(28,20,16,0.015); }

.empty-state {
  text-align: center;
  padding: 48px 16px !important;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-pending { background: rgba(201,149,60,0.15); color: #b8860b; }
.badge-confirmed { background: rgba(0,184,148,0.15); color: #00a381; }
.badge-fulfilled { background: rgba(9,132,227,0.15); color: #0770c2; }
.badge-abandoned { background: rgba(214,48,49,0.15); color: #c72c2c; }
.badge-email-sent { background: rgba(0,184,148,0.15); color: #00a381; }
.badge-email-failed { background: rgba(214,48,49,0.15); color: #c72c2c; }
.badge-email-missing { background: rgba(201,149,60,0.15); color: #b8860b; }
.badge-email-sending { background: rgba(9,132,227,0.15); color: #0770c2; }

/* Method badges */
.method-badge {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Ref link style */
.ref-code {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

/* Actions column */
.action-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.action-btns .btn { min-width: 120px; text-align: center; }

/* ============================================
   MODAL
   ============================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-white);
  border-radius: 12px;
  padding: 32px;
  max-width: 420px;
  width: 100%;
  margin: 20px;
  box-shadow: var(--shadow-md);
}

.modal h3 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.modal p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 24px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ============================================
   DRAWER
   ============================================ */
.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 50;
}

.drawer-backdrop.active { display: block; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 460px;
  max-width: 100%;
  background: var(--bg-white);
  box-shadow: var(--shadow-md);
  z-index: 51;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.drawer.active { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid rgba(28,20,16,0.06);
  gap: 12px;
}

.drawer-header > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.drawer-close {
  background: none;
  border: none;
  font-size: 1.6rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

.drawer-close:hover { color: var(--text-primary); background: var(--surface); }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.drawer-section { margin-bottom: 24px; }

.drawer-section-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

/* Detail rows */
.drawer-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(28,20,16,0.04);
  font-size: 0.85rem;
}

.drawer-detail-row:last-child { border-bottom: none; }

.drawer-detail-label { color: var(--text-secondary); }

.drawer-detail-value {
  font-weight: 600;
  color: var(--text-primary);
  text-align: right;
  max-width: 60%;
  word-break: break-word;
}

/* Editable fields (super admin) */
.drawer-detail-value .edit-input {
  width: 100%;
  max-width: 180px;
  padding: 4px 8px;
  border: 1.5px solid rgba(28,20,16,0.15);
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  text-align: right;
  background: var(--bg);
  outline: none;
}

.drawer-detail-value .edit-input:focus { border-color: var(--accent); }

.edit-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 2px 6px;
  margin-left: 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.edit-toggle:hover { color: var(--accent); background: var(--surface); }

/* Edit mode actions */
.drawer-edit-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

/* Timeline */
.timeline-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 0;
  font-size: 0.85rem;
}

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--surface);
  margin-top: 6px;
  flex-shrink: 0;
}

.timeline-dot.active { background: var(--green); }
.timeline-dot.pending { background: var(--gold); }

.timeline-label { color: var(--text-secondary); min-width: 80px; }
.timeline-date { font-weight: 500; color: var(--text-primary); }

/* Audit log */
.audit-entry {
  padding: 10px 0;
  border-bottom: 1px solid rgba(28,20,16,0.04);
  font-size: 0.8rem;
}

.audit-entry:last-child { border-bottom: none; }

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

.audit-entry-type { font-weight: 600; color: var(--text-primary); }
.audit-entry-time { color: var(--text-secondary); font-size: 0.75rem; }

.audit-entry-details {
  color: var(--text-secondary);
  font-size: 0.75rem;
  line-height: 1.5;
}

.audit-entry-error {
  color: var(--red);
  font-size: 0.75rem;
  margin-top: 2px;
}

/* Footer */
.drawer-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(28,20,16,0.06);
}

.drawer-actions { display: flex; flex-direction: column; gap: 8px; }

.drawer-divider {
  height: 1px;
  background: rgba(28,20,16,0.08);
  margin: 12px 0;
}

.drawer-admin-row { display: flex; flex-direction: column; gap: 12px; }

.drawer-status-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.drawer-select {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid rgba(28,20,16,0.15);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text-primary);
  outline: none;
}

.drawer-select:focus { border-color: var(--accent); }

/* Danger button */
.btn-danger {
  background: var(--red);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: #c72c2c; }

/* Super admin visibility */
.super-admin-only { display: none; }
body.is-super-admin .super-admin-only { display: block; }

/* Clickable rows */
.orders-table tbody tr { cursor: pointer; }
.orders-table tbody tr:hover { background: rgba(28,20,16,0.025); }

/* Mobile drawer */
@media (max-width: 600px) {
  .drawer { width: 100%; }
}
