:root {
    --header-height: 80px;
    --panel-bg: rgba(248, 252, 255, 0.72);
    --panel-border: rgba(255, 255, 255, 0.56);
    --panel-shadow: 0 16px 40px rgba(7, 28, 63, 0.18);
    --panel-hover-bg: rgba(255, 255, 255, 0.9);
    --accent-cyan: #00c8ff;
    --accent-blue: #2c78fa;
}

@media (max-width: 768px) {
    :root { --header-height: 60px; }
}

body {
    background-image:
        radial-gradient(circle at 20% 15%, rgba(0, 205, 255, 0.12), transparent 42%),
        radial-gradient(circle at 80% 0%, rgba(44, 120, 250, 0.1), transparent 35%),
        var(--bg-img);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    font-family: 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
    overflow: hidden;
    letter-spacing: 0.01em;
}

h1, h2, h3,
header .font-bold,
.tab-btn {
    font-family: 'Rajdhani', 'Noto Sans SC', sans-serif;
    letter-spacing: 0.02em;
}

.app-overlay {
    background:
        linear-gradient(120deg, rgba(2, 8, 24, calc(var(--opacity) + 0.08)), rgba(2, 20, 48, calc(var(--opacity) + 0.04))),
        repeating-linear-gradient(90deg, rgba(255,255,255,0.02) 0 1px, transparent 1px 24px);
}

.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(var(--blur)) saturate(150%);
    -webkit-backdrop-filter: blur(var(--blur)) saturate(150%);
    border: 1px solid var(--panel-border);
    box-shadow: var(--panel-shadow);
}

.dark {
    --panel-bg: rgba(9, 26, 50, 0.68);
    --panel-border: rgba(110, 185, 255, 0.2);
    --panel-shadow: 0 20px 46px rgba(0, 12, 28, 0.5);
    --panel-hover-bg: rgba(20, 42, 72, 0.82);
}

.dark .glass-panel {
    color: #e2e8f0;
}

.glass-hover:hover {
    background: var(--panel-hover-bg);
    transform: translateY(-3px);
    border-color: rgba(0, 200, 255, 0.35);
}

.tab-content {
    display: none !important;
    height: 100%;
    width: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-content.active {
    display: flex !important;
    animation: contentFadeIn 0.35s ease;
}

#view-iframe { overflow: hidden; }

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

.bookmark-grid {
    display: grid;
    gap: 1.2rem;
    width: 100%;
}

.bookmark-item {
    border: 1px solid rgba(255, 255, 255, 0.22);
    transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
    position: relative;
}

.bookmark-item:hover {
    border-color: rgba(0, 200, 255, 0.42);
    box-shadow: 0 12px 28px rgba(0, 90, 160, 0.2);
}

.bookmark-item.is-dragging {
    opacity: 0.5;
    transform: scale(0.97);
}

.bookmark-item[draggable="true"] {
    cursor: grab;
}

.bookmark-item[draggable="true"]:active {
    cursor: grabbing;
}

@media (max-width: 768px) {
    .bookmark-grid {
        grid-template-columns: repeat(auto-fill, minmax(75px, 1fr)) !important;
        gap: 0.6rem !important;
        padding: 0.5rem !important;
    }

    .bookmark-item {
        aspect-ratio: 1 / 1 !important;
        min-height: unset !important;
        height: auto !important;
        padding: 0.4rem !important;
        border-radius: 1rem !important;
    }

    .bookmark-item img,
    .bookmark-item .lucide,
    .bookmark-item i,
    .bookmark-item .bg-yellow-400\/20 {
        width: 1.75rem !important;
        height: 1.75rem !important;
        margin-bottom: 0.2rem !important;
        padding: 0 !important;
    }

    .bookmark-item span {
        font-size: 0.65rem !important;
        font-weight: 500 !important;
        line-height: 1.1 !important;
        max-width: 100% !important;
    }

}

.notes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.2rem;
}

@media (max-width: 768px) {
    .notes-grid {
        grid-template-columns: 1fr;
        gap: 0.9rem;
    }
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.7rem;
}

.calendar-day {
    aspect-ratio: 1 / 1;
    transition: all 0.2s;
    position: relative;
}

.calendar-day.today {
    border: 2px solid var(--accent-cyan);
    box-shadow: 0 0 0 2px rgba(0, 200, 255, 0.16);
}

.has-note::after {
    content: '';
    position: absolute;
    bottom: 6px;
    right: 6px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #0ea5e9;
}

main {
    height: calc(100vh - var(--header-height));
    overflow: hidden;
    position: relative;
}

.tab-content::-webkit-scrollbar { width: 6px; }

.tab-content::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(0, 200, 255, 0.55), rgba(44, 120, 250, 0.55));
    border-radius: 999px;
}

#view-bookmarks::-webkit-scrollbar { display: none; }

#view-bookmarks {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.tab-btn {
    opacity: 0.76;
    color: rgba(18, 33, 56, 0.88);
    transition: all 0.2s ease;
}

.dark .tab-btn { color: rgba(226, 232, 240, 0.82); }

.tab-btn.active-tab {
    background: linear-gradient(120deg, rgba(0, 200, 255, 0.25), rgba(44, 120, 250, 0.22));
    color: #0f172a;
    font-weight: 700;
    opacity: 1;
}

.dark .tab-btn.active-tab {
    color: #e2e8f0;
    background: linear-gradient(120deg, rgba(0, 200, 255, 0.2), rgba(44, 120, 250, 0.28));
}

#mobile-menu {
    transition: transform 0.3s ease;
    transform: translateY(-100%);
}

#mobile-menu.open { transform: translateY(0); }

.drop-target {
    outline: 2px dashed var(--accent-cyan);
    background: rgba(0, 200, 255, 0.12) !important;
    scale: 1.04;
}

#bm-search-wrap {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    width: 42px;
}

#bm-search-wrap:focus-within {
    width: 230px;
    border-color: rgba(0, 200, 255, 0.5);
}

@media (max-width: 640px) {
    #bm-search-wrap:focus-within { width: 140px; }
}

#engine-selector-menu {
    animation: slideUp 0.2s ease-out;
    border: 1px solid rgba(255, 255, 255, 0.14);
}

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

.tm-autosize {
    transition: height 0.15s ease;
}

.control-shell {
    background: rgba(248, 252, 255, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.42);
    backdrop-filter: blur(16px) saturate(120%);
    -webkit-backdrop-filter: blur(16px) saturate(120%);
    position: relative;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.control-shell::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: linear-gradient(90deg, rgba(14, 165, 233, 0.85), rgba(16, 185, 129, 0.85));
    pointer-events: none;
}

.dark .control-shell {
    background: rgba(9, 20, 36, 0.94);
    border-color: rgba(71, 85, 105, 0.65);
}

.settings-modal .settings-section {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(203, 213, 225, 0.65);
    border-radius: 14px;
    padding: 14px;
    margin-bottom: 12px;
}

.dark .settings-modal .settings-section {
    background: rgba(15, 30, 50, 0.88);
    border-color: rgba(71, 85, 105, 0.55);
}

.settings-modal .settings-flat-panel {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.dark .settings-modal .settings-flat-panel {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.settings-section-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.72;
    margin: 0 0 10px;
}

.settings-field {
    margin-bottom: 12px;
}

.settings-field:last-child {
    margin-bottom: 0;
}

.settings-label {
    display: block;
    font-size: 12px;
    opacity: 0.72;
    margin-bottom: 6px;
    font-weight: 700;
}

.settings-input {
    width: 100%;
    padding: 0.56rem 0.72rem;
    border-radius: 10px;
    background: rgba(241, 245, 249, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.32);
    outline: none;
    font-size: 13px;
}

.settings-input:focus {
    border-color: rgba(14, 165, 233, 0.55);
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.12);
}

.dark .settings-input {
    background: rgba(15, 23, 42, 0.7);
    border-color: rgba(100, 116, 139, 0.45);
}

.settings-chip {
    padding: 0.5rem 0.6rem;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    font-weight: 700;
    font-size: 13px;
    transition: all 0.2s ease;
    background: rgba(241, 245, 249, 0.8);
}

.settings-chip:hover {
    background: rgba(226, 232, 240, 0.9);
}

.dark .settings-chip {
    border-color: rgba(100, 116, 139, 0.5);
    background: rgba(30, 41, 59, 0.65);
}

.control-overview-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.control-kpi {
    background: rgba(241, 245, 249, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.32);
    border-radius: 12px;
    padding: 10px 12px;
    min-height: 72px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.dark .control-kpi {
    background: rgba(15, 23, 42, 0.72);
    border-color: rgba(100, 116, 139, 0.5);
}

.control-kpi-label {
    font-size: 12px;
    opacity: 0.65;
    font-weight: 600;
}

.control-kpi-value {
    font-size: 22px;
    line-height: 1;
    font-weight: 800;
    color: #0f172a;
    font-family: 'Rajdhani', 'Noto Sans SC', sans-serif;
}

.dark .control-kpi-value {
    color: #e2e8f0;
}

.control-overview-updated {
    margin-top: 10px;
    font-size: 12px;
    opacity: 0.66;
}

.device-session-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.device-session-empty {
    border: 1px dashed rgba(148, 163, 184, 0.6);
    border-radius: 12px;
    padding: 14px;
    font-size: 13px;
    opacity: 0.72;
    text-align: center;
}

.device-card {
    border: 1px solid rgba(148, 163, 184, 0.42);
    background: rgba(248, 250, 252, 0.9);
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.dark .device-card {
    background: rgba(15, 23, 42, 0.72);
    border-color: rgba(100, 116, 139, 0.55);
}

.device-card:hover {
    transform: translateY(-1px);
    border-color: rgba(56, 189, 248, 0.48);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.1);
}

.device-main {
    min-width: 0;
    flex: 1;
}

.device-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}

.device-title {
    font-size: 14px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-status {
    font-size: 11px;
    border-radius: 999px;
    padding: 2px 8px;
    border: 1px solid;
}

.device-status.is-online {
    color: #0369a1;
    border-color: rgba(14, 165, 233, 0.5);
    background: rgba(186, 230, 253, 0.55);
}

.device-status.is-offline {
    color: #64748b;
    border-color: rgba(148, 163, 184, 0.5);
    background: rgba(241, 245, 249, 0.7);
}

.device-meta {
    font-size: 12px;
    opacity: 0.72;
    margin-top: 2px;
}

.device-badges {
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.device-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.5);
    background: rgba(241, 245, 249, 0.85);
}

.device-badge.is-current {
    color: #155e75;
    border-color: rgba(34, 211, 238, 0.55);
    background: rgba(207, 250, 254, 0.7);
}

.device-badge.is-persistent {
    color: #166534;
    border-color: rgba(34, 197, 94, 0.62);
    background: rgba(220, 252, 231, 0.82);
}

.dark .device-badge.is-persistent {
    color: #86efac;
    border-color: rgba(34, 197, 94, 0.6);
    background: rgba(20, 83, 45, 0.55);
}

.device-badge.is-temporary {
    color: #64748b;
    border-color: rgba(148, 163, 184, 0.45);
    background: rgba(241, 245, 249, 0.78);
}

.dark .device-badge.is-temporary {
    color: #cbd5e1;
    border-color: rgba(100, 116, 139, 0.6);
    background: rgba(30, 41, 59, 0.65);
}

.device-actions {
    display: flex;
    align-items: center;
}

.device-remove {
    border: 1px solid rgba(248, 113, 113, 0.45);
    color: #b91c1c;
    background: rgba(254, 226, 226, 0.78);
    border-radius: 10px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.device-remove:hover {
    background: rgba(254, 202, 202, 0.95);
}

.device-remove.danger {
    color: #7f1d1d;
    border-color: rgba(220, 38, 38, 0.55);
}

.tm-calendar-option {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    max-width: 100%;
    padding: 0.55rem 0.65rem;
    border-radius: 0.9rem;
    background: rgba(15, 23, 42, 0.05);
}

.dark .tm-calendar-option {
    background: rgba(255, 255, 255, 0.07);
}

.tm-calendar-check {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    font-weight: 700;
}

.tm-calendar-icon {
    line-height: 1;
}

.tm-calendar-time {
    width: 12rem;
    max-width: calc(100vw - 8rem);
    padding: 0.45rem 0.6rem;
    border-radius: 0.65rem;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(255, 255, 255, 0.85);
    font-size: 0.82rem;
    outline: none;
}

.dark .tm-calendar-time {
    background: rgba(0, 0, 0, 0.18);
    border-color: rgba(148, 163, 184, 0.28);
}

.tm-calendar-time:disabled {
    opacity: 0.45;
}

.tm-image-preview,
.tm-feed-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: 0.55rem;
    margin: -0.35rem 0 1rem;
}

.tm-image-preview.hidden,
.tm-feed-images.hidden {
    display: none;
}

.tm-image-thumb,
.tm-feed-image {
    position: relative;
    display: block;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.08);
}

.dark .tm-image-thumb,
.dark .tm-feed-image {
    background: rgba(255, 255, 255, 0.08);
}

.tm-image-thumb img,
.tm-feed-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tm-image-thumb button {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    width: 1.75rem;
    height: 1.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: white;
    background: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.tm-feed-images {
    margin: 0.85rem 0 0;
}

.tm-feed-image {
    transition: transform 0.18s ease, opacity 0.18s ease;
}

.tm-feed-image:hover {
    transform: translateY(-1px);
    opacity: 0.92;
}

@media (max-width: 768px) {
    .control-overview-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .device-card {
        flex-direction: column;
        align-items: stretch;
    }

    .device-actions {
        justify-content: flex-end;
    }

    .tm-calendar-option {
        width: 100%;
        justify-content: flex-start;
    }

    .tm-image-preview,
    .tm-feed-images {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

#bookmark-container {
    padding-bottom: 9rem !important;
}

@media (max-width: 768px) {
    #bookmark-container {
        padding-bottom: calc(11rem + env(safe-area-inset-bottom)) !important;
    }

    #bookmark-fab {
        bottom: calc(0.9rem + env(safe-area-inset-bottom)) !important;
    }
}

.folder-drop-dock {
    position: fixed;
    left: 50%;
    bottom: 1rem;
    transform: translateX(-50%);
    width: min(860px, calc(100vw - 2rem));
    z-index: 60;
    background: rgba(6, 23, 44, 0.92);
    border: 1px solid rgba(0, 200, 255, 0.34);
    box-shadow: 0 16px 40px rgba(0, 15, 32, 0.45);
    border-radius: 16px;
    padding: 12px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.folder-drop-dock.hidden {
    display: none !important;
}

.folder-drop-dock-title {
    color: #cdeefe;
    font-size: 12px;
    font-weight: 600;
    margin: 0 0 8px;
    opacity: 0.9;
}

.folder-drop-dock-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
    max-height: 220px;
    overflow: auto;
    padding-right: 2px;
}

.folder-drop-target {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    text-align: left;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.13);
    color: #eff7ff;
    border-radius: 10px;
    padding: 8px 10px;
    transition: all 0.16s ease;
}

.folder-drop-target.root-target {
    border-color: rgba(16, 185, 129, 0.45);
    background: rgba(16, 185, 129, 0.16);
}

.folder-drop-target.root-target .folder-drop-target-title {
    color: #d1fae5;
}

.folder-drop-target-title {
    font-size: 13px;
    font-weight: 700;
    color: #f0f9ff;
}

.folder-drop-target-path {
    font-size: 10px;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.folder-drop-target.is-over {
    border-color: rgba(0, 200, 255, 0.7);
    box-shadow: 0 0 0 1px rgba(0, 200, 255, 0.5) inset;
    background: rgba(0, 200, 255, 0.16);
}

.tm-image-viewer {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 64px 64px 56px;
    border: 0;
    background: rgba(8, 12, 20, 0.96);
    color: white;
    overflow: hidden;
}
.tm-image-viewer[open] { display: flex; align-items: center; justify-content: center; }
.tm-image-viewer::backdrop { background: rgba(0, 0, 0, 0.8); }
.tm-viewer-image-link { display: flex; max-width: 100%; max-height: 100%; }
.tm-viewer-image { max-width: 100%; max-height: calc(100vh - 120px); max-height: calc(100dvh - 120px); object-fit: contain; }
.tm-viewer-close, .tm-viewer-prev, .tm-viewer-next {
    position: absolute;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: white;
    font-size: 32px;
    cursor: pointer;
    z-index: 1;
}
.tm-image-viewer button[hidden] { display: none; }
.tm-image-viewer button:hover { background: rgba(255, 255, 255, 0.26); }
.tm-image-viewer :focus-visible { outline: 2px solid #7dd3fc; outline-offset: 4px; }
.tm-viewer-close { top: max(12px, env(safe-area-inset-top)); right: 16px; }
.tm-viewer-prev { left: 12px; top: calc(50% - 22px); }
.tm-viewer-next { right: 12px; top: calc(50% - 22px); }
.tm-viewer-counter { position: absolute; top: max(24px, env(safe-area-inset-top)); left: 24px; font-size: 14px; }
.tm-viewer-hint { position: absolute; bottom: max(18px, env(safe-area-inset-bottom)); left: 16px; right: 16px; text-align: center; font-size: 12px; color: #cbd5e1; pointer-events: none; }
@media (max-width: 640px) {
    .tm-image-viewer { padding-left: 8px; padding-right: 8px; }
    .tm-viewer-prev, .tm-viewer-next { width: 36px; height: 36px; top: calc(50% - 18px); background: rgba(0, 0, 0, 0.5); }
    .tm-viewer-prev { left: 8px; }
    .tm-viewer-next { right: 8px; }
}

.folder-drop-dock-empty {
    color: rgba(222, 237, 248, 0.75);
    font-size: 12px;
    padding: 10px;
}
