/* ============================================================
   Sign-Calc Admin Dashboard — admin.css
   ============================================================ */

/* ------------------------------------------------------------
   CSS Variables
   ------------------------------------------------------------ */
:root {
  --color-bg: #f0f2f5;
  --color-surface: #ffffff;
  --color-border: #d1d5db;
  --color-border-light: #e5e7eb;

  --color-text: #111827;
  --color-text-muted: #6b7280;
  --color-text-light: #9ca3af;

  --color-blue: #2563eb;
  --color-blue-hover: #1d4ed8;
  --color-blue-light: #eff6ff;
  --color-blue-border: #bfdbfe;

  --color-green: #16a34a;
  --color-green-light: #f0fdf4;
  --color-green-border: #bbf7d0;

  --color-red: #dc2626;
  --color-red-hover: #b91c1c;
  --color-red-light: #fef2f2;
  --color-red-border: #fecaca;

  --color-amber: #d97706;
  --color-amber-light: #fffbeb;
  --color-amber-border: #fde68a;

  --color-gray-50: #f9fafb;
  --color-gray-100: #f3f4f6;
  --color-gray-200: #e5e7eb;
  --color-gray-700: #374151;
  --color-gray-800: #1f2937;

  --topbar-height: 56px;
  --tab-nav-height: 44px;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

/* ------------------------------------------------------------
   Reset & Base
   ------------------------------------------------------------ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

.hidden {
  display: none !important;
}

/* ------------------------------------------------------------
   Auth Error
   ------------------------------------------------------------ */
.auth-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  font-size: 16px;
  color: var(--color-text-muted);
  padding: 24px;
  text-align: center;
}

/* ------------------------------------------------------------
   Topbar
   ------------------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-height);
  background: var(--color-gray-800);
  border-bottom: 1px solid var(--color-gray-700);
  display: flex;
  align-items: center;
  padding: 0 24px;
  box-shadow: var(--shadow-md);
}

.topbar-title {
  font-size: 18px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 0.01em;
}

/* ------------------------------------------------------------
   Tab Navigation
   ------------------------------------------------------------ */
.tab-nav {
  position: sticky;
  top: var(--topbar-height);
  z-index: 90;
  display: flex;
  background: var(--color-surface);
  border-bottom: 2px solid var(--color-border);
  padding: 0 24px;
  gap: 0;
  box-shadow: var(--shadow-sm);
}

.tab-btn {
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  padding: 12px 16px;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

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

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

/* ------------------------------------------------------------
   Tab Panels
   ------------------------------------------------------------ */
.tab-panel {
  padding: 24px;
  max-width: 1600px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-gray-800);
}

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

.coming-soon {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  color: var(--color-text-muted);
  font-size: 15px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

/* ------------------------------------------------------------
   Filter Input
   ------------------------------------------------------------ */
.filter-input {
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 7px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  width: 240px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.filter-input:focus {
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.filter-input::placeholder {
  color: var(--color-text-light);
}

/* ------------------------------------------------------------
   Buttons
   ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  outline: none;
  text-decoration: none;
}

.btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

.btn-primary {
  background: var(--color-blue);
  color: #ffffff;
  border-color: var(--color-blue);
}

.btn-primary:hover {
  background: var(--color-blue-hover);
  border-color: var(--color-blue-hover);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-gray-100);
}

.btn-danger {
  background: var(--color-red);
  color: #ffffff;
  border-color: var(--color-red);
}

.btn-danger:hover {
  background: var(--color-red-hover);
  border-color: var(--color-red-hover);
}

.btn-sm {
  font-size: 12px;
  padding: 4px 10px;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-text-muted);
  padding: 4px 8px;
}

.btn-ghost:hover {
  background: var(--color-gray-100);
  color: var(--color-text);
}

/* ------------------------------------------------------------
   Data Table
   ------------------------------------------------------------ */
.table-wrapper {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead {
  background: var(--color-gray-50);
}

.data-table thead th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  user-select: none;
}

.data-table thead th.sortable {
  cursor: pointer;
}

.data-table thead th.sortable:hover {
  color: var(--color-text);
  background: var(--color-gray-100);
}

.data-table thead th.sort-asc .sort-icon::after {
  content: " \25B2";
  color: var(--color-blue);
}

.data-table thead th.sort-desc .sort-icon::after {
  content: " \25BC";
  color: var(--color-blue);
}

.data-table tbody tr {
  border-bottom: 1px solid var(--color-border-light);
  transition: background 0.1s;
}

.data-table tbody tr:last-child {
  border-bottom: none;
}

.data-table tbody tr:nth-child(even) {
  background: var(--color-gray-50);
}

.data-table tbody tr:hover {
  background: var(--color-blue-light);
}

.data-table tbody td {
  padding: 9px 12px;
  vertical-align: middle;
  color: var(--color-text);
}

.data-table tbody td.loading-cell {
  text-align: center;
  padding: 40px;
  color: var(--color-text-muted);
}

.col-actions {
  width: 140px;
  text-align: right !important;
}

td.col-actions {
  text-align: right;
}

.action-group {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

/* Monospace for key fields */
.cell-key {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-gray-700);
}

/* ------------------------------------------------------------
   Badges
   ------------------------------------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
}

.badge-green {
  background: var(--color-green-light);
  color: var(--color-green);
  border: 1px solid var(--color-green-border);
}

.badge-red {
  background: var(--color-red-light);
  color: var(--color-red);
  border: 1px solid var(--color-red-border);
}

.badge-amber {
  background: var(--color-amber-light);
  color: var(--color-amber);
  border: 1px solid var(--color-amber-border);
}

.badge-gray {
  background: var(--color-gray-100);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

/* ------------------------------------------------------------
   Settings inline edit
   ------------------------------------------------------------ */
.setting-value-cell {
  min-width: 180px;
}

.setting-value-display {
  display: flex;
  align-items: center;
  gap: 8px;
}

.setting-value-text {
  font-family: var(--font-mono);
  font-size: 13px;
}

.setting-edit-form {
  display: flex;
  align-items: center;
  gap: 6px;
}

.setting-edit-input {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  width: 160px;
  outline: none;
}

.setting-edit-input:focus {
  border-color: var(--color-blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

/* ------------------------------------------------------------
   Modal
   ------------------------------------------------------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-gray-800);
}

.modal-close {
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  color: var(--color-text-muted);
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.modal-close:hover {
  color: var(--color-text);
  background: var(--color-gray-100);
}

.modal-form {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border-light);
  margin-top: 4px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-row-checks {
  grid-template-columns: auto auto;
  justify-content: start;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-gray-700);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-group input:invalid {
  border-color: var(--color-red);
}

.required {
  color: var(--color-red);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
}

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

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding-top: 2px;
}

.form-fieldset {
  border: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-fieldset legend {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-gray-700);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0;
}

/* ------------------------------------------------------------
   Toast Notifications
   ------------------------------------------------------------ */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  max-width: 340px;
  animation: toast-in 0.2s ease-out;
  border-left: 3px solid;
}

.toast-success {
  background: var(--color-green-light);
  color: var(--color-green);
  border-left-color: var(--color-green);
}

.toast-error {
  background: var(--color-red-light);
  color: var(--color-red);
  border-left-color: var(--color-red);
}

.toast-info {
  background: var(--color-blue-light);
  color: var(--color-blue);
  border-left-color: var(--color-blue);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ------------------------------------------------------------
   Filter Select (Quotes / Log dropdowns)
   ------------------------------------------------------------ */
.filter-select {
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-width: 130px;
}

.filter-select:focus {
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* ------------------------------------------------------------
   Pagination Bar
   ------------------------------------------------------------ */
.pagination-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0 4px;
}

.pagination-label {
  font-size: 13px;
  color: var(--color-text-muted);
  min-width: 90px;
  text-align: center;
}

.pagination-total {
  font-size: 12px;
  color: var(--color-text-light);
}

/* ------------------------------------------------------------
   Quotes Table — expandable rows
   ------------------------------------------------------------ */
.quotes-table tbody tr.quote-row {
  cursor: pointer;
}

.quotes-table tbody tr.quote-row:hover {
  background: var(--color-blue-light);
}

.quote-detail-row {
  background: var(--color-gray-50) !important;
}

.quote-detail-row:hover {
  background: var(--color-gray-50) !important;
}

.quote-detail-cell {
  padding: 0 !important;
}

.quote-detail-panel {
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  border-top: 2px solid var(--color-blue-border);
}

.detail-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 2px;
}

.detail-kv {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  gap: 8px;
}

.detail-kv-label {
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.detail-kv-value {
  color: var(--color-text);
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12px;
}

.detail-full-row {
  grid-column: 1 / -1;
}

.validation-errors-box {
  background: var(--color-red-light);
  border: 1px solid var(--color-red-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--color-red);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 120px;
  overflow-y: auto;
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.detail-download-link {
  font-size: 12px;
  color: var(--color-blue);
  text-decoration: none;
  font-weight: 500;
}

.detail-download-link:hover {
  text-decoration: underline;
}

.detail-placeholder {
  font-size: 12px;
  color: var(--color-text-light);
  font-style: italic;
}

/* Quote row expand indicator */
.expand-icon {
  display: inline-block;
  font-size: 10px;
  margin-right: 4px;
  transition: transform 0.15s;
  color: var(--color-text-muted);
}

.quote-row.expanded .expand-icon {
  transform: rotate(90deg);
}

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

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--color-gray-800);
  line-height: 1.1;
}

/* ------------------------------------------------------------
   Analytics — Chart Card
   ------------------------------------------------------------ */
.chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.chart-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-gray-800);
  margin-bottom: 12px;
}

.bar-chart-canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* ------------------------------------------------------------
   Analytics — Popular Materials Section
   ------------------------------------------------------------ */
.analytics-section {
  margin-top: 4px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-gray-800);
  margin-bottom: 10px;
}

/* ------------------------------------------------------------
   Day Range Switcher
   ------------------------------------------------------------ */
.day-range-switcher {
  display: flex;
  gap: 4px;
  background: var(--color-gray-100);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 3px;
}

.day-range-btn {
  border-radius: var(--radius-sm) !important;
  min-width: 36px;
}

.day-range-btn.active-range {
  background: var(--color-blue) !important;
  color: #ffffff !important;
  border-color: var(--color-blue) !important;
}

/* ------------------------------------------------------------
   Responsive
   ------------------------------------------------------------ */
@media (max-width: 768px) {
  .tab-panel {
    padding: 16px;
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .filter-input {
    width: 100%;
  }

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

  .topbar {
    padding: 0 16px;
  }

  .tab-nav {
    padding: 0 8px;
    overflow-x: auto;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .quote-detail-panel {
    grid-template-columns: 1fr;
  }

  .filter-select {
    width: 100%;
  }
}
