/* ============================================
   BoxServer - 管理后台样式
   ============================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --border: #d9d9d9;
    --text: #333333;
    --text-muted: #888888;
    --primary: #1677ff;
    --primary-hover: #4096ff;
    --success: #52c41a;
    --danger: #ff4d4f;
    --warning: #faad14;
    --online: #52c41a;
    --offline: #d9d9d9;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

/* ---- Login Page ---- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-container {
    background: var(--surface);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.1);
    width: 380px;
    max-width: 95vw;
}

.login-container h1 {
    text-align: center;
    margin-bottom: 32px;
    color: var(--primary);
    font-size: 24px;
}

/* ---- App Layout ---- */
.app { max-width: 1400px; margin: 0 auto; padding: 0 20px 40px; }

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 24px;
}

.header h1 { font-size: 22px; color: var(--primary); }
.header-right { display: flex; align-items: center; gap: 16px; }

/* ---- Sections ---- */
.config-section, .clients-section {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 24px;
    margin-bottom: 20px;
}

.config-section h2, .clients-section h2 {
    font-size: 16px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.refresh-info { font-size: 12px; color: var(--text-muted); font-weight: normal; }
.config-grid { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.config-item { display: flex; flex-direction: column; gap: 4px; }
.config-item label { font-size: 13px; color: var(--text-muted); }
.config-msg { font-size: 13px; margin-left: 8px; }
.config-msg.success { color: var(--success); }
.config-msg.error { color: var(--danger); }

/* ---- Forms ---- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
input[type="text"],
input[type="password"],
input[type="number"],
textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(22,119,255,0.15);
}

textarea {
    resize: vertical;
    font-family: "SF Mono", "Cascadia Code", "Consolas", monospace;
    font-size: 12px;
    line-height: 1.5;
}

/* ---- Buttons ---- */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    white-space: nowrap;
}

.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #ff7875; color: #fff; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #73d13d; color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 8px; font-size: 11px; }
.btn-block { display: block; width: 100%; }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #fafafa; font-weight: 600; font-size: 12px; }
tr:hover td { background: #fafafa; }
.text-center { text-align: center; color: var(--text-muted); }

/* ---- Status Badge ---- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.badge-online { background: #f6ffed; color: var(--online); }
.badge-offline { background: #f5f5f5; color: var(--text-muted); }
.badge-frp-on { background: #e6f7ff; color: var(--primary); }
.badge-frp-off { background: #f5f5f5; color: var(--text-muted); }
.badge-na { color: var(--text-muted); }

/* ---- Alert ---- */
.alert { padding: 10px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }
.alert-error { background: #fff2f0; color: var(--danger); border: 1px solid #ffccc7; }

/* ---- Modal ---- */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active { display: flex; }

.modal-content {
    background: var(--surface);
    border-radius: 12px;
    padding: 24px;
    width: 440px;
    max-width: 95vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 8px 40px rgba(0,0,0,0.2);
    position: relative;
}

.modal-large { width: 90vw; max-width: 1200px; }

.modal-content h3 { margin-bottom: 20px; font-size: 18px; padding-right: 30px; }

.modal-close {
    position: absolute;
    top: 18px;
    right: 18px;
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    font-size: 20px;
    color: #999;
    cursor: pointer;
    border-radius: 4px;
    line-height: 28px;
    text-align: center;
    transition: all 0.15s;
}

.modal-close:hover {
    color: #333;
    background: #f0f0f0;
}

/* 抖动动画 */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    50% { transform: translateX(6px); }
    75% { transform: translateX(-4px); }
}

.modal.shake .modal-content {
    animation: shake 0.4s ease;
}

.modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
}

/* ---- Loading Overlay ---- */
#loading-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.6);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    pointer-events: all;
    cursor: wait;
}

#loading-overlay.active { display: flex; }

#loading-overlay .spinner {
    width: 42px; height: 42px;
    border: 3px solid #e8e8e8;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

#loading-overlay .loading-text {
    font-size: 14px;
    color: var(--text-muted);
}

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

/* ---- Dropdown Menu ---- */
.action-cell {
    position: relative;
}

.btn-menu {
    padding: 4px 10px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-weight: bold;
    letter-spacing: 1px;
    transition: all 0.2s;
}

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

.dropdown-menu {
    display: none;
    position: fixed;       /* JS 会动态设置 top/left，避免被表格 overflow 裁剪 */
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.18);
    z-index: 500;
    min-width: 170px;
    overflow-y: auto;
    max-height: 80vh;
    border: 1px solid #e8e8e8;
}

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

.dropdown-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    background: none;
    color: var(--text);
    font-family: inherit;
    transition: background 0.15s;
    text-decoration: none;
}

.dropdown-item:hover { background: #f0f5ff; color: var(--primary); }

.dropdown-item.disabled {
    color: #c0c0c0;
    cursor: not-allowed;
    pointer-events: none;
}

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

.dropdown-item.danger:hover {
    background: #fff2f0;
    color: var(--danger);
}

.dropdown-divider {
    height: 1px;
    background: #f0f0f0;
    margin: 4px 0;
}

/* ---- Detail Modal Grid ---- */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 24px;
}

.detail-grid .detail-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.detail-grid .detail-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.detail-grid .detail-value {
    font-size: 14px;
    word-break: break-all;
}

.detail-grid .detail-full {
    grid-column: 1 / -1;
}

/* ---- Disk Table in Modal ---- */
.disk-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 12px;
}

.disk-table th, .disk-table td {
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.disk-table th {
    background: #fafafa;
    font-weight: 600;
}

.disk-usage-bar {
    display: inline-block;
    height: 6px;
    border-radius: 3px;
    background: #e8e8e8;
    width: 80px;
    vertical-align: middle;
    margin-right: 6px;
    position: relative;
    overflow: hidden;
}

.disk-usage-bar-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    border-radius: 3px;
    background: var(--primary);
}

/* ---- Metric Mini Badge ---- */
.metric-badge {
    font-size: 12px;
    white-space: nowrap;
}

.metric-sub {
    font-size: 10px;
    color: var(--text-muted);
}

.metric-bar {
    display: inline-block;
    height: 6px;
    border-radius: 3px;
    background: #e8e8e8;
    width: 50px;
    vertical-align: middle;
    position: relative;
    overflow: hidden;
}

.metric-bar-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    border-radius: 3px;
}

.metric-bar-fill.green  { background: var(--success); }
.metric-bar-fill.yellow { background: var(--warning); }
.metric-bar-fill.red    { background: var(--danger); }

/* ---- Clickable Table Cells ---- */
td.clickable {
    cursor: pointer;
    color: var(--primary);
    transition: background 0.15s;
}
td.clickable:hover {
    background: #e6f7ff;
    text-decoration: underline;
}

/* ---- Stale Row (已失效设备) ---- */
.stale-row { background: #f5f5f5; }
.stale-row td { color: #999; }
.stale-row td button { opacity: 1 !important; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .config-grid { flex-direction: column; }
    .header { flex-direction: column; gap: 8px; align-items: flex-start; }
    .detail-grid { grid-template-columns: 1fr; }
}
