/* ════════════════════════════════════════════════════════════
   ADMIN DASHBOARD STYLES
   ════════════════════════════════════════════════════════════ */

.admin-body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  margin: 0;
  padding: 0;
  cursor: default !important;
}

.admin-body a, .admin-body button, .admin-body select, .admin-body .conv-item {
  cursor: pointer !important;
}
.admin-body input, .admin-body textarea {
  cursor: text !important;
}

/* LOGIN GATE */
.login-gate {
  position: fixed;
  inset: 0;
  background: var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.login-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 40px;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

/* LAYOUT */
.admin-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.admin-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 32px;
  background: rgba(10, 10, 15, 0.8);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}
.admin-content {
  padding: 32px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* TABS */
.admin-tabs {
  display: flex;
  gap: 16px;
  margin-bottom: 32px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
}
.admin-tab {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  font-weight: 500;
  padding: 12px 24px;
  cursor: pointer;
  position: relative;
  transition: color var(--dur-fast);
}
.admin-tab:hover {
  color: var(--text-primary);
}
.admin-tab.active {
  color: var(--accent);
}
.admin-tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--accent);
}

/* STATS GRID */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
}
.stat-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  padding: 24px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  transition: transform var(--dur-fast), border-color var(--dur-fast);
}
.stat-card:hover {
  transform: translateY(-2px);
  border-color: rgba(45, 79, 255, 0.3);
}
.stat-card--warning {
  border-color: rgba(241, 196, 15, 0.3);
  background: rgba(241, 196, 15, 0.05);
}
.stat-label {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 12px;
}
.stat-value {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}
.stat-subtext {
  font-size: 0.85rem;
  margin-top: 8px;
}
.text-green { color: #2ecc71; }
.text-danger { color: #e74c3c; }
.text-warning { color: #f1c40f; }

/* PANELS & GRIDS */
.admin-grid-2 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}
.admin-grid-inner {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.admin-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
}
.border-warning {
  border-color: rgba(241, 196, 15, 0.3);
}
.panel-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text-primary);
}

/* TABLES */
.table-responsive {
  overflow-x: auto;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.admin-table th, .admin-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.admin-table th {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.admin-table tbody tr:hover {
  background: rgba(255,255,255,0.02);
}

/* BADGES & INPUTS */
.badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}
.badge-sm { padding: 2px 6px; font-size: 0.75rem; }

.status-select {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 0.9rem;
}
.status-select:focus { outline: none; border-color: var(--accent); }

.code-input {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 0.9rem;
  width: 150px;
}

/* LISTS */
.stock-alert-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.stock-alert-list li {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.stock-alert-list li:last-child { border: none; }

/* ── ADMIN CHAT UI ── */
.conv-item {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
}
.conv-item:hover { background: rgba(255,255,255,0.05); }
.conv-item.active { background: rgba(0,200,255,0.1); border-left: 3px solid var(--accent); }
.conv-item.unread { background: rgba(255,255,255,0.02); }
.conv-item.unread .conv-id { font-weight: 700; color: #fff; }

.conv-id { font-size: 0.95rem; color: var(--text-primary); margin-bottom: 4px; display: flex; align-items: center; justify-content: space-between; }
.conv-preview { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 0.75rem; color: var(--text-muted); }

.unread-dot {
  display: inline-block;
  width: 8px; height: 8px;
  background: #ff4757;
  border-radius: 50%;
}

/* ── CALCULATOR WIDGET ── */
.calc-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 50px;
  height: 50px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 102, 255, 0.4);
  z-index: 1000;
  transition: transform 0.2s;
}
.calc-toggle:hover { transform: scale(1.05); }

.calc-widget {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 280px;
  background: rgba(10, 15, 25, 0.9);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 200, 255, 0.3);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  z-index: 1000;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.calc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.9rem;
  font-weight: 600;
}
.calc-header button {
  background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.2rem; line-height: 1;
}
.calc-header button:hover { color: #fff; }

.calc-display {
  padding: 24px 16px;
  text-align: right;
  font-size: 2.2rem;
  font-weight: 700;
  color: #fff;
  background: rgba(0,0,0,0.2);
  word-wrap: break-word;
  word-break: break-all;
}

.calc-keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: rgba(255, 255, 255, 0.05);
}
.calc-key {
  border: none;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 1.2rem;
  padding: 16px 0;
  cursor: pointer;
  transition: background 0.1s;
}
.calc-key:hover { background: rgba(255,255,255,0.1); }
.calc-key:active { background: rgba(255,255,255,0.15); }
.calc-operator { color: var(--accent-light); font-weight: 600; background: rgba(0, 102, 255, 0.05); }
.calc-operator:hover { background: rgba(0, 102, 255, 0.15); }
.calc-equals { background: var(--accent); color: #fff; }
.calc-equals:hover { background: var(--accent-hover); }

/* STOCK INPUT */
.stock-input-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
}
.stock-input {
  width: 50px;
  padding: 4px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: #fff;
  border-radius: 4px;
  text-align: center;
}
.stock-save-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
}



/* ════════════════════════════════════════════════════════════
   MOBILE RESPONSIVENESS
   ════════════════════════════════════════════════════════════ */

/* Table scroll indicator */
.table-responsive {
  position: relative;
}
.table-responsive::after {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 40px;
  background: linear-gradient(to left, var(--bg-surface), transparent);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.table-responsive.is-scrollable::after {
  opacity: 1;
}

@media (max-width: 900px) {
  .admin-grid-2 {
    grid-template-columns: 1fr;
  }
  .admin-topbar {
    flex-direction: row;
    gap: 12px;
    padding: 12px 16px;
  }
  .admin-tabs {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
    width: 100%;
    gap: 4px;
  }
  .admin-tab {
    padding: 10px 16px;
    font-size: 0.9rem;
  }
  .admin-content {
    padding: 16px;
  }
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  /* Admin tables: ensure they scroll smoothly */
  .admin-table {
    font-size: 0.85rem;
  }
  .admin-table th, .admin-table td {
    padding: 10px 12px;
    white-space: nowrap;
  }

  /* Messages view: stack vertically */
  #view-messages {
    height: auto !important;
    min-height: calc(100vh - 140px);
  }
  #view-messages > .admin-panel {
    flex-direction: column !important;
    height: auto !important;
    min-height: calc(100vh - 200px);
  }
  #view-messages > .admin-panel > div:first-child {
    width: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border);
    max-height: 250px;
    overflow-y: auto;
  }
  #view-messages > .admin-panel > div:last-child {
    width: 100% !important;
    min-height: 400px;
  }
  
  /* Conversation items: better touch targets */
  .conv-item {
    padding: 14px 16px;
    min-height: 60px;
  }

  /* Admin form grids: single column */
  #add-product-form > div[style*="grid"],
  #edit-product-form > div[style*="grid"] {
    grid-template-columns: 1fr !important;
  }

  /* Panel header: stack if needed */
  .panel-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start !important;
  }
  
  /* Tabs: allow horizontal scroll */
  .admin-tabs {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* Chat input in admin */
  #admin-chat-input-area {
    flex-wrap: wrap;
  }
  #admin-chat-text {
    font-size: 16px;
  }

  /* Stat cards */
  .stat-value {
    font-size: 1.8rem;
  }

  /* Calculator widget */
  .calc-widget {
    right: 8px;
    left: 8px;
    width: auto;
  }

  /* Inputs: prevent iOS zoom */
  .admin-body .form-input,
  .admin-body input[type="text"],
  .admin-body input[type="password"],
  .admin-body input[type="number"],
  .admin-body select,
  .admin-body textarea,
  .admin-body .code-input,
  .admin-body .stock-input {
    font-size: 16px !important;
  }
}

@media (max-width: 500px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .stat-card {
    padding: 16px;
  }
  .stat-value {
    font-size: 1.4rem;
  }
  .calc-toggle {
    top: 50%;
    bottom: auto;
    right: 12px;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
  }
  .login-box {
    padding: 24px;
    margin: 0 16px;
  }
  .admin-topbar {
    padding: 10px 12px;
  }
  .admin-topbar .heading-brand {
    font-size: 1rem;
  }
}
