﻿:root {
  color-scheme: light dark;
  --bg: #f4f4f4;
  --panel: #ffffff;
  --line: #e0e0e0;
  --text: #1b1b1b;
  --muted: #6b6b6b;
  --accent: #1f9cf0;
  --accent-strong: #0d7fd0;
  --danger-border: #f0c8c8;
  --danger-text: #ad2a2a;
  --header-bg: #f7f7f7;
  --row-line: #ebebeb;
  --row-hover: #f3f3f3;
  --btn-hover: #efefef;
  --menu-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
  --backdrop: rgba(9, 12, 16, 0.35);
  --sidebar-bg: #ebebeb;
  --sidebar-active: #e1e1e1;
  --sidebar-hover: #e6e6e6;
  --sidebar-tab-border: #d4d4d4;
  --warning-bg: #ffe2e2;
  --warning-border: #f0a4a4;
  --warning-text: #a52626;
  --status-success: #1d8a4b;
  --topbar-height: 62px;
  --window-bar-height: 32px;
  --window-tab-bg: #1f1f1f;
  --section-gap: 12px;
  font-family: "Segoe UI", "Inter", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --panel: #1b1b1e;
    --line: #343434;
    --text: #e8e8e8;
    --muted: #9e9e9e;
    --accent: #2ba8ff;
    --accent-strong: #1895ee;
    --danger-border: #5a3131;
    --danger-text: #ff8d8d;
    --header-bg: #202020;
    --row-line: #2d2d2d;
    --row-hover: #262626;
    --btn-hover: #252525;
    --menu-shadow: 0 14px 28px rgba(0, 0, 0, 0.45);
    --backdrop: rgba(0, 0, 0, 0.55);
    --sidebar-bg: #181818;
    --sidebar-active: #232323;
    --sidebar-hover: #1f1f1f;
    --sidebar-tab-border: #2f2f2f;
    --warning-bg: #3d2323;
    --warning-border: #8a3a3a;
    --warning-text: #ff9f9f;
    --status-success: #5bd38d;
    --window-tab-bg: #141414;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f4f4;
  --panel: #ffffff;
  --line: #e0e0e0;
  --text: #1b1b1b;
  --muted: #6b6b6b;
  --accent: #1f9cf0;
  --accent-strong: #0d7fd0;
  --danger-border: #f0c8c8;
  --danger-text: #ad2a2a;
  --header-bg: #f7f7f7;
  --row-line: #ebebeb;
  --row-hover: #f3f3f3;
  --btn-hover: #efefef;
  --menu-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
  --backdrop: rgba(9, 12, 16, 0.35);
  --sidebar-bg: #ebebeb;
  --sidebar-active: #e1e1e1;
  --sidebar-hover: #e6e6e6;
  --sidebar-tab-border: #d4d4d4;
  --warning-bg: #ffe2e2;
  --warning-border: #f0a4a4;
  --warning-text: #a52626;
  --status-success: #1d8a4b;
  --window-tab-bg: #1f1f1f;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212;
  --panel: #1b1b1e;
  --line: #343434;
  --text: #e8e8e8;
  --muted: #9e9e9e;
  --accent: #2ba8ff;
  --accent-strong: #1895ee;
  --danger-border: #5a3131;
  --danger-text: #ff8d8d;
  --header-bg: #202020;
  --row-line: #2d2d2d;
  --row-hover: #262626;
  --btn-hover: #252525;
  --menu-shadow: 0 14px 28px rgba(0, 0, 0, 0.45);
  --backdrop: rgba(0, 0, 0, 0.55);
  --sidebar-bg: #181818;
  --sidebar-active: #232323;
  --sidebar-hover: #1f1f1f;
  --sidebar-tab-border: #2f2f2f;
  --warning-bg: #3d2323;
  --warning-border: #8a3a3a;
  --warning-text: #ff9f9f;
  --status-success: #5bd38d;
  --window-tab-bg: #141414;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
}

input,
textarea,
select {
  user-select: text;
  -webkit-user-select: text;
}

.app-root {
  height: 100vh;
  display: grid;
  grid-template-rows: var(--window-bar-height) minmax(0, 1fr);
  overflow: hidden;
}

.window-bar {
  background: var(--window-tab-bg);
  border-bottom: 1px solid var(--line);
  -webkit-app-region: drag;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 220px 1fr;
  overflow: hidden;
}

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
}

.side-tab:first-of-type {
  margin-top: var(--section-gap);
}

.sidebar-brand {
  position: relative;
  margin-top: var(--section-gap);
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  -webkit-app-region: drag;
}

.sidebar-brand-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.sidebar-brand-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  opacity: 0.3;
}

.side-tab {
  border: 0;
  background: transparent;
  color: var(--text);
  border-radius: 0;
  height: 44px;
  padding: 0 12px;
  text-align: left;
  cursor: pointer;
  font: inherit;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 120ms ease;
  outline: none;
  -webkit-app-region: no-drag;
}

.side-tab:hover {
  background: color-mix(in srgb, var(--sidebar-hover) 70%, #ffffff);
}

.side-tab.active {
  background: color-mix(in srgb, var(--sidebar-active) 78%, #ffffff);
  box-shadow: none;
}

.tab-icon {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  background: transparent;
  border: 0;
}

.tab-icon svg {
  width: 32px;
  height: 32px;
  display: block;
}

.side-tab.active .tab-icon {
  color: var(--text);
  background: transparent;
}

.tab-label {
  font-weight: 600;
  font-size: 13px;
}

.side-spacer { flex: 1; }

.panel-host {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  overflow: hidden;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) min-content;
  gap: 0;
  min-height: 0;
  height: 100%;
}

.toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 10px 10px 22px;
  min-height: var(--topbar-height);
  border: 1px solid var(--line);
  border-top: 0;
  border-left: 0;
  border-right: 0;
  -webkit-app-region: drag;
}

.panel-topbar {
  margin-top: var(--section-gap);
  margin-bottom: var(--section-gap);
  border-bottom: 0;
}

#topbar-projects {
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
}

#topbar-projects #search {
  width: calc(100% - 300px);
  min-width: 0;
  margin-left: 300px;
  max-width: 100%;
  justify-self: stretch;
}

#topbar-installs {
  grid-template-columns: auto minmax(0, 1fr) auto auto;
}

#topbar-installs #search-installs {
  width: calc(100% - 300px);
  min-width: 0;
  margin-left: 300px;
  max-width: 100%;
  justify-self: stretch;
}

#topbar-settings {
  grid-template-columns: auto minmax(0, 1fr);
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

#search,
#search-installs,
.settings-panel input,
.theme-select {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  height: 38px;
  padding: 0 12px;
  font: inherit;
  -webkit-app-region: no-drag;
}

.projects-panel,
.settings-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0;
  overflow: auto;
  min-height: 0;
}

.view.active > .projects-panel,
.view.active > .settings-panel {
  border-top: 0;
  border-bottom: 0;
}

.settings-panel {
  padding: 16px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.settings-row {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.settings-panel .settings-row:not(.settings-header-row) {
  padding-left: 14px;
}

.settings-row.dependencies-row,
.settings-row.settings-section-row,
.settings-row.settings-header-row {
  align-items: start;
}

.settings-row > label {
  color: var(--muted);
  font-size: 12px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  margin: 0;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
}

.settings-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.dep-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.dep-ok {
  color: var(--status-success);
  font-weight: 600;
}

.dep-check {
  color: var(--status-success);
}

.dep-bad {
  color: var(--status-error);
  font-weight: 600;
}

.dep-cross {
  color: var(--status-error);
}

.settings-panel .settings-section-title,
.settings-panel .settings-header {
  width: 100%;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-weight: 700;
  text-align: left;
  justify-self: stretch;
  align-self: start;
}

.settings-panel .settings-section-title.first,
.settings-panel .settings-header.first {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.settings-row.settings-header-row {
  grid-template-columns: 1fr;
  margin-top: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 0;
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

td.actions-cell {
  position: relative;
  overflow: visible;
}

#projects-table th:last-child,
#projects-table td.actions-cell,
#installs-table th:last-child,
#installs-table td.actions-cell {
  width: 64px;
  min-width: 64px;
  max-width: 64px;
}

#projects-table th[data-sort="status"],
#projects-table td:nth-child(8) {
  width: 92px;
  min-width: 92px;
  max-width: 92px;
}

#projects-table th[data-sort="sizeBytes"],
#projects-table td:nth-child(7) {
  width: 96px;
  min-width: 96px;
  max-width: 96px;
}

#projects-table th:first-child,
#projects-table td:first-child,
#installs-table th:first-child,
#installs-table td:first-child {
  padding-left: 22px;
}

th {
  color: var(--muted);
  font-weight: 600;
  background: var(--header-bg);
  position: sticky;
  top: 0;
  z-index: 120;
}

thead {
  position: sticky;
  top: 0;
  z-index: 110;
}

tr.clickable {
  cursor: pointer;
}

tr.clickable:hover {
  background: var(--row-hover);
}

tr.row-busy {
  opacity: 0.56;
  pointer-events: none;
}

tr.menu-open {
  position: relative;
  z-index: 2200;
}

tr.cloud-row {
  opacity: 0.68;
}

tr.cloud-row:hover {
  opacity: 0.88;
}

tr.selected {
  background: var(--sidebar-active);
}

.cell-with-icon {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 100%;
  max-width: 100%;
}

.cell-with-icon .cell-text {
  display: block;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: inherit;
}

.vcs-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.vcs-busy {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.vcs-busy-icon {
  width: 14px;
  height: 14px;
  display: inline-flex;
  animation: vcs-spin 0.9s linear infinite;
}

.vcs-busy-icon svg {
  width: 14px;
  height: 14px;
  display: block;
}

@keyframes vcs-spin {
  to { transform: rotate(360deg); }
}

.vcs-kind {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 18px;
  padding: 0 5px;
  border-radius: 5px;
  background: var(--btn-hover);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.vcs-branch {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.vcs-metric {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.vcs-metric.active {
  color: #d3a327;
  font-weight: 600;
}

.vcs-metric-icon {
  width: 12px;
  height: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.vcs-metric-icon svg {
  width: 12px;
  height: 12px;
  display: block;
}

.vcs-warn {
  color: var(--warning-text);
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.vcs-warn svg {
  width: 14px;
  height: 14px;
  display: block;
}

.editor-missing-warn {
  color: var(--warning-text);
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  flex: 0 0 auto;
}

.editor-missing-warn svg {
  width: 14px;
  height: 14px;
  display: block;
}

.project-icon {
  width: 16px;
  height: 16px;
  display: block;
  object-fit: cover;
  border-radius: 3px;
  flex: 0 0 auto;
}

.footer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  border-top: 1px solid var(--line);
  border-left: 0;
  border-right: 0;
  border-bottom: 1px solid var(--line);
  min-height: 34px;
}

#status,
#settings-status {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  max-width: min(72%, 900px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  min-width: 0;
}

#status.status-success,
#settings-status.status-success {
  color: var(--status-success);
}

#status.status-warning,
#settings-status.status-warning {
  color: #d3a327;
}

#status.status-error,
#settings-status.status-error {
  color: var(--warning-text);
}

#status.status-info,
#settings-status.status-info {
  color: var(--muted);
}

#status.status-loading::before,
#settings-status.status-loading::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 999px;
  vertical-align: -1px;
  animation: status-spin 0.8s linear infinite;
}

.inline-spinner {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 2px solid color-mix(in srgb, var(--muted) 60%, transparent);
  border-top-color: var(--text);
  display: inline-block;
  animation: status-spin 0.8s linear infinite;
}

@keyframes status-spin {
  to { transform: rotate(360deg); }
}

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

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  -webkit-app-region: no-drag;
}

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

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.accent {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn.accent:hover {
  background: var(--accent-strong);
}

.btn.danger {
  border-color: var(--danger-border);
  color: var(--danger-text);
}

.add-wrap { position: relative; }
.row-actions { position: relative; display: flex; justify-content: flex-end; z-index: 1; }
.row-actions:has(.row-menu:not(.hidden)) { z-index: 2000; }

.icon-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  height: 38px;
  min-width: 44px;
  padding: 0 12px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  line-height: 1;
  font-size: 20px;
  font-weight: 700;
  -webkit-app-region: no-drag;
}

.icon-btn:hover {
  background: var(--btn-hover);
}

.row-action-btn {
  height: 38px;
  min-width: 38px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  border-radius: 6px;
}

.row-action-btn:hover,
.row-action-btn:focus-visible {
  filter: brightness(2);
}

.topbar-refresh-btn {
  height: 38px;
  min-width: 38px;
  padding: 0;
  border-radius: 8px;
  font-size: 18px;
}

.row-menu {
  top: 34px;
  right: 0;
}

.menu {
  position: absolute;
  top: 40px;
  right: 0;
  min-width: 170px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--menu-shadow);
  padding: 6px;
  z-index: 2100;
  -webkit-app-region: no-drag;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 9px 10px;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}

.menu-item-icon {
  width: 24px;
  text-align: center;
  flex: 0 0 24px;
  color: currentColor;
  opacity: 1;
  font-size: 1.5em;
  line-height: 1;
  font-variant-emoji: text;
}

.menu-item:hover {
  background: var(--row-hover);
}

.menu-item.danger-item {
  color: var(--danger-text);
}

.hidden { display: none; }

.warning-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--warning-border);
  background: var(--warning-bg);
  color: var(--warning-text);
  font-size: 11px;
  font-weight: 600;
}

.open-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--status-success) 45%, var(--line));
  background: color-mix(in srgb, var(--status-success) 18%, transparent);
  color: var(--status-success);
  font-size: 11px;
  font-weight: 600;
}

.cloud-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--line) 78%, #fff);
  background: color-mix(in srgb, var(--panel-alt) 74%, transparent);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.modal {
  border: 1px solid var(--line);
  border-radius: 10px;
  width: min(560px, 92vw);
  padding: 0;
  background: var(--panel);
  color: var(--text);
  -webkit-app-region: no-drag;
}

.modal::backdrop {
  background: var(--backdrop);
}

.modal-form {
  padding: 16px;
  display: grid;
  gap: 10px;
}

.modal-form h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.modal-form label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.modal-form input {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 10px;
  font: inherit;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.input-row.path-picker {
  gap: 0;
}

.input-row.path-picker input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.input-row.path-picker .browse-btn {
  min-width: 40px;
  width: 40px;
  padding: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  color: var(--text);
  font-variant-emoji: text;
  font-size: 1.05rem;
  line-height: 1;
}

menu {
  margin: 2px 0 0;
  padding: 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 980px) {
  .toolbar { grid-template-columns: 1fr; }

  #topbar-projects #search,
  #topbar-installs #search-installs {
    margin-left: 0;
  }

  .settings-row {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .footer-actions { flex-wrap: nowrap; }

  #status,
  #settings-status {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
