@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #f5f5f7;
  --bg-card: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(0, 0, 0, 0.06);
  --glass-shadow: 0 2px 12px rgba(0, 0, 0, 0.03);

  --apple-blue: #0071e3;
  --apple-green: #34c759;
  --apple-orange: #ff9f0a;
  --apple-red: #ff3b30;
  --apple-purple: #5856d6;
  --apple-indigo: #4f46e5;
  --apple-cyan: #5ac8fa;

  --text-main: #1d1d1f;
  --text-secondary: #424245;
  --text-muted: #86868b;

  --font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Inter', sans-serif;
  --border-radius: 14px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: var(--font-family);
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.dashboard-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
}

.logo {
    margin-bottom: 3rem;
    padding-left: 1rem;
}

.logo h2 {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.875rem 1rem;
    border-radius: 0.5rem;
    text-align: left;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-item.active {
    background-color: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
    border-left: 3px solid var(--accent-blue);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem 3rem;
    overflow-y: auto;
}

.top-header {
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.top-header h1 {
    font-size: 1.75rem;
    font-weight: 600;
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* ─── Cards ─── */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius);
  box-shadow: var(--glass-shadow);
  padding: 16px 18px;
  transition: all 0.2s ease;
}

.card:hover {
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.05);
}

/* ─── Segmented Control Tabs (Apple Style) ─── */
.tabs-container {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.05);
  padding: 3px;
  border-radius: 10px;
  margin-bottom: 16px;
  gap: 2px;
}

.tab-btn {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  background: transparent;
  user-select: none;
  white-space: nowrap;
}

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

.tab-btn.active {
  background: #ffffff;
  color: var(--text-main);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ─── Metric Badges & KPIs ─── */
.kpi-title {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.kpi-num {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.trend-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  margin-top: 4px;
}

.trend-badge.positive {
  background: rgba(52, 199, 89, 0.12);
  color: var(--apple-green);
}

.trend-badge.negative {
  background: rgba(255, 59, 48, 0.12);
  color: var(--apple-red);
}

/* ─── Tables ─── */
.table-wrapper {
  overflow-x: auto;
  border-radius: 10px;
}

.dealer-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 12px;
}

.dealer-table th {
  padding: 8px 10px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.02);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  white-space: nowrap;
}

.dealer-table td {
  padding: 7px 10px;
  font-size: 11.5px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
  color: var(--text-main);
  white-space: nowrap;
}

.dealer-table tr:hover td {
  background: rgba(0, 113, 227, 0.02);
}

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

/* ─── Form Controls & Selects ─── */
.apple-select {
  appearance: none;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: var(--text-main);
  padding: 6px 24px 6px 10px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2386868b' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: all 0.15s ease;
}

.apple-select:focus {
  border-color: var(--apple-blue);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

.apple-input {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 11.5px;
  outline: none;
  transition: all 0.15s ease;
}

.apple-input:focus {
  border-color: var(--apple-blue);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

/* ─── AI Markdown Summary Box ─── */
.markdown-report h2 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 10px;
  margin-bottom: 6px;
  letter-spacing: -0.2px;
}

.markdown-report h2:first-child {
  margin-top: 0;
}

.markdown-report h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 8px;
  margin-bottom: 4px;
}

.markdown-report ul {
  list-style-type: none;
  padding-left: 0;
  margin-bottom: 8px;
}

.markdown-report li {
  position: relative;
  padding-left: 14px;
  margin-bottom: 3px;
  line-height: 1.45;
  font-size: 11.5px;
}

.markdown-report li::before {
  content: "•";
  position: absolute;
  left: 3px;
  color: var(--apple-blue);
  font-weight: bold;
}

.markdown-report blockquote {
  border-left: 3px solid var(--apple-blue);
  padding: 6px 12px;
  background: rgba(0, 113, 227, 0.04);
  border-radius: 0 8px 8px 0;
  margin: 8px 0;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.markdown-report table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 11.5px;
  border-radius: 8px;
  overflow: hidden;
}

.markdown-report th, .markdown-report td {
  border: 1px solid rgba(0, 0, 0, 0.06);
  padding: 5px 8px;
  text-align: left;
}

.markdown-report th {
  background: rgba(0, 0, 0, 0.03);
  font-weight: 600;
  color: var(--text-muted);
}

/* ─── Scrollbars ─── */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.22);
}

/* ─── Print ─── */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #ffffff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; zoom: 0.8 !important; }
  .no-print { display: none !important; }
  .card { box-shadow: none !important; border: 1px solid rgba(0,0,0,0.1) !important; break-inside: avoid !important; margin-bottom: 10px !important; }
  .tab-btn { display: none !important; }
  .tab-content { display: block !important; }
}

/* Platform Toggles */
.platform-toggles {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.25rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
}

.plat-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.plat-btn.active {
    background: var(--accent-blue);
    color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Cards */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* KPIs */
.kpi-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.kpi-card h3 {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.highlight-blue { color: var(--accent-blue); }
.highlight-cyan { color: var(--accent-cyan); }
.highlight-purple { color: var(--accent-purple); }
.highlight-orange { color: var(--accent-orange); }

/* Charts Layout */
.charts-grid-two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.charts-grid-full {
    margin-bottom: 2rem;
}

.chart-container h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.chart-container canvas {
    max-height: 300px;
    width: 100%;
}

/* Tables and Top Models */
.table-section {
    margin-bottom: 2rem;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.table-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.dropdown {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    outline: none;
    cursor: pointer;
}
.dropdown option {
    background: var(--bg-card);
    color: var(--text-primary);
}

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th, td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

th {
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

tr:hover td {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Monthly Mini Tables */
.monthly-tables-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.mini-table-container {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0.75rem;
    padding: 1rem;
    border-top: 3px solid;
}

.border-ecovacs { border-color: #10b981; }
.border-dreame { border-color: var(--accent-orange); }
.border-roborock { border-color: var(--accent-blue); }

.brand-title {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    text-align: center;
}
.text-ecovacs { color: #10b981; }
.text-dreame { color: var(--accent-orange); }
.text-roborock { color: var(--accent-blue); }

.mini-table th, .mini-table td {
    padding: 0.5rem;
    font-size: 0.75rem;
}

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

.rank-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    background: rgba(255, 255, 255, 0.1);
    font-weight: 600;
    font-size: 0.75rem;
}

.rank-1 { background: rgba(59, 130, 246, 0.2); color: var(--accent-blue); }
.rank-2 { background: rgba(6, 182, 212, 0.2); color: var(--accent-cyan); }
.rank-3 { background: rgba(139, 92, 246, 0.2); color: var(--accent-purple); }

.brand-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 500;
}

.brand-dreame { background: rgba(249, 115, 22, 0.15); color: var(--accent-orange); }
.brand-roborock { background: rgba(59, 130, 246, 0.15); color: var(--accent-blue); }
.brand-ecovacs { background: rgba(16, 185, 129, 0.15); color: #10b981; }

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