/* DEWBU AI ERP Customer Service Module Styles */
/* Matches cs-supervisor-agent-v2 visual style */

:root {
  --primary: #2563eb;
  --primary-light: #3b82f6;
  --primary-dark: #1d4ed8;
  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --sidebar-bg: #0f172a;
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-active: rgba(255,255,255,0.12);
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 8px;
  --nav-height: 48px;
  --sidebar-width: 200px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', sans-serif;
  background-color: var(--bg);
  color: var(--text);
  font-size: 13px;
  min-height: 100vh;
}

/* Unified top navigation */
.unified-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 10000;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.unified-nav a,
.unified-nav .nav-dropdown-label {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  padding: 0 14px;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  transition: background 0.2s;
  cursor: pointer;
}

.unified-nav a:hover,
.unified-nav .nav-dropdown-label:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.unified-nav .nav-brand {
  font-weight: 700;
  margin-right: 8px;
  color: #fff;
}

.unified-nav .nav-divider {
  width: 1px;
  height: 24px;
  background: rgba(255,255,255,0.15);
  margin: 0 8px;
}

.unified-nav .nav-dropdown {
  position: relative;
  height: var(--nav-height);
  display: flex;
  align-items: center;
}

.unified-nav .nav-dropdown > a::after,
.unified-nav .nav-dropdown > .nav-dropdown-label::after {
  content: ' ▼';
  font-size: 9px;
  opacity: 0.6;
  margin-left: 4px;
}

.unified-nav .nav-dropdown-menu {
  display: none;
  position: absolute;
  top: var(--nav-height);
  left: 0;
  min-width: 180px;
  background: #1e293b;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.2);
  overflow: hidden;
  flex-direction: column;
}

.unified-nav .nav-dropdown:hover .nav-dropdown-menu {
  display: flex;
}

.unified-nav .nav-dropdown-menu a {
  height: 36px;
  padding: 0 16px;
  white-space: nowrap;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.unified-nav .nav-dropdown-menu a:last-child {
  border-bottom: none;
}

.unified-nav .nav-active {
  background: var(--sidebar-active) !important;
  color: #fff !important;
}

/* Layout */
.app-container {
  display: flex;
  min-height: 100vh;
  padding-top: var(--nav-height);
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: var(--nav-height);
  bottom: 0;
  z-index: 9000;
}

.brand {
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.brand span {
  font-size: 11px;
  opacity: 0.7;
  display: block;
  margin-top: 2px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  padding: 11px 16px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  font-size: 13px;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.nav-item.active {
  background: var(--sidebar-active);
  border-left-color: var(--primary);
  color: #fff;
}

.nav-group-toggle {
  display: flex;
  align-items: center;
  padding: 11px 16px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.nav-group-toggle:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.nav-group-toggle.active {
  background: var(--sidebar-active);
  border-left-color: var(--primary);
  color: #fff;
}

.nav-group-toggle .nav-arrow {
  margin-left: auto;
  font-size: 10px;
  opacity: 0.7;
  transition: transform 0.2s;
}

.nav-group.collapsed .nav-arrow {
  transform: rotate(-90deg);
}

.nav-submenu {
  display: block;
  background: rgba(0,0,0,0.12);
  padding: 6px 0;
}

.nav-group.collapsed .nav-submenu {
  display: none;
}

.nav-subitem {
  display: flex;
  align-items: center;
  padding: 9px 16px 9px 44px;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 12px;
  border-left: 3px solid transparent;
  transition: all 0.2s;
}

.nav-subitem:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.nav-subitem.active {
  background: var(--sidebar-active);
  border-left-color: var(--primary);
  color: #fff;
}

.nav-icon {
  width: 18px;
  height: 18px;
  margin-right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}

.user-profile {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
}

.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11px; opacity: 0.7; }

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 20px 24px;
  background: var(--bg);
  min-height: calc(100vh - var(--nav-height));
  max-width: calc(100% - var(--sidebar-width));
}

/* Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h2 {
  margin: 0 0 4px 0;
  font-size: 20px;
  font-weight: 700;
}

.page-header p {
  margin: 0;
  color: var(--text-muted);
}

.page-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 20px;
  margin-bottom: 20px;
}

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

.card-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 4px 0;
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* Dashboard cards */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.dashboard-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: transform 0.15s, box-shadow 0.15s;
  border-left: 4px solid var(--primary);
}

.dashboard-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.dashboard-card.success { border-left-color: var(--success); }
.dashboard-card.warning { border-left-color: var(--warning); }
.dashboard-card.danger { border-left-color: var(--danger); }
.dashboard-card.info { border-left-color: var(--primary-light); }

.dashboard-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.dashboard-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 4px 0;
}

.dashboard-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  border-left: 4px solid var(--primary);
}

.stat-card.warning { border-left-color: var(--warning); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-card.success { border-left-color: var(--success); }

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

.stat-change {
  font-size: 12px;
  color: var(--text-muted);
}

.stat-change.positive { color: var(--success); }
.stat-change.negative { color: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  background: #fff;
  color: var(--text);
}

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

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

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }

.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

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

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

/* Forms */
.search-box {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border 0.2s, box-shadow 0.2s;
  min-width: 200px;
}

.search-box:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

select.search-box {
  flex: none;
  min-width: 140px;
  background: #fff;
}

.form-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* Tags */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.tag-blue { background: #dbeafe; color: #1e40af; }
.tag-green { background: var(--success-light); color: #065f46; }
.tag-yellow { background: var(--warning-light); color: #92400e; }
.tag-red { background: var(--danger-light); color: #991b1b; }
.tag-gray { background: #f1f5f9; color: #475569; }
.tag-primary { background: #dbeafe; color: #1e40af; }

.quick-tags {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.quick-tags .tag {
  cursor: pointer;
  transition: all 0.15s;
}

.quick-tags .tag:hover {
  filter: brightness(0.95);
}

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg);
}

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

/* Order detail */
.order-detail-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.order-detail-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}

.order-detail-card .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.order-detail-card .value {
  font-size: 15px;
  font-weight: 600;
  word-break: break-word;
  line-height: 1.4;
}

.ai-summary-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}

.ai-summary-box h4 {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--primary);
}

.ai-summary-box ul {
  margin: 0;
  padding-left: 18px;
}

.ai-summary-box li {
  margin-bottom: 4px;
  line-height: 1.5;
}

/* Product image */
.product-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.product-thumb-empty {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-muted);
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
}

/* Tracking */
.tracking-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.tracking-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tracking-timeline {
  position: relative;
  padding-left: 20px;
}

.tracking-timeline::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--border);
}

.tracking-event {
  position: relative;
  margin-bottom: 16px;
}

.tracking-event::before {
  content: '';
  position: absolute;
  left: -18px;
  top: 3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--primary);
}

.tracking-event.current::before {
  background: var(--success);
  box-shadow: 0 0 0 2px var(--success);
}

.tracking-event.exception::before {
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--danger);
}

.tracking-event-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.tracking-event-text {
  font-size: 13px;
  font-weight: 600;
}

.tracking-event-location {
  font-size: 12px;
  color: var(--text-muted);
}

/* Async task card */
.async-task-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

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

.async-task-title {
  font-weight: 700;
  font-size: 14px;
}

.async-task-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.async-task-progress {
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 10px;
}

.async-task-progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.async-task-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

.pulse {
  animation: pulse 1.5s infinite;
}

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

/* Sessions */
.session-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  background: var(--card-bg);
}

.session-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
}

.session-title {
  font-weight: 700;
  font-size: 13px;
  margin: 0 0 4px 0;
}

.session-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.session-message {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 10px;
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 10px;
}

.session-ai-reply {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 10px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--primary-dark);
  white-space: pre-wrap;
}

/* Results */
.result-panel {
  display: none;
}

.result-panel.show {
  display: block;
}

.result-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 40px 20px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.result-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 14px 16px;
  color: #991b1b;
}

.result-error .error-code {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 4px;
}

.result-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 20px;
  margin-bottom: 20px;
}

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

.result-section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 4px 0;
}

.result-section-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* Grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* Utility */
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mb-0 { margin-bottom: 0; }
.mt-12 { margin-top: 12px; }

/* Loading */
.loading {
  display: none;
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
  font-size: 13px;
}

.loading.show { display: block; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Responsive */
@media (max-width: 1200px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .order-detail-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 992px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .order-detail-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .unified-nav {
    padding: 0 10px;
    font-size: 12px;
  }

  .unified-nav a {
    padding: 0 8px;
  }

  .unified-nav .nav-brand {
    font-size: 12px;
  }

  .unified-nav .nav-dropdown > a::after {
    display: none;
  }

  .unified-nav .nav-dropdown-menu {
    display: none !important;
  }

  .sidebar {
    width: 60px;
  }

  .brand h1, .brand span, .nav-text, .user-profile {
    display: none;
  }

  .nav-item {
    justify-content: center;
    padding: 12px 0;
    border-left: none;
    border-bottom: 2px solid transparent;
  }

  .nav-item.active {
    border-left-color: transparent;
    border-bottom-color: var(--primary);
  }

  .nav-icon {
    margin-right: 0;
  }

  .main-content {
    margin-left: 60px;
    max-width: calc(100% - 60px);
    padding: 16px;
  }

  .form-row {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box, .btn {
    width: 100%;
  }

  select.search-box {
    min-width: 100%;
  }

  .order-detail-grid { grid-template-columns: 1fr; }
  .tracking-header { flex-direction: column; align-items: flex-start; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .async-task-header { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
  .unified-nav .nav-brand {
    display: none;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}
