:root {
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-text: #222428;
  --color-text-muted: #6b7075;
  --color-border: #e2e4e8;
  --color-accent: #0082c9;
  --color-accent-hover: #006aa3;
  --color-success: #2ea44f;
  --color-danger: #d93636;
  --color-disabled-bg: #eceef1;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-card-hover: 0 4px 14px rgba(0, 0, 0, 0.12);
  --radius: 14px;
  --topbar-height: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #14161a;
    --color-surface: #1e2126;
    --color-text: #e8e9eb;
    --color-text-muted: #9a9ea3;
    --color-border: #2c2f35;
    --color-accent: #4db8ff;
    --color-accent-hover: #7cc9ff;
    --color-disabled-bg: #24272c;
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-card-hover: 0 4px 14px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.topbar-inner {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
}

.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}
.menu-toggle span {
  display: block;
  height: 2px;
  background: var(--color-text);
  border-radius: 1px;
}
.menu-toggle:hover { background: var(--color-disabled-bg); }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
}
.brand-icon { font-size: 1.3rem; }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-input {
  padding: 8px 12px;
  border-radius: 20px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 0.9rem;
  min-width: 160px;
}
.search-input:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

.btn-customize {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
}
.btn-customize:hover { background: var(--color-disabled-bg); }
.btn-customize.active {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

/* Layout */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
}

.content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: start;
  gap: 24px;
  min-width: 0;
}

/* Category sections */
.category-section h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  margin: 0 0 14px;
}

.group-block { margin-bottom: 18px; }
.group-block h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.card-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.project-card {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  text-decoration: none;
  color: var(--color-text);
  cursor: pointer;
  min-height: 56px;
  width: 100%;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
  text-align: left;
}
.project-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-card-hover);
}
.project-card:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
.project-card .icon { font-size: 1.5rem; flex-shrink: 0; }
.project-card .text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.project-card .title {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-card .description {
  font-size: 0.76rem;
  color: var(--color-text-muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-card .card-status-msg {
  display: none;
  font-size: 0.76rem;
  color: var(--color-text-muted);
  line-height: 1.3;
}

.project-card.disabled {
  cursor: default;
  background: var(--color-disabled-bg);
  color: var(--color-text-muted);
  box-shadow: none;
}
.project-card.disabled:hover { transform: none; box-shadow: none; }

.project-card.starting { cursor: wait; opacity: 0.85; }
.project-card.starting .description { display: none; }
.project-card.starting .card-status-msg { display: block; }
.project-card.has-msg .description { display: none; }
.project-card.has-msg .card-status-msg { display: block; }

.status-dot {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-text-muted);
  flex-shrink: 0;
}
.status-dot.online { background: var(--color-success); }
.status-dot.offline { background: var(--color-danger); }
.status-dot.starting {
  background: #e8a33d;
  animation: status-pulse 1s ease-in-out infinite;
}

@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.empty-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 90px;
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text-muted);
  font-size: 0.85rem;
  padding: 12px;
  text-align: center;
}

/* Sidebar / widgets */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sidebar-header h2 {
  font-size: 1rem;
  margin: 0 0 4px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.widget-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.widget-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 16px;
}
.widget-card h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Clock widget */
.widget-clock .time { font-size: 1.9rem; font-weight: 700; letter-spacing: 0.02em; }
.widget-clock .date { color: var(--color-text-muted); font-size: 0.85rem; margin-top: 2px; }

/* Status widget */
.status-list { display: flex; flex-direction: column; gap: 8px; font-size: 0.85rem; }
.status-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.status-row .label { display: flex; align-items: center; gap: 8px; }
.status-badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--color-disabled-bg);
  color: var(--color-text-muted);
}
.status-badge.online { background: rgba(46, 164, 79, 0.15); color: var(--color-success); }
.status-badge.offline { background: rgba(217, 54, 54, 0.15); color: var(--color-danger); }
.status-badge.starting { background: rgba(232, 163, 61, 0.18); color: #b9781e; }
.status-empty { color: var(--color-text-muted); font-size: 0.85rem; }

/* Notes widget */
.widget-notes textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 10px;
  font-family: inherit;
  font-size: 0.87rem;
  background: var(--color-bg);
  color: var(--color-text);
}
.widget-notes .hint {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  margin-top: 6px;
}

/* Customize panel */
.customize-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 16px;
}
.customize-panel.hidden { display: none; }
.customize-panel h3 { margin: 0 0 10px; font-size: 0.9rem; }
.customize-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 0.88rem;
}

.footer {
  text-align: center;
  padding: 18px;
  color: var(--color-text-muted);
  font-size: 0.78rem;
}

.sidebar-overlay {
  display: none;
}

/* Mobile */
@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 16px 12px;
  }
  .content {
    grid-template-columns: 1fr;
  }
  .menu-toggle { display: flex; }
  .search-input { min-width: 0; width: 120px; }

  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: min(320px, 85vw);
    background: var(--color-bg);
    padding: 20px 16px;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    z-index: 40;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 30;
  }
  .sidebar-overlay.visible { display: block; }
}

@media (max-width: 480px) {
  .brand span#dashboardTitle { display: none; }
  .search-input { width: 90px; }
}
