/* File Manager v3 — สำนักงานศึกษาธิการจังหวัดอุดรธานี */
:root,
[data-theme="light"] {
    --fm-bg: #f3f6fb;
    --fm-surface: #ffffff;
    --fm-surface-alt: #f8fafd;
    --fm-border: #e1e8f0;
    --fm-text: #162235;
    --fm-text-muted: #607087;
    --fm-primary: #0f3d7a;
    --fm-primary-hover: #0a2d5c;
    --fm-primary-soft: rgba(15, 61, 122, 0.08);
    --fm-accent: #1d64c2;
    --fm-shadow: 0 2px 10px rgba(15, 42, 82, 0.06);
    --fm-shadow-lg: 0 10px 30px rgba(15, 42, 82, 0.12);
    --fm-navbar-bg: linear-gradient(135deg, #092852 0%, #0f3d7a 60%, #1954a1 100%);
    --fm-input-bg: #ffffff;
}

[data-theme="dark"] {
    --fm-bg: #0d131f;
    --fm-surface: #151e2e;
    --fm-surface-alt: #1b263a;
    --fm-border: #2a3954;
    --fm-text: #e6edf7;
    --fm-text-muted: #93a4bd;
    --fm-primary: #4e94f3;
    --fm-primary-hover: #367fe0;
    --fm-primary-soft: rgba(78, 148, 243, 0.14);
    --fm-accent: #6aa7ff;
    --fm-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    --fm-shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
    --fm-navbar-bg: linear-gradient(135deg, #0a1426 0%, #0f2547 65%, #163668 100%);
    --fm-input-bg: #111928;
}

body {
    font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--fm-bg);
    color: var(--fm-text);
    line-height: 1.55;
    min-height: 100vh;
}

a {
    color: var(--fm-primary);
}
a:hover {
    color: var(--fm-primary-hover);
}

/* Override bootstrap elements to match CSS vars */
.card {
    background-color: var(--fm-surface);
    border: 1px solid var(--fm-border);
    color: var(--fm-text);
    border-radius: 14px;
    box-shadow: var(--fm-shadow);
}
.card-header {
    background-color: var(--fm-surface);
    border-bottom: 1px solid var(--fm-border);
    padding: 0.9rem 1.2rem;
    border-top-left-radius: 14px !important;
    border-top-right-radius: 14px !important;
}
.card-footer {
    background-color: var(--fm-surface-alt);
    border-top: 1px solid var(--fm-border);
}

.form-control,
.form-select {
    background-color: var(--fm-input-bg);
    border-color: var(--fm-border);
    color: var(--fm-text);
}
.form-control:focus,
.form-select:focus {
    background-color: var(--fm-input-bg);
    color: var(--fm-text);
    border-color: var(--fm-primary);
    box-shadow: 0 0 0 0.2rem var(--fm-primary-soft);
}
.input-group-text {
    background-color: var(--fm-surface-alt);
    border-color: var(--fm-border);
    color: var(--fm-text-muted);
}

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--fm-text);
    --bs-table-border-color: var(--fm-border);
    --bs-table-hover-bg: var(--fm-primary-soft);
    --bs-table-hover-color: var(--fm-text);
}
.table thead th {
    background-color: var(--fm-surface-alt);
    color: var(--fm-text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    border-bottom-width: 1px;
    white-space: nowrap;
}

.modal-content {
    background-color: var(--fm-surface);
    color: var(--fm-text);
    border: 1px solid var(--fm-border);
    border-radius: 16px;
}
.modal-header,
.modal-footer {
    border-color: var(--fm-border);
}
[data-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

.text-muted {
    color: var(--fm-text-muted) !important;
}

/* Navbar */
.fm-navbar {
    background: var(--fm-navbar-bg);
    box-shadow: 0 2px 12px rgba(9, 40, 82, 0.2);
}
.fm-navbar .navbar-brand {
    font-weight: 700;
    letter-spacing: 0.2px;
}

/* Hero strip */
.fm-hero {
    background: var(--fm-navbar-bg);
    color: #fff;
    padding: 1.5rem 0;
    margin-bottom: 1.5rem;
}
.fm-hero-stat {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    padding: 0.6rem 1rem;
    backdrop-filter: blur(4px);
}

/* Tag Sidebar */
.fm-tag-sidebar {
    position: sticky;
    top: 1rem;
}
.fm-tag-list {
    max-height: 62vh;
    overflow-y: auto;
}
.fm-tag-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    text-decoration: none;
    color: var(--fm-text);
    font-size: 0.9rem;
    transition: background-color 0.15s, transform 0.1s;
    border: 1px solid transparent;
}
.fm-tag-item:hover {
    background-color: var(--fm-primary-soft);
    color: var(--fm-text);
}
.fm-tag-item.active {
    background-color: var(--fm-primary);
    color: #fff;
    font-weight: 600;
}
.fm-tag-item.active .badge {
    background-color: rgba(255, 255, 255, 0.22) !important;
    color: #fff !important;
}
.fm-tag-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.fm-tag-name {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.3;
}

/* File Cards */
.fm-file-card {
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
    overflow: hidden;
}
.fm-file-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--fm-shadow-lg);
    border-color: var(--fm-primary);
}
.fm-file-icon-box {
    height: 112px;
    background-color: var(--fm-surface-alt);
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--fm-border);
    position: relative;
}
.fm-file-title {
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.6em;
}
.fm-type-badge {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.4px;
    padding: 0.25em 0.55em;
    border-radius: 6px;
}

/* Dropzone */
.fm-dropzone {
    border: 2px dashed var(--fm-border);
    border-radius: 14px;
    padding: 2rem 1rem;
    text-align: center;
    cursor: pointer;
    background-color: var(--fm-surface-alt);
    transition: border-color 0.2s, background-color 0.2s;
}
.fm-dropzone:hover,
.fm-dropzone.drag-over {
    border-color: var(--fm-primary);
    background-color: var(--fm-primary-soft);
}
.fm-queue-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.8rem;
    border-radius: 10px;
    background-color: var(--fm-surface-alt);
    border: 1px solid var(--fm-border);
    margin-bottom: 0.5rem;
}

/* Tag Selector Pills */
.fm-tag-pill {
    cursor: pointer;
    user-select: none;
    border-radius: 999px;
    padding: 0.4em 0.9em;
    font-size: 0.85rem;
    border: 1px solid var(--fm-border);
    background-color: var(--fm-surface-alt);
    color: var(--fm-text-muted);
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.fm-tag-pill.active {
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* Embed specifics */
body.fm-embed-body {
    background: transparent;
    min-height: auto;
    padding: 4px;
}
.fm-embed-shell {
    background-color: var(--fm-surface);
    border: 1px solid var(--fm-border);
    border-radius: 14px;
    padding: 1rem;
    box-shadow: var(--fm-shadow);
}
.fm-embed-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 0.9rem;
}
.fm-card-preview {
    height: 195px;
    background-color: var(--fm-surface-alt);
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--fm-border);
    position: relative;
    overflow: hidden;
}
.fm-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    display: block;
    transition: transform 0.2s ease;
}
.fm-file-card:hover .fm-thumb-img {
    transform: scale(1.03);
}
.fm-table-thumb {
    width: 36px;
    height: 48px;
    object-fit: cover;
    object-position: top center;
    border-radius: 5px;
    border: 1px solid var(--fm-border);
    background-color: var(--fm-surface-alt);
    flex-shrink: 0;
    transition: transform 0.15s ease;
}
.fm-table-thumb:hover {
    transform: scale(1.12);
}
.fm-table-icon-box {
    width: 36px;
    height: 48px;
    border-radius: 5px;
    border: 1px solid var(--fm-border);
    background-color: var(--fm-surface-alt);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.25rem;
}
.fm-compact-thumb {
    width: 28px;
    height: 36px;
    object-fit: cover;
    object-position: top center;
    border-radius: 4px;
    border: 1px solid var(--fm-border);
    background-color: var(--fm-surface-alt);
    flex-shrink: 0;
}
.fm-embed-grid .fm-card-preview {
    height: 215px;
}

/* Admin Sidebar Layout */
.fm-admin-wrapper {
    display: flex;
    min-height: 100vh;
}
.fm-admin-sidebar {
    width: 260px;
    flex-shrink: 0;
    background: linear-gradient(180deg, #092852 0%, #0d3266 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
}
.fm-admin-sidebar .nav-link {
    color: rgba(255, 255, 255, 0.8);
    border-radius: 10px;
    padding: 0.6rem 0.9rem;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-size: 0.95rem;
}
.fm-admin-sidebar .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.12);
    color: #fff;
}
.fm-admin-sidebar .nav-link.active {
    background-color: #ffffff;
    color: #092852;
    font-weight: 700;
}
.fm-admin-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.fm-admin-topbar {
    background-color: var(--fm-surface);
    border-bottom: 1px solid var(--fm-border);
    padding: 0.75rem 1.5rem;
}

.fm-stat-card {
    border: none;
    border-radius: 14px;
    color: #fff;
    overflow: hidden;
    position: relative;
}
.fm-stat-card .fm-stat-bg-icon {
    position: absolute;
    right: 1rem;
    bottom: -0.35rem;
    font-size: 3.4rem;
    opacity: 0.2;
}

@media (max-width: 991.98px) {
    .fm-admin-wrapper {
        flex-direction: column;
    }
    .fm-admin-sidebar {
        width: 100%;
    }
    .fm-tag-sidebar {
        position: static;
    }
}
