/* ============================================================
   BayRobot 管理平台 — 全局主题 (亮色·绿色系)
   所有主要页面通过 <link rel="stylesheet" href="/css/theme.css"> 引入
   ============================================================ */

/* 1. CSS 变量 */
:root {
    --primary-1: #f0fdf4;             /* 页面主背景：极浅绿白 */
    --primary-2: #ffffff;             /* 卡片/容器背景：纯白 */
    --accent-green: #16a34a;          /* 主绿色：深绿，可读性好 */
    --accent-green-light: #dcfce7;    /* 浅绿：用于徽章/背景 */
    --accent-green-hover: #15803d;    /* 悬停绿：更深 */
    --accent-blue: #0ea5e9;           /* 辅助蓝色 */
    --text-primary: #1e293b;          /* 主要文字：深色 */
    --text-secondary: #64748b;        /* 次要文字：中灰 */
    --text-light: #334155;            /* 兼容旧变量名 → 深色字 */
    --text-lighter: #1e293b;          /* 兼容旧变量名 → 深色字 */
    --primary-dark-1: #f0fdf4;        /* 兼容旧 --primary-1 引用 */
    --primary-dark-2: #ffffff;        /* 兼容旧 --primary-2 引用 */
    --border-light: rgba(0, 0, 0, 0.08); /* 边框 */
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.08); /* 阴影 */
    --error-red: #ef4444;
    --warning-yellow: #f59e0b;
    --nav-height: 64px;
    --sidebar-width: 220px;
}

/* 2. 全局重置 */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    overflow-y: scroll;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: 'Noto Sans SC', 'Segoe UI', sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    background-color: var(--primary-1);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

button, input, select, textarea {
    font: inherit;
}

/* 3. 顶部导航栏 */
.top-nav {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 50;
    height: var(--nav-height);
    background: var(--accent-green);
    box-shadow: 0 2px 8px rgba(22, 163, 74, 0.3);
    transition: none; /* 防止导航栏自身动画 */
}

.nav-container {
    max-width: 1440px;
    margin: 0 auto;
    height: 100%;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr) 220px;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
}

/* 4. Logo */
.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.15rem;
    color: #ffffff !important;
    background: none !important;
    -webkit-background-clip: unset !important;
    background-clip: unset !important;
    text-decoration: none;
    flex-shrink: 0;
    width: 220px;
    overflow: hidden;
}

.nav-logo-img {
    width: 30px;
    height: 30px;
    object-fit: contain;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.96);
    padding: 3px;
    box-shadow: 0 1px 6px rgba(15, 23, 42, 0.18);
}

/* 5. 导航按钮 */
.nav-buttons {
    display: flex;
    gap: 4px;
    justify-content: center;
    min-width: 0;
}

.nav-btn {
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    border: none;
    color: rgba(255, 255, 255, 0.85); /* 默认：白色半透明 */
    background: transparent;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

/* 防止 Tailwind mr-* 等工具类给图标附加额外边距 */
.nav-btn i {
    margin: 0;
}

.nav-btn:hover:not(.selected) {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.15);
}

.nav-btn.selected {
    background: rgba(255, 255, 255, 0.22);
    color: #ffffff;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.4);
}

/* 6. 用户菜单 */
.user-menu {
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
    justify-self: end;
    width: 220px;
}

.user-info {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.875rem;
    transition: background 0.15s;
    min-width: 100%;
}

.user-info:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 180px;
    background: #ffffff;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
}

.user-menu:hover .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.875rem;
    border-radius: 8px;
    transition: background 0.1s;
}

.dropdown-item:hover {
    background: var(--accent-green-light);
    color: var(--accent-green);
}

/* 7. 主内容区 */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 24px 24px 40px 28px;
    min-height: 100vh;
}

/* 8. 统计卡片 */
.stat-card {
    background: var(--primary-2);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat-icon { border-radius: 8px; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; }
.stat-icon.total  { background: #dcfce7; color: var(--accent-green); }
.stat-icon.online { background: #e0f2fe; color: var(--accent-blue); }
.stat-icon.error  { background: #fee2e2; color: var(--error-red); }
.stat-icon.area   { background: #fef9c3; color: var(--warning-yellow); }

.stat-title { font-size: 0.85rem; color: var(--text-secondary); }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--text-primary); }
.stat-value.total  { color: var(--accent-green); }
.stat-value.error  { color: var(--error-red); }
.stat-value.area   { color: var(--warning-yellow); }

/* 9. 通用卡片 */
.card {
    background: var(--primary-2);
    border-radius: 14px;
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    margin-bottom: 20px;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.card-title i { color: var(--accent-green); }

/* 10. 按钮 */
.action-btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border-light);
    background: var(--primary-2);
    color: var(--text-primary);
    transition: background 0.15s, border-color 0.15s;
}

.action-btn.primary {
    background: var(--accent-green);
    color: #ffffff;
    border: none;
    box-shadow: 0 2px 8px rgba(22, 163, 74, 0.25);
}

.action-btn:hover:not(.primary) {
    background: var(--accent-green-light);
    border-color: var(--accent-green);
    color: var(--accent-green);
}

.action-btn.primary:hover { background: var(--accent-green-hover); }

.refresh-btn {
    width: 34px; height: 34px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-1);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.refresh-btn:hover { background: var(--accent-green-light); color: var(--accent-green); border-color: var(--accent-green); }

/* 11. 设备卡片 */
.device-list-container {
    background: var(--primary-2);
    border-radius: 14px;
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}

.device-card {
    background: var(--primary-1);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 18px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.device-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-green);
    box-shadow: 0 6px 20px rgba(22, 163, 74, 0.12);
}

.device-name { font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.device-mode { font-size: 0.82rem; color: var(--text-secondary); }

/* 12. 状态徽章 */
.status-online  { background: #dcfce7; color: #16a34a; }
.status-offline { background: #f1f5f9; color: #94a3b8; }
.status-error   { background: #fee2e2; color: #ef4444; }
.status-online .status-indicator  { background: #16a34a; animation: pulse 2s infinite; }
.status-offline .status-indicator { background: #94a3b8; }
.status-error .status-indicator   { background: #ef4444; animation: blink 1.5s infinite alternate; }

/* 13. 电池条 */
.battery-bar { background: #e2e8f0; }
.battery-high   { background: var(--accent-green); }
.battery-medium { background: var(--warning-yellow); }
.battery-low    { background: var(--error-red); }

/* 14. 骨架屏 */
.skeleton-card { background: var(--primary-1); border: 1px solid var(--border-light); }
.skeleton-avatar, .skeleton-status, .skeleton-text, .skeleton-battery {
    background: #e2e8f0;
    animation: skeleton-loading 1.5s infinite;
}

/* 15. 动作图标按钮 */
.action-icon-btn {
    width: 34px; height: 34px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-1);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.action-icon-btn:hover { background: var(--accent-green-light); color: var(--accent-green); }

/* 16. 页面标题 */
.page-title { display: flex; align-items: center; gap: 10px; font-size: 1.4rem; font-weight: 700; color: var(--text-primary); margin-bottom: 24px; }
.page-title i { color: var(--accent-green); }
.page-description { color: var(--text-secondary); font-size: 0.92rem; line-height: 1.7; margin-top: -12px; }

/* 17. 通用工具栏 / 搜索 */
.search-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.search-field {
    position: relative;
    width: min(420px, 100%);
}

.search-field i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 11px 14px 11px 40px;
    border-radius: 10px;
    border: 1px solid var(--border-light);
    background: var(--primary-1);
    color: var(--text-primary);
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.search-input:focus {
    border-color: var(--accent-green);
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.12);
    background: #ffffff;
}

.search-input::placeholder {
    color: var(--text-secondary);
}

.search-meta {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-secondary);
}

.empty-state i {
    display: block;
    font-size: 2.4rem;
    margin-bottom: 12px;
    opacity: 0.45;
}

/* 18. 子页面表单布局 */
.page-panel {
    max-width: 960px;
    margin: 0 auto;
    padding: 40px 24px 48px;
}

.page-panel.narrow {
    max-width: 860px;
}

.stack-lg {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.form-card {
    background: var(--primary-2);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    padding: 28px;
    box-shadow: var(--shadow);
}

.page-back-btn {
    margin-bottom: 18px;
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-section + .form-section {
    margin-top: 28px;
}

.form-section-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.form-section-label small {
    font-weight: 400;
    color: var(--text-secondary);
}

.helper-text {
    color: var(--text-secondary);
    font-size: 0.83rem;
    line-height: 1.6;
}

.dynamic-form-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.input-group,
.dynamic-form-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    background: var(--primary-1);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.input-group:hover,
.dynamic-form-row:hover {
    transform: translateY(-1px);
    border-color: rgba(22, 163, 74, 0.22);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
}

.input-group.single-line,
.dynamic-form-row.single-line {
    align-items: center;
}

.form-grid-two {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    flex: 1;
}

.form-grid-one {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    flex: 1;
}

.text-input,
.text-select {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-light);
    background: #ffffff;
    color: var(--text-primary);
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.text-input:focus,
.text-select:focus {
    border-color: var(--accent-green);
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.12);
}

.remove-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--error-red);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
}

.remove-btn:hover {
    background: rgba(239, 68, 68, 0.1);
}

.inline-link-btn {
    width: fit-content;
    border: none;
    background: transparent;
    color: var(--accent-green);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    font-weight: 600;
}

.inline-link-btn:hover {
    color: var(--accent-green-hover);
}

.upload-dropzone {
    border: 2px dashed rgba(100, 116, 139, 0.28);
    border-radius: 14px;
    padding: 24px 20px;
    text-align: center;
    background: linear-gradient(180deg, rgba(240, 253, 244, 0.55), rgba(255, 255, 255, 0.9));
    transition: border-color 0.18s ease, background 0.18s ease;
}

.upload-dropzone:hover {
    border-color: var(--accent-green);
    background: linear-gradient(180deg, rgba(220, 252, 231, 0.8), rgba(255, 255, 255, 0.96));
}

.upload-dropzone-label {
    cursor: pointer;
    display: block;
    color: var(--text-secondary);
}

.upload-dropzone-label i {
    display: block;
    font-size: 2rem;
    margin-bottom: 10px;
    color: #94a3b8;
}

.upload-dropzone-label strong {
    display: block;
    margin-bottom: 6px;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.file-list {
    margin-top: 14px;
    text-align: left;
}

.file-list-title {
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 0.84rem;
    font-weight: 600;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.84rem;
    line-height: 1.5;
}

.file-item + .file-item {
    margin-top: 6px;
}

.button-row {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 28px;
}

/* 19. 底部 footer */
.footer {
    background: var(--primary-2);
    border-top: 1px solid var(--border-light);
    padding: 16px 24px;
    margin-top: 40px;
}
.footer-container {
    max-width: 1440px; margin: 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    color: var(--text-secondary); font-size: 0.8rem;
    flex-wrap: wrap; gap: 8px;
}

/* 20. 动画 */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.4s ease forwards; }

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.7; }
}

@keyframes blink {
    0%   { opacity: 0.5; }
    100% { opacity: 1; }
}

@keyframes skeleton-loading {
    0%, 100% { background: #e2e8f0; }
    50%       { background: #f1f5f9; }
}

/* 21. 响应式 */
@media (max-width: 768px) {
    .nav-buttons .nav-btn span { display: none; }
    .nav-btn { width: 40px; height: 40px; padding: 0; justify-content: center; }
    .nav-container { padding: 0 12px; }
    .nav-container { grid-template-columns: auto minmax(0, 1fr) auto; }
    .logo, .user-menu { width: auto; }
    .form-card { padding: 22px; }
    .form-grid-two { grid-template-columns: 1fr; }
    .page-panel { padding: 24px 16px 36px; }
}

@media (max-width: 480px) {
    .logo span { display: none; }
    .user-info span { display: none; }
    .search-field { width: 100%; }
    .button-row { flex-direction: column; }
    .button-row .action-btn { width: 100%; justify-content: center; }
}

/* 22. Tailwind 兼容工具类（供移除了 Tailwind CDN 的页面使用） */
.hidden { display: none !important; }
.fixed  { position: fixed; }
.inset-0 { top: 0; right: 0; bottom: 0; left: 0; }
.flex   { display: flex; }
.items-center   { align-items: center; }
.justify-center { justify-content: center; }
.z-50 { z-index: 50; }
.w-full { width: 100%; }
.max-w-md { max-width: 28rem; }
.rounded-lg { border-radius: 0.5rem; }
.shadow-xl { box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04); }
.p-6  { padding: 1.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.text-lg   { font-size: 1.125rem; }
.font-bold { font-weight: 700; }
.flex-end  { justify-content: flex-end; }
.space-x-4 > * + * { margin-left: 1rem; }
.justify-end { justify-content: flex-end; }
