/* ===== CSS Variables ===== */
:root {
    --sidebar-bg: #1e293b;
    --sidebar-bg-2: #0f172a;
    --sidebar-hover: #334155;
    --sidebar-active: #3b82f6;
    --content-bg: #f1f5f9;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-light: #94a3b8;
    --text-white: #f8fafc;
    --border-color: #e2e8f0;
    --accent: #3b82f6;
    --accent-light: #60a5fa;
    --accent-bg: #eff6ff;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --sidebar-width: 260px;
    --header-height: 60px;
}

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

body {
    font-family: 'Inter', -apple-system, 'Microsoft YaHei', sans-serif;
    background: var(--content-bg);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

/* ===== App Container ===== */
.app-container {
    display: flex;
    height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-white);
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
}

.logo-icon {
    font-size: 22px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
}

.nav-section {
    margin-bottom: 8px;
}

.nav-section-title {
    padding: 12px 24px 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-light);
}

.nav-items {
    list-style: none;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 24px;
    color: #cbd5e1;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
    white-space: nowrap;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--text-white);
}

.nav-item.active {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-light);
    border-left-color: var(--sidebar-active);
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.nav-label {
    flex: 1;
}

.nav-arrow {
    font-size: 12px;
    transition: transform 0.2s ease;
}

.nav-arrow.expanded {
    transform: rotate(90deg);
}

.nav-subitems {
    list-style: none;
    margin-left: 20px;
    border-left: 1px solid rgba(255,255,255,0.08);
}

.nav-subitem {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 24px;
    color: #94a3b8;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
}

.nav-subitem:hover {
    color: var(--text-white);
    background: var(--sidebar-hover);
}

.nav-subitem.active {
    color: var(--accent-light);
    border-left-color: var(--accent);
}

.nav-sub-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.6;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-light);
}

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

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-header {
    height: var(--header-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: var(--radius);
    transition: background 0.15s ease;
}

.sidebar-toggle:hover {
    background: var(--content-bg);
}

.page-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-time {
    font-size: 13px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
}

.user-name {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

.page-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ===== Page Content ===== */
.page-content {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Cards ===== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 20px;
}

/* ===== Stats Cards ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.stat-info {
    flex: 1;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.stat-change {
    font-size: 12px;
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.stat-icon.blue { background: #dbeafe; }
.stat-icon.green { background: #dcfce7; }
.stat-icon.orange { background: #fef3c7; }
.stat-icon.red { background: #fee2e2; }
.stat-icon.cyan { background: #cffafe; }

/* ===== Charts ===== */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.chart-container {
    position: relative;
    height: 280px;
}

/* ===== Tables ===== */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead th {
    text-align: left;
    padding: 12px 16px;
    background: #f8fafc;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

tbody tr:hover {
    background: #f8fafc;
}

tbody tr:last-child td {
    border-bottom: none;
}

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

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-secondary {
    background: var(--content-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: white;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-icon {
    padding: 6px 8px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all 0.15s ease;
}

.btn-icon:hover {
    background: var(--content-bg);
    color: var(--text-primary);
}

.btn-icon.danger:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-info { background: #dbeafe; color: #1d4ed8; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* ===== Forms ===== */
.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.form-label .required {
    color: var(--danger);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text-primary);
    background: white;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    font-family: inherit;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: white;
    border-radius: var(--radius-lg);
    width: 560px;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.2s ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-light);
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

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

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--text-primary);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    animation: slideInRight 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast.success { background: #15803d; }
.toast.error { background: #b91c1c; }
.toast.info { background: #1d4ed8; }

/* ===== Tabs ===== */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s ease;
}

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

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 15px;
    margin-bottom: 20px;
}

/* ===== Warning List ===== */
.warning-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.warning-item {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-left: 4px solid transparent;
}

.warning-item.critical { border-left-color: var(--danger); }
.warning-item.high { border-left-color: var(--warning); }
.warning-item.medium { border-left-color: var(--info); }
.warning-item.low { border-left-color: var(--text-light); }

.warning-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.warning-icon.critical { background: #fee2e2; }
.warning-icon.high { background: #fef3c7; }
.warning-icon.medium { background: #cffafe; }
.warning-icon.low { background: #f1f5f9; }

.warning-content {
    flex: 1;
}

.warning-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.warning-desc {
    font-size: 13px;
    color: var(--text-secondary);
}

.warning-time {
    font-size: 12px;
    color: var(--text-light);
    text-align: right;
    white-space: nowrap;
}

/* ===== Config Cards ===== */
.config-section {
    max-width: 640px;
}

.config-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.config-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.config-card-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.config-card-body {
    padding: 20px;
}

.config-card-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: #f8fafc;
}

/* ===== Robot List ===== */
.robot-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.robot-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: border-color 0.15s ease;
}

.robot-card:hover {
    border-color: var(--accent-light);
}

.robot-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    background: var(--accent-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.robot-info {
    flex: 1;
}

.robot-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.robot-webhook {
    font-size: 12px;
    color: var(--text-light);
    font-family: monospace;
    word-break: break-all;
}

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

/* ===== Filter Bar ===== */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-bar .form-input,
.filter-bar .form-select {
    width: auto;
    min-width: 160px;
}

.search-box {
    position: relative;
    flex: 1;
    max-width: 300px;
}

.search-box input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 13px;
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.search-box::before {
    content: '🔍';
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
}

.filter-spacer {
    flex: 1;
}

/* ===== Upload Area ===== */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 24px 16px;
    text-align: center;
    transition: all 0.15s ease;
    background: #fafbfc;
}

.upload-area:hover {
    border-color: var(--accent);
    background: var(--accent-bg);
}

/* 合并上传区域 - 更大更醒目 */
.upload-area-merged {
    padding: 36px 24px;
    border-width: 2px;
}

/* 拖拽悬停高亮 */
.upload-area-merged.drag-over {
    border-color: #2563eb;
    background: #dbeafe;
    transform: scale(1.01);
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.2);
}

.upload-area.dragover {
    border-color: var(--accent);
    background: var(--accent-bg);
}

/* ===== Contact Tags ===== */
.contact-tag-area {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 38px;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: white;
    align-items: center;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px 4px 10px;
    background: var(--accent-bg);
    color: var(--accent);
    border-radius: 14px;
    font-size: 12px;
    font-weight: 500;
}

.tag-remove {
    cursor: pointer;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 14px;
    line-height: 1;
}

.tag-remove:hover {
    background: var(--accent);
    color: white;
}

.tag-input {
    border: none !important;
    box-shadow: none !important;
    padding: 4px 0 !important;
    background: transparent !important;
    flex: 1;
    min-width: 120px;
}

.tag-input:focus {
    outline: none;
    box-shadow: none !important;
}

/* ===== Picker Items ===== */
.picker-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.picker-item:hover {
    border-color: var(--accent-light);
    background: var(--accent-bg);
}

.picker-item input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

/* ===== Inspection Module ===== */
.inspection-tabs {
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
}
.inspection-tab {
    padding: 10px 20px;
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
    position: relative;
}
.inspection-tab:hover {
    color: var(--accent);
}
.inspection-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}
.tab-badge {
    display: inline-block;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    background: var(--accent);
    color: white;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 4px;
    padding: 0 5px;
}
.btn-warning {
    background: #f59e0b;
    color: white;
}
.btn-warning:hover {
    background: #d97706;
}
.btn-danger {
    background: #ef4444;
    color: white;
}
.btn-danger:hover {
    background: #dc2626;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .chart-grid {
        grid-template-columns: 1fr;
    }
    .form-row,
    .form-row-3 {
        grid-template-columns: 1fr;
    }
}
