:root {
  --primary: #0078d4;
  --primary-dark: #005a9e;
  --bg: #f3f2f1;
  --card-bg: #ffffff;
  --border: #e0e0e0;
  --text: #323130;
  --text-muted: #605e5c;
  --required: #d13438;
  --available: #107c10;
  --uninstall: #605e5c;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --radius: 6px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

.hidden { display: none !important; }

/* ── Login View ── */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0078d4 0%, #005a9e 100%);
}

.login-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 48px 40px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.login-icon {
  width: 56px;
  height: 56px;
  background: var(--primary);
  border-radius: 12px;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-icon svg { width: 32px; height: 32px; fill: white; }

.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

.login-card p {
  margin: 0 0 28px;
  color: var(--text-muted);
  line-height: 1.5;
}

#login-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
  justify-content: center;
}

#login-btn:hover { background: var(--primary-dark); }

/* ── Dashboard View ── */
#dashboard-view {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.dash-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.dash-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}

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

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

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

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

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

/* Progress */
#progress-container {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 8px 24px;
}

#progress-bar-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 6px;
}

#progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s;
  width: 0%;
}

#progress-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* Main content */
.dash-content {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* Stat Cards */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg { width: 24px; height: 24px; fill: white; }
.stat-icon.blue { background: #0078d4; }
.stat-icon.indigo { background: #5c2d91; }
.stat-icon.teal { background: #008272; }
.stat-icon.orange { background: #ca5010; }

.stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}

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

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

.chart-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.chart-card h3 {
  margin: 0 0 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.chart-container {
  position: relative;
  height: 260px;
}

/* Search Section */
.search-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.search-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.search-card h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
}

.search-input-wrap {
  position: relative;
  margin-bottom: 12px;
}

.search-input-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  fill: var(--text-muted);
  pointer-events: none;
}

input[type="text"], select {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--card-bg);
  outline: none;
  transition: border-color 0.15s;
}

select { padding-left: 12px; }

input[type="text"]:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0,120,212,0.15);
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.search-placeholder {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 24px 0;
}

/* Result Cards */
.result-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.result-card:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(0,120,212,0.2);
}

.result-app-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
}

.result-app-name a {
  color: var(--primary);
  text-decoration: none;
}

.result-app-name a:hover { text-decoration: underline; }

.result-app-type {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.assignment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.assignment-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  background: var(--bg);
  border-radius: 4px;
  padding: 3px 8px;
}

.assignment-item a {
  color: var(--text);
  text-decoration: none;
}

.assignment-item a:hover { color: var(--primary); text-decoration: underline; }

/* Intent Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-required { background: #fde7e9; color: var(--required); }
.badge-available { background: #dff6dd; color: var(--available); }
.badge-uninstall { background: #f3f2f1; color: var(--uninstall); }

/* Error Banner */
#error-banner {
  background: #fde7e9;
  border: 1px solid #d13438;
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--required);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Stat cards — 6 columns */
.stat-cards { grid-template-columns: repeat(6, 1fr); }
.stat-icon.red { background: #d13438; }

/* Secondary Nav */
.secondary-nav {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  gap: 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

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

.nav-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Page Views */
.page-view {
  flex: 1;
  overflow-y: auto;
}

.page-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

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

/* Data Tables */
.table-wrap {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
}

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

.data-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  background: #faf9f8;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

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

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

.table-app-name {
  font-weight: 500;
  color: var(--text);
}

.table-app-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

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

.intent-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 4px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
  white-space: nowrap;
}

/* Tabs */
.tabs-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: #faf9f8;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab-bar::-webkit-scrollbar { display: none; }

.tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}

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

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--card-bg);
}

.tab-content { padding: 20px; }

.tab-panel .search-results {
  max-height: 500px;
  overflow-y: auto;
}

.results-count {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 1100px) {
  .charts-row { grid-template-columns: 1fr 1fr; }
  .charts-row .chart-card:last-child { grid-column: 1 / -1; }
}

@media (max-width: 1200px) {
  .stat-cards { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .charts-row .chart-card:last-child { grid-column: auto; }
  .search-section { grid-template-columns: 1fr; }
  .dash-header h1 span { display: none; }
  .header-right .user-info .username { display: none; }
}

@media (max-width: 480px) {
  .stat-cards { grid-template-columns: 1fr; }
  .dash-content { padding: 16px; }
}

/* ── Clickable Table Rows ── */
.clickable-row { cursor: pointer; }

/* ── How It Works — Login Card ── */
.how-section {
  margin-top: 24px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  text-align: left;
}

.how-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  padding: 4px 0;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  gap: 8px;
}

.how-toggle:hover { color: var(--text); }

.how-chevron {
  width: 16px;
  height: 16px;
  fill: currentColor;
  flex-shrink: 0;
  transition: transform 0.2s;
}

.how-toggle[aria-expanded="true"] .how-chevron {
  transform: rotate(180deg);
}

.how-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.how-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}

.how-icon {
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1.2;
}

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

.modal-card {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
}

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

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

.modal-body {
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-body .how-item {
  font-size: 14px;
}

/* ── Breadcrumb Navigation (Detail Pages) ── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.breadcrumb a,
.breadcrumb button {
  color: var(--primary);
  text-decoration: none;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}

.breadcrumb a:hover,
.breadcrumb button:hover { text-decoration: underline; }

.breadcrumb-sep {
  color: var(--border);
  user-select: none;
}

.breadcrumb-current {
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}

/* ── Detail Page Header ── */
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.detail-title-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.detail-title-block h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
