/* ============================================================
   ply 服务器面板 —— 管理后台样式
   ============================================================ */

/* ---------- 设计变量 ---------- */
:root {
    /* 尺寸 */
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --radius: 12px;
    --radius-sm: 8px;

    /* 字体 */
    --font-size: 16px;
    /* 基准字号 */
    --line-height: 1.6;

    /* 主色 */
    --primary: #2060df;
    --primary-hover: #1b53c4;
    --primary-soft: rgba(32, 96, 223, 0.08);

    /* 背景 & 表面 */
    --bg: #f4f6fb;
    --surface: #ffffff;

    /* 文字 */
    --text: #373c44;
    --text-muted: #646b79;

    /* 边框 */
    --border: #e7eaef;

    /* 侧边栏 */
    --sidebar-bg: #1c2536;
    --sidebar-text: #aab3c8;
    --sidebar-muted: #69738c;
    --sidebar-hover: #2a3650;

    /* 阴影 */
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

/* ---------- 基础样式 ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: var(--font-size);
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    line-height: var(--line-height);
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    margin: 0 0 0.5em;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text);
}

h1 {
    font-size: 1.5rem;
}

h2 {
    font-size: 1.25rem;
}

h3 {
    font-size: 1.06rem;
}

h4 {
    font-size: 1rem;
}

p {
    margin: 0 0 1em;
}

a {
    color: var(--primary);
}

a:hover {
    color: var(--primary-hover);
}

img {
    max-width: 100%;
}

ul,
ol {
    margin: 0 0 1em;
    padding-left: 1.25em;
}

/* ---------- 页面布局 ---------- */
.layout {
    display: flex;
    min-height: 100vh;
}

/* ---------- 侧边栏 ---------- */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    overflow-y: auto;
    transition: transform 0.25s ease;
    z-index: 30;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 3px;
}

/* 品牌区 */
.sidebar-brand {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: #fff;
}

.brand-logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
    flex-shrink: 0;
}

.brand-name {
    font-weight: 600;
    font-size: 1.05rem;
    white-space: nowrap;
    flex-shrink: 0;
}

/* 导航 */
.sidebar-nav {
    flex: 1;
    padding: 16px 14px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.92rem;
    margin-bottom: 2px;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.nav-link.active {
    background: var(--primary);
    color: #fff;
}

.nav-ico {
    width: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ---------- 顶栏 ---------- */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    overflow: hidden;
}

.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0;
    flex: 1;
}

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

.user-badge {
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
}

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.menu-toggle:hover {
    background: var(--primary-soft);
}

/* ---------- 顶部子导航栏 ---------- */
.subnav {
    display: flex;
    gap: 8px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.subnav-item {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    line-height: 1.2;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}

.subnav-item:hover {
    background: var(--primary-soft);
    color: var(--primary);
}

.subnav-item.active {
    background: var(--primary);
    color: #fff;
}

/* ---------- 内容区 & 页脚 ---------- */
.main {
    flex: 1;
    min-height: 0;
    padding: 24px;
    overflow-y: auto;
}

.footer {
    position: sticky;
    bottom: 0;
    z-index: 10;
    padding: 16px 24px;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.footer p {
    margin: 0;
}

/* ---------- 组件 ---------- */
/* 卡片 */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

/* 面板 */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: visible;
    margin-bottom: 8px;
}

.panel-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    border-radius: var(--radius) var(--radius) 0 0;
}

.panel-body {
    padding: 24px;
}

/* 版本对比 */
.version-compare {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.version-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border);
}

.version-label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.version-value {
    font-weight: 600;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.version-status {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

.version-status-latest {
    background: rgba(34, 160, 88, 0.1);
    color: #1f7a45;
}

.version-status-outdated {
    background: rgba(230, 140, 20, 0.12);
    color: #a05a00;
}

.version-status-ahead {
    background: rgba(32, 96, 223, 0.08);
    color: var(--primary);
}

.version-status-unknown {
    background: var(--primary-soft);
    color: var(--text-muted);
}

.version-hint {
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.version-hint code {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border);
}

/* 数据统计 */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
}

.stat {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.stat-value {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text);
}

.stat-bar {
    display: block;
    width: 100%;
    height: 6px;
    margin-top: 4px;
    border: none;
    border-radius: 999px;
    background: var(--border);
    overflow: hidden;
    appearance: none;
    -webkit-appearance: none;
}

/* WebKit / Chromium */
.stat-bar::-webkit-progress-bar {
    background: var(--border);
    border-radius: 999px;
}

.stat-bar::-webkit-progress-value {
    background: var(--primary);
    border-radius: 999px;
    transition: width 0.3s ease;
}

/* Firefox */
.stat-bar::-moz-progress-bar {
    background: var(--primary);
    border-radius: 999px;
}

/* 内存 / 磁盘 / CPU 统计悬浮详请 */
.stat--mem,
.stat--disk,
.stat--cpu {
    position: relative;
    cursor: help;
}

.stat-tip {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    min-width: 190px;
    max-width: 320px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 10px 12px;
    background: var(--sidebar-bg);
    color: #fff;
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.22);
    font-size: 0.8rem;
    line-height: 1.5;
    opacity: 0;
    visibility: hidden;
    pointer-events: auto;
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
    z-index: 40;
}

.stat--mem:hover .stat-tip,
.stat--mem:focus-visible .stat-tip,
.stat--disk:hover .stat-tip,
.stat--disk:focus-visible .stat-tip,
.stat--cpu:hover .stat-tip,
.stat--cpu:focus-visible .stat-tip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* 指向卡片的箭头 */
.stat-tip::before {
    content: "";
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 7px solid transparent;
    border-bottom-color: var(--sidebar-bg);
}

.stat-tip-title {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
}

.stat-tip-row {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin: 3px 0;
    color: var(--sidebar-muted);
}

.stat-tip-row b {
    color: #fff;
    font-weight: 500;
}

.stat-tip-name {
    flex: 1 1 auto;
    min-width: 0;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-tip-sub {
    color: var(--sidebar-muted);
    font-size: 0.75rem;
    margin: -1px 0 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-tip-sub:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

/* 页面标题 */
.page-title {
    margin: 0 0 4px;
    font-size: 1.35rem;
}

.page-subtitle {
    margin: 0 0 20px;
    color: var(--text-muted);
}

/* 错误页 */
.error-page {
    padding: 80px 24px;
    text-align: center;
}

.error-code {
    margin: 0 0 12px;
    font-size: 4.5rem;
    font-weight: 700;
    line-height: 1;
    color: var(--primary);
}

.error-message {
    margin: 0 0 24px;
    color: var(--text-muted);
}

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

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

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

/* 禁用态按钮 */
.btn:disabled,
.btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary:disabled,
.btn-primary[disabled] {
    background: var(--border);
    border-color: var(--border);
    color: var(--text-muted);
}

.btn-danger {
    background: #dc2626;
    border-color: #dc2626;
    color: #fff;
}

.btn-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fff;
}

/* 仅图标按钮 */
.btn-icon {
    padding: 0.5rem;
    line-height: 1;
}

/* 表单 */
label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.35rem;
    color: var(--text);
}

input,
select,
textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    font: inherit;
    font-size: 0.9rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

/* JSON 配置编辑框 */
.code-editor {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    white-space: pre;
    tab-size: 2;
    resize: vertical;
}

.form-actions {
    margin-top: 16px;
    display: flex;
    gap: 12px;
}

/* 表格 */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th,
.table td {
    padding: 0.65rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* 行内小表单（如每行的删除按钮） */
.inline-form {
    display: inline;
}

/* 行内代码（如镜像名 / ID） */
code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85rem;
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border);
}

/* ---------- 服务卡片 ---------- */
.svc-project {
    margin-bottom: 20px;
}

.svc-project-header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding-bottom: 10px;
    margin-bottom: 12px;
    border-bottom: 1px dashed var(--border);
}

.svc-project-name {
    font-weight: 600;
    font-size: 1rem;
}

.svc-project-dir {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.svc-project-count {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.svc-project-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.svc-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.svc-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.svc-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.svc-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.svc-status {
    font-size: 0.8rem;
    white-space: nowrap;
}

.status-up {
    color: #1f7a45;
}

.status-down {
    color: var(--text-muted);
}

.svc-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.svc-ports {
    font-size: 0.8rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: var(--text-muted);
    white-space: pre-wrap;
    word-break: break-all;
}

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

/* ---------- 终端 ---------- */
/* JetBrainsMonoNerdFont 字体：缺失字符自动回退到系统字体 */
@font-face {
    font-family: "JetBrainsMonoNF";
    src: url("../fonts/JetBrainsMonoNerdFont-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

.terminal-page {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    gap: 12px;
}

/* 工具栏 */
.terminal-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-icon {
    min-width: 34px;
    padding: 0.4rem 0.55rem;
    font-weight: 600;
}

.font-size-label {
    min-width: 44px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

/* 黑色终端框 */
.terminal-shell {
    position: relative;
    flex: 1 1 auto;
    min-height: 320px;
    border-radius: var(--radius-sm);
    background: #0b0e14;
    overflow: hidden;
    border: 1px solid var(--border);
}

.terminal-box {
    width: 100%;
    height: 100%;
}

.terminal-box .xterm {
    height: 100%;
    padding: 8px 10px;
}

/* ---------- 响应式 ---------- */
.sidebar-mask {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 25;
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        height: 100vh;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-mask.show {
        display: block;
    }

    .menu-toggle {
        display: flex;
    }

    .main {
        padding: 16px;
    }

    .topbar {
        padding: 0 16px;
    }

    .terminal-toolbar {
        flex-wrap: wrap;
    }
}

/* ---------- 认证（登录 / 注册）---------- */
.auth-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: radial-gradient(1200px 600px at 50% -10%,
            var(--primary-soft),
            transparent 60%),
        var(--bg);
}

.auth-wrap {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.auth-card {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
}

.auth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 6px;
}

.auth-brand .brand-mark {
    width: 40px;
    height: 40px;
    font-size: 1rem;
    border-radius: 10px;
}

.auth-brand .brand-logo {
    width: 40px;
    height: 40px;
}

.auth-brand .brand-name {
    font-size: 1.2rem;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-muted);
    margin: 0 0 24px;
    font-size: 0.95rem;
}

.form-group {
    margin-bottom: 16px;
}

/* 字段级提示（边输入边校验） */
.field-hint {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 4px;
    min-height: 1em;
}

.field-hint.is-error {
    color: #b91c1c;
}

.input-invalid {
    border-color: #b91c1c !important;
}

.input-invalid:focus {
    border-color: #b91c1c !important;
    box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.12) !important;
}

.auth-submit {
    width: 100%;
    padding: 0.65rem 1rem;
    font-size: 0.95rem;
    letter-spacing: 0.2em;
}

.auth-footer {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin: 0;
}

/* ---------- 提示消息 ---------- */
.alert {
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-error {
    color: #b91c1c;
    background: #fef2f2;
    border-color: #fecaca;
}

.alert-success {
    color: #166534;
    background: #f0fdf4;
    border-color: #bbf7d0;
}