/* Jonkai GA Dashboard Styles */

:root {
  /* Jonkai Brand Colors */
  --primary-dark: #2C7A7B;
  --primary: #319795;
  --primary-light: #38B2AC;

  /* Neutrals */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-dark: #1a202c;

  --text-primary: #333333;
  --text-secondary: #666666;
  --text-muted: #718096;
  --text-light: #cbd5e0;

  --border-light: #e2e8f0;
  --border-dark: #2d3748;

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #2C7A7B 0%, #319795 50%, #38B2AC 100%);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  --spacing-2xl: 48px;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* ============ LOGIN SCREEN ============ */

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-primary);
  padding: var(--spacing-lg);
}

.login-container {
  background: var(--bg-primary);
  padding: var(--spacing-2xl);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
}

.login-header {
  text-align: center;
  margin-bottom: var(--spacing-xl);
}

.logo {
  display: inline-block;
  margin-bottom: var(--spacing-md);
}

.logo svg {
  width: 64px;
  height: 64px;
}

.login-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--spacing-xs);
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.input-group {
  margin-bottom: var(--spacing-lg);
}

.input-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--spacing-sm);
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(49, 151, 149, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  width: 100%;
  background: var(--gradient-primary);
  color: white;
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary.loading span {
  opacity: 0;
}

.btn-primary .spinner {
  display: none;
  width: 20px;
  height: 20px;
  animation: spin 1s linear infinite;
  position: absolute;
}

.btn-primary.loading .spinner {
  display: block;
}

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

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

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

.btn-icon {
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
}

.btn-icon:hover {
  color: var(--primary);
  background: rgba(49, 151, 149, 0.1);
  border-radius: var(--radius-md);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

.error-message {
  color: #e53e3e;
  font-size: 0.875rem;
  text-align: center;
  margin-top: var(--spacing-md);
}

/* ============ DASHBOARD SCREEN ============ */

#dashboard-screen {
  min-height: 100vh;
  padding: var(--spacing-lg);
  max-width: 1600px;
  margin: 0 auto;
}

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--spacing-xl);
  padding-bottom: var(--spacing-lg);
  border-bottom: 1px solid var(--border-light);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.logo-small svg {
  width: 40px;
  height: 40px;
}

.header-left h1 {
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.date-select {
  padding: 8px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  background: white;
  cursor: pointer;
}

.date-select:focus {
  outline: none;
  border-color: var(--primary);
}

/* ============ SUMMARY CARDS ============ */

.summary-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
}

.summary-card {
  background: white;
  padding: var(--spacing-lg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.summary-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.summary-icon svg {
  width: 24px;
  height: 24px;
}

.summary-icon.users {
  background: rgba(44, 122, 123, 0.1);
  color: var(--primary-dark);
}

.summary-icon.sessions {
  background: rgba(49, 151, 149, 0.1);
  color: var(--primary);
}

.summary-icon.pageviews {
  background: rgba(56, 178, 172, 0.1);
  color: var(--primary-light);
}

.summary-icon.properties {
  background: rgba(113, 128, 150, 0.1);
  color: var(--text-muted);
}

.summary-content {
  display: flex;
  flex-direction: column;
}

.summary-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.summary-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ============ CONTROLS ============ */

.controls-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-lg);
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  background: white;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  flex: 1;
  max-width: 400px;
}

.search-box svg {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-box input {
  border: none;
  outline: none;
  width: 100%;
  font-size: 0.95rem;
}

.sort-controls {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.sort-controls label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.sort-controls select {
  padding: 8px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  background: white;
}

#sort-order svg {
  transition: transform 0.2s;
}

#sort-order.asc svg {
  transform: rotate(180deg);
}

/* ============ PROPERTIES GRID ============ */

.properties-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--spacing-lg);
}

.loading-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--spacing-2xl);
  color: var(--text-secondary);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto var(--spacing-md);
}

.property-card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.property-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.property-header {
  background: var(--gradient-primary);
  padding: var(--spacing-md) var(--spacing-lg);
  color: white;
}

.property-name {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.property-account {
  font-size: 0.75rem;
  opacity: 0.8;
  margin-top: 2px;
}

.property-metrics {
  padding: var(--spacing-lg);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--spacing-md);
}

.metric {
  text-align: center;
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.metric-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.property-card.error .property-header {
  background: linear-gradient(135deg, #9b2c2c 0%, #c53030 100%);
}

.property-card.error .property-metrics {
  text-align: center;
  color: var(--text-secondary);
}

.property-footer {
  padding: var(--spacing-sm) var(--spacing-lg);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-light);
  text-align: center;
}

.view-details {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 500;
}

.property-card {
  cursor: pointer;
}

/* ============ MODAL ============ */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: white;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  margin: var(--spacing-lg);
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-body {
  padding: var(--spacing-lg);
}

.modal-body h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: var(--spacing-lg);
  color: var(--text-primary);
}

.message {
  font-size: 0.875rem;
  margin-top: var(--spacing-md);
  padding: var(--spacing-md);
  border-radius: var(--radius-md);
}

.message.success {
  background: rgba(56, 178, 172, 0.1);
  color: var(--primary-dark);
}

.message.error {
  background: rgba(229, 62, 62, 0.1);
  color: #c53030;
}

/* ============ PROPERTY DETAIL MODAL ============ */

.modal-large {
  max-width: 900px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-large .modal-header {
  flex-shrink: 0;
}

.modal-large .modal-body {
  flex: 1;
  overflow-y: auto;
}

.modal-title-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.modal-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: normal;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.realtime-badge {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: 4px 12px;
  background: rgba(56, 178, 172, 0.1);
  border-radius: 20px;
  font-size: 0.75rem;
  color: var(--primary-dark);
  font-weight: 500;
}

.realtime-dot {
  width: 8px;
  height: 8px;
  background: #38B2AC;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

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

/* Tabs */
.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-light);
  padding: 0 var(--spacing-lg);
  flex-shrink: 0;
}

.tab-btn {
  padding: var(--spacing-md) var(--spacing-lg);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

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

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

.tab-content {
  display: none;
}

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

/* Chart */
.chart-container {
  margin-bottom: var(--spacing-lg);
}

.chart-container h3 {
  margin-bottom: var(--spacing-md);
}

.simple-chart {
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 120px;
  width: 100%;
  padding: var(--spacing-sm) 0;
}

.chart-bar-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}

.chart-bar {
  width: 100%;
  max-width: 30px;
  background: var(--gradient-primary);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  min-height: 4px;
  margin-top: auto;
  transition: height 0.3s;
}

.chart-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-top: 4px;
  white-space: nowrap;
}

/* Metrics row */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--spacing-md);
}

.metric-card {
  background: var(--bg-secondary);
  padding: var(--spacing-md);
  border-radius: var(--radius-md);
  text-align: center;
}

.metric-card-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.metric-card-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

/* Detail grid */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--spacing-lg);
}

.detail-section {
  background: var(--bg-secondary);
  padding: var(--spacing-md);
  border-radius: var(--radius-md);
}

.detail-section.wide {
  grid-column: span 2;
}

.detail-section h3 {
  font-size: 0.875rem;
  margin-bottom: var(--spacing-md);
  padding-bottom: var(--spacing-sm);
  border-bottom: 1px solid var(--border-light);
}

/* Data list */
.data-list {
  max-height: 200px;
  overflow-y: auto;
}

.data-items {
  list-style: none;
}

.data-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-sm) 0;
  border-bottom: 1px solid var(--border-light);
}

.data-item:last-child {
  border-bottom: none;
}

.data-item-label {
  font-size: 0.875rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}

.data-item-value {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.no-data {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  padding: var(--spacing-md);
}

.error-text {
  font-size: 0.875rem;
  color: #c53030;
  text-align: center;
}

/* Device chart */
.device-chart {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

.device-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.device-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

.device-icon svg {
  width: 20px;
  height: 20px;
}

.device-info {
  flex: 1;
}

.device-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  text-transform: capitalize;
}

.device-bar {
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  margin-top: 4px;
  overflow: hidden;
}

.device-bar-fill {
  height: 100%;
  background: var(--gradient-primary);
  border-radius: 3px;
  transition: width 0.3s;
}

.device-percent {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 50px;
  text-align: right;
}

/* Pages table */
.data-table {
  overflow-x: auto;
}

.pages-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.pages-table th,
.pages-table td {
  padding: var(--spacing-sm);
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

.pages-table th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.7rem;
  text-transform: uppercase;
}

.pages-table td {
  color: var(--text-primary);
}

.page-path {
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Loading spinner small */
.loading-spinner.small {
  width: 24px;
  height: 24px;
  border-width: 2px;
}

/* ============ RESPONSIVE ============ */

@media (max-width: 768px) {
  #dashboard-screen {
    padding: var(--spacing-md);
  }

  .dashboard-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--spacing-md);
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
  }

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

  .controls-section {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    max-width: none;
  }

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

@media (max-width: 480px) {
  .summary-section {
    grid-template-columns: 1fr;
  }

  .sort-controls {
    flex-wrap: wrap;
  }
}

/* Modal responsive */
@media (max-width: 768px) {
  .modal-large {
    margin: 0;
    max-height: 100vh;
    border-radius: 0;
  }

  .modal-tabs {
    overflow-x: auto;
    padding: 0 var(--spacing-md);
  }

  .tab-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    white-space: nowrap;
  }

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

  .detail-section.wide {
    grid-column: span 1;
  }

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

  .chart-label {
    display: none;
  }
}
