:root {
    --blue: #3b82f6;
    --blue-dark: #2563eb;
    --blue-light: #60a5fa;
    --orange: #f97316;
    --orange-light: #fb923c;
    --green: #10b981;
    --purple: #8b5cf6;
    --cyan: #06b6d4;
    --red: #ef4444;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 2px 8px rgba(0,0,0,.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,.12);
    --radius: 12px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #f0f4ff 0%, #fff7ed 100%);
    color: var(--gray-800);
    min-height: 100vh;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* ========== 导航栏 ========== */
.navbar {
    position: fixed; top: 0; left: 0; right: 0; height: 60px;
    background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--gray-200);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; z-index: 999;
}

.nav-brand {
    display: flex; align-items: center; gap: 8px;
    font-size: 1.25rem; font-weight: 700; color: var(--blue);
}
.brand-icon { font-size: 1.5rem; }

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

.device-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: 20px;
    background: linear-gradient(135deg, var(--orange), #ea580c);
    color: white; border: none;
    font-size: .85rem; font-weight: 600;
    cursor: pointer; transition: all .2s;
}
.device-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(249, 115, 22, .4);
}

.back-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: 20px;
    background: var(--gray-100); color: var(--gray-700);
    text-decoration: none; font-size: .85rem; font-weight: 600;
    transition: all .2s;
}
.back-btn:hover { background: var(--blue); color: #fff; }

/* ========== 弹窗样式 ========== */
.modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    display: none; align-items: center; justify-content: center;
    z-index: 10000;
}
.modal.active { display: flex; }

.modal-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: white; border-radius: 16px;
    width: 90%; max-width: 420px;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn .3s ease;
}
.modal-content.modal-large {
    max-width: 700px;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(-20px) scale(.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px; border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 {
    font-size: 1.1rem; font-weight: 700; color: var(--gray-800);
    display: flex; align-items: center; gap: 10px;
}
.modal-header h3 i { color: var(--blue); }

.close-btn {
    width: 32px; height: 32px; border-radius: 8px;
    border: none; background: var(--gray-100); color: var(--gray-500);
    font-size: 1.25rem; cursor: pointer; transition: all .2s;
    display: flex; align-items: center; justify-content: center;
}
.close-btn:hover { background: var(--gray-200); color: var(--gray-700); }

.modal-body {
    padding: 24px;
    overflow-y: auto;
}
.modal-content.modal-large .modal-body {
    flex: 1;
    overflow-y: auto;
}

.modal-desc {
    font-size: .9rem; color: var(--gray-500);
    margin-bottom: 16px;
}

.input-group {
    position: relative;
    display: flex; align-items: center;
}
.input-group i {
    position: absolute; left: 14px;
    color: var(--gray-400); font-size: 1rem;
}
.input-group input {
    width: 100%; padding: 12px 14px 12px 42px;
    border: 2px solid var(--gray-200); border-radius: 10px;
    font-size: 1rem; transition: all .2s;
}
.input-group input:focus {
    outline: none; border-color: var(--blue);
}

.error-msg {
    color: var(--red); font-size: .85rem;
    margin-top: 8px; min-height: 20px;
}

.modal-footer {
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 16px 24px; border-top: 1px solid var(--gray-200);
}

.btn {
    padding: 10px 20px; border-radius: 8px;
    font-size: .9rem; font-weight: 600;
    cursor: pointer; transition: all .2s; border: none;
    display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary {
    background: linear-gradient(135deg, var(--blue), var(--blue-dark));
    color: white;
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, .4);
}
.btn-secondary {
    background: var(--gray-100); color: var(--gray-700);
}
.btn-secondary:hover { background: var(--gray-200); }

.btn-add {
    background: linear-gradient(135deg, var(--green), #059669);
    color: white; margin-bottom: 16px;
}
.btn-add:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, .4);
}

.btn-delete {
    width: 36px; height: 36px; border-radius: 8px;
    border: none; background: var(--gray-100); color: var(--gray-400);
    cursor: pointer; transition: all .2s;
    display: flex; align-items: center; justify-content: center;
}
.btn-delete:hover {
    background: var(--red); color: white;
}

/* ========== 新增耗材表单 ========== */
.add-filament-section {
    margin-bottom: 16px;
}

.add-form {
    background: var(--gray-50);
    border: 2px dashed var(--gray-300);
    border-radius: 12px;
    padding: 16px;
    margin-top: 12px;
}

.add-form-row {
    display: flex; gap: 12px;
    margin-bottom: 12px;
}

.add-form-row .edit-field {
    flex: 1;
}

.add-form-row .color-field {
    flex: 0 0 60px;
}

.add-form-row .color-field input[type="color"] {
    width: 100%; height: 36px; padding: 2px;
    border: 1px solid var(--gray-300); border-radius: 6px;
    cursor: pointer;
}

.add-form-actions {
    display: flex; justify-content: flex-end; gap: 10px;
}

/* ========== 耗材编辑列表 ========== */
.filament-edit-list {
    display: flex; flex-direction: column; gap: 12px;
}

.filament-edit-item {
    display: flex; align-items: center; gap: 16px;
    padding: 16px; background: var(--gray-50);
    border-radius: 12px; border: 1px solid var(--gray-200);
}

.edit-color-preview {
    width: 44px; height: 44px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.spool-mini {
    width: 40px; height: 40px; border-radius: 50%;
    position: relative;
    box-shadow: inset 0 2px 6px rgba(0,0,0,.15), 0 2px 4px rgba(0,0,0,.1);
}
.spool-mini::after {
    content: ''; position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--gray-800); border: 2px solid var(--gray-600);
}
.edit-color-preview.f-white .spool-mini { background: linear-gradient(135deg, #fff, #d1d5db); border: 2px solid #bbb; }
.edit-color-preview.f-blue .spool-mini { background: linear-gradient(135deg, #a5d8ff, #74c0fc); border: 2px solid #4dabf7; }
.edit-color-preview.f-orange .spool-mini { background: linear-gradient(135deg, #ffc078, #fd7e14); border: 2px solid #e8590c; }
.edit-color-preview.f-black .spool-mini { background: linear-gradient(135deg, #495057, #212529); border: 2px solid #111; }
.edit-color-preview.f-pink .spool-mini { background: linear-gradient(135deg, #fcc2d7, #f06595); border: 2px solid #e64980; }
.edit-color-preview.f-red .spool-mini { background: linear-gradient(135deg, #ffa8a8, #fa5252); border: 2px solid #e03131; }

.edit-fields {
    flex: 1; display: flex; gap: 12px;
}
.edit-field {
    flex: 1;
}
.edit-field label {
    display: block; font-size: .75rem; color: var(--gray-500);
    margin-bottom: 4px;
}
.edit-field input {
    width: 100%; padding: 8px 12px;
    border: 1px solid var(--gray-300); border-radius: 8px;
    font-size: .9rem; transition: all .2s;
}
.edit-field input:focus {
    outline: none; border-color: var(--blue);
}

.edit-percent {
    width: 80px; flex-shrink: 0; text-align: center;
}
.pct-value {
    display: block; font-size: 1.1rem; font-weight: 700;
    color: var(--blue); margin-bottom: 6px;
}
.pct-bar {
    height: 6px; background: var(--gray-200);
    border-radius: 3px; overflow: hidden;
}
.pct-fill {
    height: 100%; border-radius: 3px;
    background: linear-gradient(90deg, var(--blue), var(--blue-dark));
    transition: width .3s ease;
}

/* ========== 主内容区 ========== */
.main-content { padding-top: 80px; padding-bottom: 40px; }

.page-title {
    text-align: center; font-size: 1.75rem; font-weight: 800;
    margin-bottom: 32px; display: flex; align-items: center; justify-content: center; gap: 10px;
    background: linear-gradient(135deg, var(--blue), #6366f1, var(--orange));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.page-title i { -webkit-text-fill-color: var(--blue); }

.section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
}

.section-title {
    font-size: 1.15rem; font-weight: 700; color: var(--gray-800);
    display: flex; align-items: center; gap: 8px;
}
.section-title i { color: var(--blue); }

.refresh-time { font-size: .78rem; color: var(--gray-400); }

.dashboard-section { margin-bottom: 36px; }

.status-row {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 14px;
}

.status-card {
    background: white; border-radius: var(--radius);
    padding: 16px; display: flex; align-items: center; gap: 12px;
    box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200);
    transition: all .2s;
}
.status-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.status-card.status-online {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white; border: none;
}
.status-card.status-offline {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white; border: none;
}

.pulse-wrapper { position: relative; width: 28px; height: 28px; flex-shrink: 0; }
.pulse-dot {
    width: 16px; height: 16px; border-radius: 50%;
    background: rgba(255,255,255,.9);
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,.5); }
    50% { box-shadow: 0 0 0 8px rgba(255,255,255,0); }
}

.status-text { flex: 1; min-width: 0; }
.status-text .label {
    display: block; font-size: .72rem; opacity: .85;
}
.status-text .value {
    display: block; font-size: 1rem; font-weight: 700;
}

.stat-card {
    background: white; border-radius: var(--radius);
    padding: 14px; display: flex; flex-direction: column; gap: 10px;
    box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200);
    transition: all .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-icon {
    width: 34px; height: 34px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: .95rem; color: white; flex-shrink: 0;
}
.cpu-icon { background: linear-gradient(135deg, var(--orange), #ea580c); }
.mem-icon { background: linear-gradient(135deg, var(--purple), #7c3aed); }
.disk-icon { background: linear-gradient(135deg, var(--cyan), #0891b2); }

.stat-info { display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: .72rem; color: var(--gray-400); }
.stat-value { font-size: .95rem; font-weight: 700; color: var(--gray-800); }

.stat-bar {
    height: 5px; background: var(--gray-200); border-radius: 3px;
    overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 3px; transition: width .8s ease; width: 0; }
.cpu-bar { background: linear-gradient(90deg, var(--orange), #ea580c); }
.mem-bar { background: linear-gradient(90deg, var(--purple), #7c3aed); }
.disk-bar { background: linear-gradient(90deg, var(--cyan), #0891b2); }

.info-card {
    background: white; border-radius: var(--radius);
    padding: 14px; display: flex; align-items: center; gap: 12px;
    box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200);
    transition: all .2s;
}
.info-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.info-icon {
    width: 34px; height: 34px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: .95rem; color: white; flex-shrink: 0;
}
.uptime-icon { background: linear-gradient(135deg, var(--green), #059669); }
.net-icon { background: linear-gradient(135deg, var(--blue), var(--blue-dark)); }

.info-text { flex: 1; min-width: 0; }
.info-label { display: block; font-size: .72rem; color: var(--gray-400); }
.info-value { display: block; font-size: .95rem; font-weight: 700; color: var(--gray-800); }

.printer-section { margin-bottom: 36px; }

.filament-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.filament-card {
    background: white; border-radius: var(--radius);
    padding: 18px; display: flex; align-items: center; gap: 14px;
    box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200);
    transition: all .2s;
}
.filament-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.spool-wrap {
    width: 52px; height: 52px; flex-shrink: 0;
    position: relative;
}
.spool {
    width: 52px; height: 52px; border-radius: 50%;
    position: relative;
    box-shadow: inset 0 2px 8px rgba(0,0,0,.15), 0 2px 6px rgba(0,0,0,.1);
}
.spool::after {
    content: ''; position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 16px; height: 16px; border-radius: 50%;
    background: var(--gray-800); border: 2px solid var(--gray-600);
}
.f-white .spool { background: linear-gradient(135deg, #fff, #d1d5db); border: 2px solid #bbb; }
.f-blue .spool { background: linear-gradient(135deg, #a5d8ff, #74c0fc); border: 2px solid #4dabf7; }
.f-orange .spool { background: linear-gradient(135deg, #ffc078, #fd7e14); border: 2px solid #e8590c; }
.f-black .spool { background: linear-gradient(135deg, #495057, #212529); border: 2px solid #111; }
.f-pink .spool { background: linear-gradient(135deg, #fcc2d7, #f06595); border: 2px solid #e64980; }
.f-red .spool { background: linear-gradient(135deg, #ffa8a8, #fa5252); border: 2px solid #e03131; }

.filament-data { flex: 1; min-width: 0; }
.f-name { display: block; font-size: .88rem; font-weight: 600; color: var(--gray-800); margin-bottom: 2px; }
.f-weight { display: block; font-size: 1.15rem; font-weight: 700; color: var(--blue); margin-bottom: 6px; }
.f-track { height: 6px; background: var(--gray-200); border-radius: 3px; overflow: hidden; margin-bottom: 3px; }
.f-fill { height: 100%; border-radius: 3px; transition: width .6s ease; }

/* 余量颜色显示 */
.f-fill.level-sufficient { background: linear-gradient(90deg, #40c057, #51cf66); }
.f-fill.level-normal { background: linear-gradient(90deg, #fab005, #fcc419); }
.f-fill.level-danger { background: linear-gradient(90deg, #fa5252, #ff6b6b); }
.f-fill.level-unavailable { background: linear-gradient(90deg, #adb5bd, #dee2e6); }

.services-section { margin-bottom: 36px; }

.services-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.svc-item {
    background: white; border-radius: var(--radius);
    padding: 16px; display: flex; align-items: center; gap: 14px;
    box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200);
    transition: all .2s;
}
.svc-item:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.svc-icon {
    width: 42px; height: 42px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; color: white; flex-shrink: 0;
}
.svc-web { background: linear-gradient(135deg, var(--blue), var(--blue-dark)); }
.svc-bot { background: linear-gradient(135deg, var(--purple), #7c3aed); }
.svc-napcat { background: linear-gradient(135deg, var(--orange), #ea580c); }

.svc-detail { flex: 1; }
.svc-name { display: block; font-size: .9rem; font-weight: 600; color: var(--gray-800); margin-bottom: 2px; }
.svc-status { font-size: .78rem; font-weight: 500; }
.svc-status.ok { color: var(--green); }
.svc-status.err { color: var(--red); }

.footer {
    text-align: center; padding: 24px 0;
    color: var(--gray-400); font-size: .82rem;
}

/* ========== 响应式 ========== */
@media (max-width: 1100px) {
    .status-row { grid-template-columns: repeat(3, 1fr); }
    .filament-grid { grid-template-columns: repeat(2, 1fr); }
    .services-list { grid-template-columns: repeat(2, 1fr); }

    .edit-fields { flex-direction: column; gap: 8px; }
    .filament-edit-item { flex-wrap: wrap; }
    .edit-percent { width: 100%; margin-top: 8px; text-align: left; }
}

@media (max-width: 768px) {
    .navbar { padding: 0 16px; height: 54px; }
    .nav-brand { font-size: 1.1rem; }
    .nav-actions { gap: 8px; }
    .device-btn, .back-btn { padding: 6px 12px; font-size: .8rem; }
    .main-content { padding-top: 68px; }
    .page-title { font-size: 1.35rem; margin-bottom: 24px; }
    .section-title { font-size: 1rem; }

    .status-row,
    .filament-grid,
    .services-list {
        grid-template-columns: 1fr; gap: 10px;
    }

    .status-card { padding: 14px; }
    .stat-card { padding: 12px; }
    .info-card { padding: 12px; }
    .filament-card { padding: 14px; flex-direction: column; text-align: center; gap: 10px; }
    .svc-item { padding: 14px; }
    .spool-wrap { width: 44px; height: 44px; }
    .spool { width: 44px; height: 44px; }

    .modal-content { width: 95%; border-radius: 12px; }
    .modal-header { padding: 16px 20px; }
    .modal-body { padding: 16px 20px; }
    .modal-footer { padding: 12px 20px; }

    .filament-edit-item {
        flex-direction: column; align-items: flex-start;
        padding: 12px;
    }
    .edit-fields { width: 100%; }
    .edit-percent { width: 100%; margin-top: 8px; }
}

@media (max-width: 480px) {
    .nav-actions .back-btn span { display: none; }
    .nav-actions .device-btn span { display: none; }
    .nav-actions .device-btn, .nav-actions .back-btn { padding: 8px; }
}
