:root {
    --bg: #111213;
    --surface: #1a1b1c;
    --surface-hover: #212223;
    --border: #2b2c2d;
    --text-primary: #e8e8e6;
    --text-secondary: #9a9a97;
    --text-muted: #6f6f6c;
    --accent: #e8e8e6;
    --danger: #e5484d;
    --danger-hover: #ff5b60;
  }

  * { box-sizing: border-box; }

  html, body {
    height: 100%;
  }

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

  .layout {
    display: flex;
    width: 100%;
    min-height: 100vh;
  }

  nav.sidebar {
    width: 260px;
    flex-shrink: 0;
    padding: 2rem 1rem;
    border-right: 1px solid var(--border);
  }

  .profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.5rem 0.5rem 1rem;
  }

  .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--border);
    flex-shrink: 0;
  }

  .profile .name {
    font-size: 14px;
    font-weight: 600;
  }

  .profile .name span {
    color: var(--text-secondary);
    font-weight: 400;
  }

  .profile .sub {
    font-size: 12px;
    color: var(--text-secondary);
  }

  .section-label {
    font-size: 12px;
    color: var(--text-muted);
    padding: 0.9rem 10px 0.35rem;
    text-transform: none;
  }

  ul.nav-group {
    list-style: none;
    margin: 0;
    padding: 0 0 0.5rem;
    border-bottom: 1px solid var(--border);
  }

  ul.nav-group:last-child {
    border-bottom: none;
  }

  .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 14px;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    border-left: 2px solid transparent;
  }

  .nav-item:hover {
    background: var(--surface-hover);
  }

  .nav-item.active {
    background: var(--surface);
    font-weight: 600;
  }

  .nav-item .icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .nav-item .icon svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
  }

  .nav-item .icon i {
    font-size: 15px;
    color: currentColor;
  }

  .nav-item.has-children {
    justify-content: space-between;
  }
  .nav-item.has-children .label-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .chevron {
    width: 14px;
    height: 14px;
    transition: transform 0.15s ease;
    stroke: var(--text-secondary);
    font-size: 11px;
    color: var(--text-secondary);
  }
  .nav-item.expanded .chevron {
    transform: rotate(180deg);
  }
  .subnav {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.15s ease;
  }
  .subnav.open {
    max-height: 300px;
  }
  .subnav .nav-item {
    padding-left: 34px;
    font-size: 13px;
  }

  main {
    flex: 1;
    min-width: 0;
    padding: 2rem 3rem;
  }

  .main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
  }

  .main-header h1 {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
  }

  button.primary {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
  }

  button.primary:hover {
    background: var(--surface-hover);
  }

  button.ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 7px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
  }

  button.ghost:hover {
    background: var(--surface-hover);
  }

  button.danger {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 7px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
  }

  button.danger:hover {
    background: var(--danger);
    border-color: var(--danger-hover);
    color: #fff;
  }

  .empty-state {
    color: var(--text-secondary);
    text-align: center;
    padding: 3rem 0;
    font-size: 14px;
  }

  .panel {
    margin-top: 0;
    max-width: 620px;
  }

  .panel h2 {
    font-size: 16px;
    margin: 0 0 0.9rem;
  }

  .panel h2.section-heading {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
  }

  .panel p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
    max-width: 620px;
    margin: 0 0 1rem;
  }

  .field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 1rem;
    font-size: 13px;
    color: var(--text-secondary);
  }

  .field input,
  .field select,
  .field textarea {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 9px 10px;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
  }

  .field input:focus,
  .field select:focus,
  .field textarea:focus {
    border-color: var(--text-secondary);
  }

  .field textarea {
    resize: vertical;
  }

  .inline-form {
    display: flex;
    gap: 8px;
  }

  .inline-form input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 9px 10px;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
  }

  .toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    padding: 8px 0;
    cursor: pointer;
  }

  .toggle-row input {
    accent-color: var(--text-primary);
    width: 15px;
    height: 15px;
  }

  .list {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
  }

  .list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
  }

  .list-row:last-child {
    border-bottom: none;
  }

  .list-title {
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .list-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
  }

  .badge {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--surface-hover);
    border: 1px solid var(--border);
    padding: 2px 7px;
    border-radius: 100px;
  }

  .danger-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
  }

  .danger-title {
    font-size: 14px;
    font-weight: 500;
  }

  .danger-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
  }

  .auth-wrap {
    min-height: 100vh;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
  }

  .auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2rem;
  }

  .auth-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 1.25rem;
  }

  .auth-subtext {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0 0 1rem;
  }

  .auth-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 1rem;
    font-size: 13px;
  }

  .auth-links a {
    color: var(--text-secondary);
    text-decoration: none;
  }

  .auth-links a:hover {
    color: var(--text-primary);
    text-decoration: underline;
  }

  .alert-error {
    background: rgba(229, 72, 77, 0.1);
    border: 1px solid var(--danger);
    color: #ff9b9e;
    font-size: 13px;
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 1rem;
  }

  .alert-success {
    background: rgba(70, 167, 88, 0.1);
    border: 1px solid #46a758;
    color: #7ee08a;
    font-size: 13px;
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 1rem;
  }

  .secret-box {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 15px;
    letter-spacing: 1px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 0.75rem;
    text-align: center;
    word-break: break-all;
  }

  .device-icon {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 8px;
    background: var(--surface-hover);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .device-icon svg {
    width: 18px;
    height: 18px;
    stroke: var(--text-secondary);
    fill: none;
    stroke-width: 1.8;
  }

  .device-icon i {
    font-size: 16px;
    color: var(--text-secondary);
  }

  .sensitive {
    filter: blur(5px);
    transition: filter 0.15s ease;
    cursor: pointer;
    user-select: none;
  }

  .sensitive:hover,
  .sensitive:focus,
  .sensitive.revealed {
    filter: blur(0);
    user-select: text;
  }

  .plan-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
  }

  .page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
  }

  body {
    display: block;
  }

  .layout {
    flex: 1;
    min-height: 0;
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 60px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: relative;
    z-index: 20;
  }

  .topbar-logo {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .topbar-logo img {
    height: 26px;
    display: block;
  }

  .topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .icon-btn:hover,
  .icon-btn.open {
    background: var(--surface-hover);
    border-color: var(--border);
    color: var(--text-primary);
  }

  .icon-btn svg {
    width: 19px;
    height: 19px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
  }

  .icon-btn i {
    font-size: 17px;
  }

  .icon-btn img.avatar-sm {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
  }

  .dropdown-wrap {
    position: relative;
  }

  .dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px;
    display: none;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  }

  .dropdown-menu.open {
    display: block;
  }

  .dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 6px;
    font-size: 14px;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
  }

  .dropdown-item:hover {
    background: var(--surface-hover);
  }

  .dropdown-item.active {
    font-weight: 600;
  }

  .dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 6px 4px;
  }

  [data-theme="light"] {
    --bg: #f5f5f4;
    --surface: #ffffff;
    --surface-hover: #ececea;
    --border: #dcdcda;
    --text-primary: #1a1a19;
    --text-secondary: #55554f;
    --text-muted: #85857e;
    --accent: #1a1a19;
  }

  @media (prefers-color-scheme: light) {
    html:not([data-theme]) {
      --bg: #f5f5f4;
      --surface: #ffffff;
      --surface-hover: #ececea;
      --border: #dcdcda;
      --text-primary: #1a1a19;
      --text-secondary: #55554f;
      --text-muted: #85857e;
      --accent: #1a1a19;
    }
  }

  nav.sidebar.compact {
    width: 76px;
    padding: 2rem 0.5rem;
  }

  nav.sidebar.compact .profile .sub,
  nav.sidebar.compact .profile > div .name,
  nav.sidebar.compact .section-label,
  nav.sidebar.compact .chevron,
  nav.sidebar.compact .label-wrap span:last-child {
    display: none;
  }

  nav.sidebar.compact .nav-item {
    justify-content: center;
    font-size: 0;
  }

  nav.sidebar.compact .nav-item .icon {
    font-size: initial;
  }

  nav.sidebar.compact .profile {
    justify-content: center;
  }

  [data-reduce-motion="true"] * {
    transition: none !important;
    animation: none !important;
  }

  .console-layout {
    display: flex;
    flex: 1;
    min-height: 0;
  }

  .console-rail {
    width: 260px;
    flex-shrink: 0;
    padding: 1.5rem 1rem;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .console-rail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.5rem 1rem;
  }

  .console-rail-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
  }

  .console-rail-add {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 13px;
  }

  .console-rail-add:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
  }

  .server-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    color: var(--text-primary);
  }

  .server-row:hover {
    background: var(--surface-hover);
  }

  .server-row.active {
    background: var(--surface);
    border: 1px solid var(--border);
  }

  .server-row-info {
    min-width: 0;
    flex: 1;
  }

  .server-row-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .server-row-meta {
    font-size: 11px;
    color: var(--text-muted);
  }

  .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  .status-dot.running { background: #46a758; box-shadow: 0 0 0 3px rgba(70,167,88,0.15); }
  .status-dot.stopped { background: #6f6f6c; }
  .status-dot.starting { background: #e5a23d; box-shadow: 0 0 0 3px rgba(229,162,61,0.15); }
  .status-dot.error { background: var(--danger); box-shadow: 0 0 0 3px rgba(229,72,77,0.15); }

  .console-main {
    flex: 1;
    min-width: 0;
    padding: 2rem 2.5rem;
    overflow-y: auto;
  }

  .console-empty {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 2rem;
  }

  .console-empty-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: var(--text-secondary);
    margin-bottom: 1.25rem;
  }

  .console-empty h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 6px;
  }

  .console-empty p {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 340px;
    margin: 0 0 1.5rem;
    line-height: 1.6;
  }

  .server-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    flex-wrap: wrap;
    gap: 12px;
  }

  .server-detail-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 600;
  }

  .server-detail-sub {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    padding: 3px 9px;
    border-radius: 100px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
  }

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

  .server-action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
  }

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

  .server-action-btn.danger {
    color: #ff9b9e;
    border-color: rgba(229,72,77,0.4);
  }

  .server-action-btn.danger:hover {
    background: rgba(229,72,77,0.1);
  }

  .resource-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 1.75rem;
  }

  .resource-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
  }

  .resource-card-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
  }

  .resource-bar-track {
    height: 6px;
    background: var(--border);
    border-radius: 100px;
    overflow: hidden;
    margin-bottom: 8px;
  }

  .resource-bar-fill {
    height: 100%;
    background: var(--text-primary);
    border-radius: 100px;
  }

  .resource-card-detail {
    font-size: 11px;
    color: var(--text-muted);
  }

  .console-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
    overflow-x: auto;
  }

  .console-tab {
    padding: 9px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
  }

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

  .console-tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--text-primary);
    font-weight: 500;
  }

  .terminal-box {
    background: #0a0a0b;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 13px;
    line-height: 1.7;
    color: #8fdb8f;
    min-height: 160px;
  }

  .terminal-box .dim { color: #55554f; }
  .terminal-box .cursor {
    display: inline-block;
    width: 7px;
    height: 14px;
    background: #8fdb8f;
    vertical-align: middle;
    animation: blink 1s step-start infinite;
  }

  @keyframes blink { 50% { opacity: 0; } }

  .server-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
  }

  .server-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    cursor: pointer;
  }

  .server-card:hover {
    border-color: var(--text-muted);
  }

  .server-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
  }

  .server-card-name {
    font-size: 14px;
    font-weight: 600;
  }

  .server-card-resources {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .server-card-resource-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-muted);
  }

  .server-card-resource-row .resource-bar-track {
    flex: 1;
    margin-bottom: 0;
  }
