:root {
  --bg: #0b1020;
  --bg-alt: #121a2b;
  --panel: #111827;
  --panel-strong: #172033;
  --panel-soft: #1b2438;
  --chip: rgba(148, 163, 184, 0.08);
  --text: #edf3ff;
  --muted: #93a4bf;
  --border: rgba(148, 163, 184, 0.18);
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.24);
  --accent: #8b5cf6;
  --accent-soft: rgba(139, 92, 246, 0.18);
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --info: #22d3ee;
  --radius: 16px;
  --radius-sm: 12px;
  --sidebar-width: 260px;
  --content-max-width: 1680px;
}

:root[data-theme="light"] {
  --bg: #eef4ff;
  --bg-alt: #f8fbff;
  --panel: #ffffff;
  --panel-strong: #f3f7ff;
  --panel-soft: #edf3ff;
  --chip: rgba(15, 23, 42, 0.04);
  --text: #122033;
  --muted: #53657c;
  --border: rgba(15, 23, 42, 0.09);
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html {
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
}

body {
  margin: 0;
  font-family: "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
  min-width: 0;
}

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  flex-shrink: 0;
  background: rgba(17, 24, 39, 0.85);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.75rem;
  transition: width 0.2s ease, flex-basis 0.2s ease, transform 0.25s ease;
  position: sticky;
  top: 0;
  height: 100vh;
}

:root[data-theme="light"] .sidebar {
  background: rgba(255, 255, 255, 0.82);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.5rem 0.75rem 1.25rem;
}

.brand-logo {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 0 0 1px var(--border);
}

.brand-name {
  font-weight: 700;
  font-size: 1.1rem;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 0.72rem;
}

.main-nav {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 0.8rem 0.85rem;
  border-radius: 12px;
  transition: 0.2s ease;
}

.nav-item:hover,
.nav-item.active {
  background: var(--panel-soft);
  border-color: var(--border);
}

.nav-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
}

.content-shell {
  flex: 1;
  min-width: 0;
}

.app-footer {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 0.75rem clamp(1rem, 2.2vw, 2rem) 1.25rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.app-footer img {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 8px;
}

.footer-copyright {
  margin-left: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 2.2vw, 2rem);
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 16, 32, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

:root[data-theme="light"] .topbar {
  background: rgba(238, 244, 255, 0.78);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.68rem;
  font-weight: 700;
}

h1, h2, h3, p {
  margin-top: 0;
}

#pageTitle {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 3vw, 2rem);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  min-width: min(100%, 350px);
}

.search-box input {
  background: transparent;
  border: none;
  color: var(--text);
  width: 100%;
}

.search-box input::placeholder {
  color: var(--muted);
}

.icon-button, .panel-toggle {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  display: grid;
  place-items: center;
}

button.secondary-button,
button.primary-button,
button.ghost-button,
button.danger-button,
button.action-button {
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-weight: 600;
  transition: transform 0.18s ease, opacity 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
}

.primary-button {
  background: var(--accent);
  color: white;
}

.secondary-button {
  background: var(--panel-soft);
  color: var(--text);
  border: 1px solid var(--border);
}

.install-button[hidden] {
  display: none;
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.danger-button {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.2);
}

.page-container {
  width: 100%;
  max-width: var(--content-max-width);
  margin-inline: auto;
  padding: clamp(1rem, 2.2vw, 2rem);
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1rem;
}

.stat-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 138px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 1rem;
}

.stat-card .stat-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.55rem;
}

.stat-label {
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.4;
}

.stat-icon {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--chip);
  color: var(--accent);
}

.stat-value {
  font-weight: 800;
  font-size: clamp(1.65rem, 2.5vw, 2rem);
  line-height: 1.15;
  margin-bottom: 0.2rem;
}

.stat-subtext {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
  margin-top: auto;
}

.content-grid {
  display: grid;
  gap: 0.9rem;
  margin-bottom: 0.9rem;
}

.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.stack-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.8rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-strong);
}

.list-row strong,
.list-row span {
  display: block;
}

.list-row small {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--chip);
  color: var(--text);
}

.badge.status-planning { background: rgba(148, 163, 184, 0.1); }
.badge.status-in-progress { background: rgba(34, 211, 238, 0.12); color: var(--info); }
.badge.status-paused { background: rgba(251, 191, 36, 0.12); color: var(--warning); }
.badge.status-completed { background: rgba(52, 211, 153, 0.12); color: var(--success); }
.badge.priority-low { background: rgba(148, 163, 184, 0.1); color: var(--muted); }
.badge.priority-medium { background: rgba(96, 165, 250, 0.1); color: #60a5fa; }
.badge.priority-high { background: rgba(251, 146, 60, 0.1); color: #f59e0b; }
.badge.priority-critical { background: rgba(248, 113, 113, 0.1); color: var(--danger); }

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.action-button {
  background: var(--panel-soft);
  color: var(--text);
  border: 1px solid var(--border);
  min-height: 44px;
  text-align: left;
}

.toolbar-panel {
  margin-bottom: 1rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  align-items: end;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.inline-field {
  min-width: 150px;
  flex: 1;
}

label {
  font-size: 0.82rem;
  color: var(--muted);
}

input, select, textarea {
  width: 100%;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.project-card {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.project-card-header,
.project-card-row,
.task-card-top,
.task-card-actions,
.task-main-row,
.meta-row,
.project-detail-header,
.project-detail-meta,
.goal-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.project-card-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.muted {
  color: var(--muted);
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--panel-soft);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #67e8f9);
}

.small-button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
}

.task-list-panel {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.task-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: var(--shadow);
}

.task-main-row {
  align-items: flex-start;
}

.task-item h3 {
  margin-bottom: 0.35rem;
}

.task-item .description {
  color: var(--muted);
  margin-bottom: 0.8rem;
}

.task-item header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.task-item .checkbox {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.7rem;
}

.task-meta span {
  background: var(--chip);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.55rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.kanban-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 1rem;
}

.kanban-column {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  min-height: 360px;
}

.kanban-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.kanban-column .task-card {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem;
  margin-bottom: 0.7rem;
}

.task-card.dragging {
  opacity: 0.6;
}

.task-card-header {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.repo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.repo-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.repo-card h3 {
  margin: 0;
  font-size: 1.05rem;
}

.repo-stats {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.8rem;
}

.inline-status {
  color: var(--muted);
  min-height: 1.4rem;
  margin-top: 0.75rem;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

.tool-card {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.tool-card textarea,
.tool-card input {
  min-height: 44px;
}

.output-box {
  min-height: 52px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  padding: 0.7rem 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.button-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.goal-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.goal-summary {
  margin-top: 1rem;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
}

.timer-box {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  align-items: center;
  justify-content: center;
}

.timer-display {
  font-size: clamp(2.2rem, 5vw, 3.5rem);
  font-weight: 800;
  letter-spacing: 0.05em;
}

.achievement-list {
  display: grid;
  gap: 0.7rem;
}

.achievement-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 0.8rem;
}

.achievement-item .icon {
  width: 2.3rem;
  height: 2.3rem;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
}

.activity-history {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.activity-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-soft);
  padding: 0.8rem 0.9rem;
}

.settings-stack {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
}

.switch-row input {
  width: 1.5rem;
  height: 1.5rem;
}

.file-upload {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background: var(--panel-soft);
  cursor: pointer;
}

.file-upload input {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 120;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(680px, calc(100vw - 2rem));
  max-height: 90vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.full-width {
  grid-column: 1 / -1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.empty-state {
  background: var(--panel-soft);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
  color: var(--muted);
  line-height: 1.5;
}

.empty-state .button-row {
  justify-content: center;
  margin-top: 0.75rem;
}

.project-detail-page {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.project-detail-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.project-detail-meta {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.project-detail-meta span {
  background: var(--chip);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  color: var(--muted);
  font-size: 0.76rem;
}

.align-right {
  text-align: right;
}

.chart-visual {
  position: relative;
  width: 100%;
  height: 240px;
}

.chart-visual canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.chart-visual canvas[hidden] {
  display: none !important;
}

.chart-empty-state {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.chart-empty-state[hidden] {
  display: none;
}

.stat-card,
.panel,
.project-card,
.tool-card,
.repo-card {
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.action-button:hover,
.secondary-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

@media (max-width: 980px) {
  .sidebar {
    position: fixed;
    z-index: 100;
    left: 0;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .kanban-board {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 981px) {
  .sidebar-collapsed .sidebar {
    width: 76px;
    flex-basis: 76px;
    padding-inline: 0.6rem;
  }

  .sidebar-collapsed .brand-row {
    justify-content: center;
    padding-inline: 0;
  }

  .sidebar-collapsed .brand-row > div:last-child,
  .sidebar-collapsed .nav-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .sidebar-collapsed .nav-item {
    justify-content: center;
    padding-inline: 0.5rem;
  }
}

@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .topbar-actions {
    flex: 0 1 340px;
    min-width: 0;
  }

  .search-box {
    flex: 1;
    min-width: 0;
  }
}

@media (max-width: 820px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .page-container {
    padding: 1rem;
  }

  .topbar {
    padding: 0.9rem 1rem;
    gap: 0.7rem;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
    min-width: 0;
  }

  .search-box {
    flex: 1;
    min-width: 0;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .app-footer {
    padding-inline: 1rem;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .chart-visual {
    height: 220px;
  }
}

@media (max-width: 420px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    gap: 0.55rem;
  }

  .chart-visual {
    height: 200px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
