/* CSS Variables for theming */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #f1f5f9;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --accent-color: #3b82f6;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --radius: 8px;
  --sidebar-width: 260px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --bg-sidebar: #0f172a;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  }
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Base */
html, body {
  height: 100%;
}

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

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

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

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

.sidebar-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.sidebar-nav {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

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

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

.nav-item.active {
  background: var(--accent-color);
  color: white;
}

.nav-item-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

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

.page-header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-card);
}

.page-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
}

.plugin-container {
  flex: 1;
  padding: 2rem;
  background: var(--bg-secondary);
}

/* Plugin Page Card */
.plugin-page {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  max-width: 800px;
}

/* KPI Card Base (for grid view) */
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

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

.kpi-card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Counter Plugin */
.kpi-counter .kpi-card-prefix,
.kpi-counter .kpi-card-suffix {
  font-size: 1.25rem;
  font-weight: 500;
  opacity: 0.7;
}

/* Progress Plugin */
.kpi-progress .progress-bar,
.progress-bar {
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 1rem;
}

.kpi-progress .progress-fill,
.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.kpi-progress .progress-label,
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

/* Sparkline Plugin */
.kpi-sparkline .sparkline-container,
.sparkline-container {
  height: 80px;
  margin-top: 1rem;
  position: relative;
}

.kpi-sparkline svg,
.sparkline-container svg {
  width: 100%;
  height: 100%;
}

.kpi-sparkline .sparkline-path,
.sparkline-path {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.kpi-sparkline .sparkline-area,
.sparkline-area {
  opacity: 0.1;
}

/* Loading State */
.kpi-loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-secondary);
}

/* Error State */
.kpi-error {
  text-align: center;
  padding: 3rem;
  color: #ef4444;
}

/* X Bookmarks Plugin */
.xb-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.xb-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.xb-refresh-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.xb-refresh-btn:hover {
  background: var(--border-color);
  color: var(--text-primary);
}

.xb-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.xb-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.xb-card-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.xb-card-value {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1;
}

.xb-card-subtext {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-secondary);
}

.xb-progress-bar {
  height: 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 1rem;
}

.xb-progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.xb-random-card {
  grid-column: span 2;
}

.xb-bookmark-link {
  font-size: 1rem;
  text-decoration: none;
  display: block;
  line-height: 1.5;
  margin-bottom: 0.5rem;
}

.xb-bookmark-link:hover {
  text-decoration: underline;
}

.xb-bookmark-author {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.xb-pick-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.xb-pick-btn:hover {
  background: var(--border-color);
  color: var(--text-primary);
}

.xb-loading {
  color: var(--text-secondary);
  padding: 2rem;
  text-align: center;
}

.xb-error-card {
  text-align: center;
  color: #ef4444;
}

.xb-error-card small {
  display: block;
  margin-top: 0.5rem;
  color: var(--text-secondary);
}

.xb-auth-card {
  text-align: center;
  padding: 2rem;
}

.xb-auth-btn {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.75rem 1.5rem;
  color: white;
  text-decoration: none;
  border-radius: var(--radius);
  font-weight: 500;
}

.xb-auth-btn:hover {
  opacity: 0.9;
}

.xb-empty {
  color: var(--text-secondary);
}

.xb-card-source {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  text-transform: uppercase;
}

/* TickTick Plugin */
.tt-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.tt-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.tt-refresh-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.tt-refresh-btn:hover {
  background: var(--border-color);
  color: var(--text-primary);
}

.tt-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.tt-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.tt-card-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.tt-card-value {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1;
}

.tt-card-source {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  text-transform: uppercase;
}

.tt-random-card {
  grid-column: span 2;
}

.tt-task-link {
  font-size: 1rem;
  text-decoration: none;
  display: block;
  line-height: 1.5;
  margin-bottom: 0.5rem;
}

.tt-task-link:hover {
  text-decoration: underline;
}

.tt-task-project {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.tt-pick-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.tt-pick-btn:hover {
  background: var(--border-color);
  color: var(--text-primary);
}

.tt-loading {
  color: var(--text-secondary);
  padding: 2rem;
  text-align: center;
}

.tt-error-card {
  text-align: center;
  color: #ef4444;
}

.tt-error-card small {
  display: block;
  margin-top: 0.5rem;
  color: var(--text-secondary);
}

.tt-empty {
  color: var(--text-secondary);
}

.tt-auth-card {
  text-align: center;
  padding: 2rem;
}

.tt-auth-btn {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.75rem 1.5rem;
  color: white;
  text-decoration: none;
  border-radius: var(--radius);
  font-weight: 500;
}

.tt-auth-btn:hover {
  opacity: 0.9;
}

/* Ranking Plugin */
.rk-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.rk-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.rk-refresh-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.rk-refresh-btn:hover {
  background: var(--border-color);
  color: var(--text-primary);
}

.rk-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.rk-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.rk-card-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.rk-card-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.rk-card-sub {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.rk-change {
  font-size: 0.875rem;
  margin-top: 0.5rem;
  font-weight: 500;
}

.rk-change.positive {
  color: #10b981;
}

.rk-change.negative {
  color: #ef4444;
}

.rk-chart-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1rem;
}

.rk-loading {
  color: var(--text-secondary);
  padding: 2rem;
  text-align: center;
}

.rk-error {
  text-align: center;
  color: #ef4444;
  padding: 2rem;
}

.rk-error small {
  display: block;
  margin-top: 0.5rem;
  color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
    gap: 0.5rem;
  }

  .nav-item {
    white-space: nowrap;
  }

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

  .plugin-container {
    padding: 1rem;
  }
}
