/* ============================================
   IoT 管理平台 — 浅色清爽风格
   ============================================ */

:root {
    --bg: #F5F7FA;
    --bg-white: #FFFFFF;
    --bg-hover: #F0F2F5;
    --bg-header: #FAFBFC;

    --primary: #2ECC71;
    --primary-hover: #27AE60;
    --primary-light: rgba(46,204,113,.08);
    --primary-bg: rgba(46,204,113,.06);

    --text-title: #333333;
    --text-body: #666666;
    --text-muted: #999999;
    --text-white: #FFFFFF;

    --border: #E8ECF0;
    --border-light: #F0F0F0;
    --divider: #E8ECF0;

    --danger: #E74C3C;
    --danger-hover: #C0392B;
    --danger-light: rgba(231,76,60,.08);
    --warning: #F39C12;
    --success: #2ECC71;
    --info: #3498DB;

    --radius: 4px;
    --radius-lg: 8px;

    --shadow-sm: 0 1px 3px rgba(0,0,0,.04);
    --shadow: 0 2px 8px rgba(0,0,0,.06);
    --shadow-lg: 0 4px 16px rgba(0,0,0,.08);

    --transition: .15s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text-body);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    font-size: 14px;
    line-height: 1.5;
}

/* ---- Navbar ---- */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 52px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: -.01em;
}

.navbar-brand i { font-size: 18px; }

.navbar-links {
    display: flex;
    gap: 0;
    height: 52px;
    align-items: center;
}

.navbar-links a {
    color: var(--text-muted);
    text-decoration: none;
    padding: 0 16px;
    height: 52px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: color var(--transition), border-color var(--transition);
    border-bottom: 2px solid transparent;
    position: relative;
}

.navbar-links a i { font-size: 15px; }
.navbar-links a:hover { color: var(--text-title); }

.navbar-links a.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ---- Main ---- */
main {
    padding: 0 24px 48px;
    animation: fadeIn .2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---- Breadcrumb ---- */
.breadcrumb {
    padding: 16px 0 0;
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb span { color: var(--text-title); font-weight: 500; }

/* ---- Page header ---- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0 0;
    margin-bottom: 20px;
}

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

.page-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-title);
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    line-height: 1.2;
    white-space: nowrap;
}

.btn:active { transform: scale(.98); }

.btn-sm { padding: 5px 12px; font-size: 12px; gap: 4px; }
.btn-sm i { font-size: 12px; }

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

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

.btn-ghost {
    background: var(--bg-white);
    color: var(--text-body);
    border: 1px solid var(--border);
}

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

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

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

/* ---- Cards ---- */
.project-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    margin-bottom: 12px;
    transition: all var(--transition);
}

.project-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
}

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

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

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

.project-meta {
    display: flex;
    gap: 24px;
    font-size: 13px;
    color: var(--text-muted);
}

.project-meta i { margin-right: 4px; font-size: 12px; }

.project-key-preview {
    margin-right: 2px;
}

.btn-copy-key {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 12px;
    border-radius: 3px;
    transition: all var(--transition);
    vertical-align: middle;
}

.btn-copy-key:hover {
    color: var(--primary);
    background: var(--primary-bg);
}

.project-desc {
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ---- Project info card ---- */
.project-info-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0;
    overflow: hidden;
}

.info-row {
    display: flex;
    align-items: center;
    padding: 16px 24px;
    gap: 16px;
    border-bottom: 1px solid var(--border-light);
}

.info-row:last-child { border-bottom: none; }

.info-row label {
    width: 80px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    flex-shrink: 0;
}

.info-row span { font-size: 14px; color: var(--text-title); }

.mono-text {
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
    font-size: 13px;
    color: var(--primary);
    background: var(--primary-bg);
    padding: 2px 8px;
    border-radius: 3px;
}

/* ---- Filter bar ---- */
.filter-bar {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 20px;
    padding: 16px 20px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

.filter-group select,
.filter-group input {
    background: var(--bg-white);
    border: 1px solid var(--border);
    color: var(--text-title);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 14px;
    min-width: 200px;
    transition: border-color var(--transition);
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(46,204,113,.15);
}

/* ---- Stats ---- */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
}

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

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-title);
}

.stat-card.online-card .stat-value { color: var(--success); }
.stat-card.offline-card .stat-value { color: var(--text-muted); }

/* Legacy stat items */
.stats { display: flex; gap: 12px; }

.stat-item {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 13px;
    background: var(--bg);
}

.stat-online { color: var(--success); }
.stat-offline { color: var(--text-muted); }

/* ---- Device cards ---- */
.device-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    margin-bottom: 10px;
    transition: all var(--transition);
    border-left: 3px solid transparent;
}

.device-card.online { border-left-color: var(--success); }
.device-card.offline { border-left-color: var(--text-muted); }

.device-card:hover {
    box-shadow: var(--shadow);
    border-color: var(--border);
}

/* ---- Compact device card grid ---- */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.device-card-compact {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    cursor: pointer;
    transition: all var(--transition);
    border-top: 3px solid transparent;
}

.device-card-compact.online { border-top-color: var(--success); }
.device-card-compact.offline { border-top-color: var(--text-muted); }

.device-card-compact:hover {
    box-shadow: var(--shadow);
    border-color: var(--primary);
    transform: translateY(-1px);
}

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

.dcc-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-title);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 65%;
}

.dcc-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.dcc-info span {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dcc-info i { width: 14px; text-align: center; font-size: 11px; }

/* Signal strength colors */
.signal-strong { color: var(--success); }
.signal-medium { color: var(--warning); }
.signal-weak { color: var(--danger); }

/* ---- Device detail modal ---- */
.device-detail-modal {
    width: 560px;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .2s ease, visibility .2s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.detail-row {
    display: flex;
    align-items: center;
    padding: 12px 0;
    gap: 16px;
    border-bottom: 1px solid var(--border-light);
}

.detail-row:last-child { border-bottom: none; }

.detail-row label {
    width: 80px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    flex-shrink: 0;
}

.detail-row span {
    font-size: 14px;
    color: var(--text-title);
    word-break: break-all;
}

.detail-data-section {
    padding-top: 12px;
}

.detail-data-section label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 8px;
}

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

.device-id { font-weight: 600; font-size: 14px; color: var(--text-title); }

.device-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
}

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

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 4px var(--success);
}

.status-dot.offline { background: #CCCCCC; }

.device-meta {
    display: flex;
    gap: 20px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.device-meta i { margin-right: 4px; font-size: 11px; }

.device-data {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 12px 16px;
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
    font-size: 12px;
    color: var(--text-body);
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 200px;
    overflow-y: auto;
    line-height: 1.6;
}

/* ---- Data table ---- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.data-table th {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 13px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-body);
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover td { background: var(--bg-hover); }

.data-table .actions { white-space: nowrap; }
.data-table .actions .btn { margin-right: 4px; }

.data-table code {
    background: var(--primary-bg);
    color: var(--primary-hover);
    padding: 2px 8px;
    border-radius: 3px;
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
    font-size: 12px;
}

/* ---- Modal ---- */
.modal {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    width: 480px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

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

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

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius);
    transition: all var(--transition);
    line-height: 1;
}

.modal-close:hover { color: var(--text-title); background: var(--bg); }

.modal-body { padding: 20px 24px; }

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

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

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

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

.form-group input[type="text"],
.form-group textarea,
.form-group input[type="file"] {
    width: 100%;
    background: var(--bg-white);
    border: 1px solid var(--border);
    color: var(--text-title);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color var(--transition);
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(46,204,113,.15);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-muted);
}

.form-group input[type="file"] { padding: 6px 12px; cursor: pointer; }

/* ---- Empty & Placeholder ---- */
.empty-state {
    text-align: center;
    padding: 64px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

.placeholder-page {
    text-align: center;
    padding: 80px 20px;
}

.placeholder-icon {
    font-size: 48px;
    margin-bottom: 16px;
    color: var(--border);
}

.placeholder-page h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-body);
    margin-bottom: 8px;
}

.placeholder-page p { font-size: 14px; color: var(--text-muted); }

/* ---- Pagination ---- */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 24px 0;
}

.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-white);
    color: var(--text-body);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
}

.page-btn:hover:not(:disabled):not(.active) {
    border-color: var(--primary);
    color: var(--primary);
}

.page-btn.active {
    background: var(--primary);
    color: var(--text-white);
    border-color: var(--primary);
}

.page-btn:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.page-ellipsis {
    padding: 0 4px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ---- Toast ---- */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--bg-white);
    border: 1px solid var(--border);
    color: var(--text-title);
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    animation: toastIn .2s ease, toastOut .3s ease 2.7s forwards;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast i { font-size: 16px; }
.toast.success { border-left: 3px solid var(--success); }
.toast.success i { color: var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.error i { color: var(--danger); }
.toast.info { border-left: 3px solid var(--info); }
.toast.info i { color: var(--info); }

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

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

/* ---- Text helpers ---- */
.text-danger { color: var(--danger); font-size: 13px; margin-top: 8px; line-height: 1.5; }

/* ---- Footer ---- */
.footer {
    text-align: center;
    padding: 24px;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    margin-top: 40px;
    background: var(--bg-white);
}

.footer span { color: var(--primary); font-weight: 600; }

/* ---- Firmware list ---- */
.firmware-list { margin-top: 0; }

/* ---- Device list in project detail ---- */
.device-list { margin-top: 0; }

.device-count-label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 400;
}

/* ---- Tab navigation ---- */
.tab-nav {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
    margin-top: 4px;
}

.tab-btn {
    background: none;
    border: none;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
}

.tab-btn i { font-size: 14px; }

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

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

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* ---- Device log entries ---- */
.log-entry {
    border-bottom: 1px solid var(--border-light);
    padding: 12px 0;
}

.log-entry:last-child { border-bottom: none; }

.log-entry-time {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.log-entry-time i { margin-right: 4px; }

.log-entry-content {
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
    font-size: 13px;
    color: var(--text-body);
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.5;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D0D5DD; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #B0B5BD; }

/* ---- Selection ---- */
::selection { background: rgba(46,204,113,.2); color: var(--text-title); }

/* ---- Login ---- */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 104px);
    padding: 40px 20px;
}

.login-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    width: 380px;
    max-width: 100%;
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 28px;
}

.login-header i {
    font-size: 40px;
    color: var(--primary);
    margin-bottom: 12px;
}

.login-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-title);
    margin-bottom: 6px;
}

.login-header p {
    font-size: 13px;
    color: var(--text-muted);
}

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

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

.login-form input {
    width: 100%;
    background: var(--bg-white);
    border: 1px solid var(--border);
    color: var(--text-title);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color var(--transition);
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(46,204,113,.15);
}

.login-form input::placeholder {
    color: var(--text-muted);
}

.login-btn {
    width: 100%;
    padding: 10px 0;
    font-size: 15px;
    margin-top: 8px;
}

.login-error {
    background: var(--danger-light);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
    text-align: center;
}

/* ---- Navbar user ---- */
.navbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-body);
}

.navbar-user .btn-logout {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 4px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    transition: all var(--transition);
}

.navbar-user .btn-logout:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* ---- Add device bar ---- */
.add-device-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
}

.add-device-manual {
    display: flex;
    gap: 8px;
    align-items: center;
}

.add-device-manual input {
    width: 220px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
    transition: border-color var(--transition);
}

.add-device-manual input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(46,204,113,.15);
}

.add-device-manual input::placeholder {
    color: var(--text-muted);
    font-family: inherit;
}

.add-device-or {
    font-size: 13px;
    color: var(--text-muted);
}

.add-device-excel {
    display: flex;
    align-items: center;
    gap: 8px;
}

.excel-hint {
    font-size: 12px;
    color: var(--text-muted);
}
