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

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f8f8;
  --bg-sidebar: #fafafa;
  --text-primary: #14120b;
  --text-secondary: #6b6b6b;
  --text-tertiary: #9a9a9a;
  --accent: #14120b;
  --accent-hover: #2d2a24;
  --accent-orange: #f97316;
  --accent-orange-hover: #ea580c;
  --accent-orange-light: #fff7ed;
  --accent-orange-muted: #fed7aa;
  --border: #e5e5e0;
  --border-hover: #d0d0c8;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --row-hover: #fafafa;
  --sidebar-width: 240px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* Global icon styling - thinner strokes, sharper corners */
svg[class^="lucide"] {
  stroke-width: 1.25 !important;
  stroke-linecap: square !important;
  stroke-linejoin: miter !important;
}

/* App Layout */
#app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  color: var(--text-primary);
  background: var(--bg-primary);
}

.nav-item.active {
  color: var(--text-primary);
  background: var(--bg-primary);
  border-left-color: var(--accent-orange);
}

.nav-item i {
  width: 18px;
  height: 18px;
  stroke-width: 1.25;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
}

.status-dot.connecting {
  background: var(--warning);
  animation: pulse 1s ease-in-out infinite;
}

.status-dot.connected {
  background: var(--success);
}

.status-dot.disconnected {
  background: var(--error);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.sidebar-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--bg-primary);
  border-radius: 3px;
  border: 1px solid var(--border);
}

.profile-avatar {
  width: 32px;
  height: 32px;
  background: var(--bg-secondary);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.profile-avatar i {
  width: 16px;
  height: 16px;
  stroke-width: 1.5;
}

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

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

.profile-role {
  font-size: 11px;
  color: var(--text-tertiary);
}

.btn-logout {
  padding: 6px;
  background: transparent;
  border: none;
  border-radius: 3px;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-logout:hover {
  background: var(--bg-secondary);
  color: var(--error);
}

/* Main Content Area */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Page Container */
.page {
  display: none;
  flex: 1;
  padding: 24px 32px;
  overflow-y: auto;
}

.page.active {
  display: block;
}

.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

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

.stat-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 20px;
  transition: all 0.15s ease;
}

.stat-card:hover {
  border-color: var(--border-hover);
}

.stat-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.stat-card-icon {
  width: 36px;
  height: 36px;
  background: #fff7ed;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.stat-card-icon i {
  width: 18px;
  height: 18px;
  stroke-width: 1.5;
  color: #c2410c;
}

.stat-card-value {
  font-size: 28px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-card-label {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Quick Actions */
.quick-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}

.breadcrumb-item {
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color 0.15s ease;
}

.breadcrumb-item:hover {
  color: var(--text-primary);
}

.breadcrumb-item.active {
  color: var(--text-primary);
  font-weight: 500;
  cursor: default;
}

.breadcrumb-separator {
  color: var(--text-tertiary);
}

/* Search Section */
.search-section {
  margin-bottom: 24px;
}

.search-box {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.search-input {
  flex: 1;
  max-width: 480px;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: border-color 0.15s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.search-input::placeholder {
  color: var(--text-tertiary);
}

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

.product-stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 14px 16px;
  text-align: center;
}

.product-stat-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.product-stat-label {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Charts */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

.chart-container {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 20px;
}

.chart-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.chart-wrapper {
  position: relative;
  height: 250px;
  width: 100%;
}

/* Loading */
.loading {
  text-align: center;
  padding: 48px 0;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent-orange);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading p {
  color: var(--text-secondary);
  font-size: 13px;
}

/* Error */
.error-message {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 3px;
  padding: 16px;
  text-align: center;
  color: #991b1b;
  font-size: 13px;
}

.error-message p {
  margin-bottom: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border: none;
  border-radius: 3px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn i {
  width: 15px;
  height: 15px;
  stroke-width: 1.5;
}

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

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

.btn-orange {
  background: var(--accent);
  color: #ffffff;
}

.btn-orange:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-secondary);
  border-color: var(--border-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  height: 36px;
  padding: 0 12px;
}

.btn-ghost:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.btn-small {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-small i {
  width: 14px;
  height: 14px;
  stroke-width: 1.5;
}

.btn-secondary.active {
  background: var(--accent-orange);
  color: white;
  border-color: var(--accent-orange);
}

.btn-secondary.active:hover {
  background: #ea580c;
  border-color: #ea580c;
}

/* Table */
.table-container {
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
}

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

.data-table th {
  text-align: left;
  padding: 12px 16px;
  background: var(--bg-secondary);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

.data-table tbody tr {
  cursor: pointer;
  transition: background 0.1s ease;
}

.data-table tbody tr:hover {
  background: var(--row-hover);
}

.data-table .text-right {
  text-align: right;
}

.data-table .text-center {
  text-align: center;
}

.data-table .text-muted {
  color: var(--text-tertiary);
}

.data-table .text-truncate {
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Status Badges */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 500;
}

.badge-success {
  background: #dcfce7;
  color: #166534;
}

/* Status badges with light backgrounds */
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 500;
}

.status-completed {
  background: #dcfce7;
  color: #166534;
}

.status-pending {
  background: #fff7ed;
  color: #c2410c;
}

.status-processing {
  background: #fef3c7;
  color: #92400e;
}

.status-error {
  background: #fee2e2;
  color: #991b1b;
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.badge-error {
  background: #fee2e2;
  color: #991b1b;
}

.badge-pending {
  background: #f3f4f6;
  color: #6b7280;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-tertiary);
}

.empty-state i {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 14px;
}

/* Money formatting */
.money {
  font-variant-numeric: tabular-nums;
  color: var(--accent-orange);
}

.money-positive {
  color: var(--success);
}

/* PDF Link */
.pdf-link-container {
  margin-bottom: 16px;
}

.pdf-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.pdf-link:hover {
  background: #fff;
  border-color: var(--border-hover);
}

/* Admin Tabs */
/* Icon-only button */
.btn-icon {
  padding: 6px;
  min-width: auto;
}

/* Detail Tabs (underline style) */
.detail-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
}

.detail-tab {
  padding: 12px 24px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-bottom: -2px;
  letter-spacing: 0.01em;
}

.detail-tab:hover {
  color: var(--text-primary);
  border-bottom-color: #fed7aa;
}

.detail-tab.active {
  color: #ea580c;
  border-bottom-color: #f97316;
  font-weight: 700;
}

/* Admin Tabs (button style) */
.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
}

.admin-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.admin-tab:hover {
  background: var(--bg-secondary);
}

.admin-tab.active {
  background: var(--bg-primary);
  color: var(--text-primary);
  border-color: var(--accent);
}

.admin-tab i {
  width: 14px;
  height: 14px;
  stroke-width: 1.5;
}

/* Admin Table */
.admin-table tbody tr {
  cursor: default;
}

.admin-table .actions {
  white-space: nowrap;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: 3px;
  width: 90%;
  max-width: 900px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 3px;
  font-size: 20px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.modal-close:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

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

.modal-body pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-secondary);
  padding: 16px;
  border-radius: 3px;
  max-height: 60vh;
  overflow: auto;
}

/* Search Results Table */
.search-results-table th:nth-child(1),
.search-results-table td:nth-child(1) {
  min-width: 200px;
}

.search-results-table th:nth-child(3),
.search-results-table td:nth-child(3) {
  min-width: 80px;
  font-weight: 600;
}

.search-results-table th:nth-child(6),
.search-results-table td:nth-child(6) {
  max-width: 180px;
}

/* Sortable Headers */
.sortable {
  cursor: pointer;
  user-select: none;
}

.sortable:hover {
  background: var(--bg-secondary);
}

.sort-icon {
  font-size: 10px;
  margin-left: 4px;
  opacity: 0.5;
}

.sort-icon.asc::after {
  content: '▲';
  opacity: 1;
}

.sort-icon.desc::after {
  content: '▼';
  opacity: 1;
}

/* Responsive */
@media (max-width: 1024px) {
  .stats-grid,
  .product-stats {
    grid-template-columns: repeat(2, 1fr);
  }

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

@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

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

  .main-content {
    margin-left: 0;
  }

  .page {
    padding: 16px;
  }

  .stats-grid,
  .product-stats {
    grid-template-columns: 1fr;
  }

  .data-table {
    font-size: 12px;
  }

  .data-table th,
  .data-table td {
    padding: 10px 12px;
  }

  .modal-content {
    width: 95%;
    max-height: 90vh;
  }
}
