/* ===== Base ===== */
html {
    font-size: 14px;
    position: relative;
    min-height: 100%;
}
@media (min-width: 768px) {
    html { font-size: 16px; }
}

*,
*::before,
*::after { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    background: #f1f5f9;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    overflow-x: hidden;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus,
.form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    background: #1e293b;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: width 0.25s ease, transform 0.25s ease;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 64px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid #334155;
    min-height: 60px;
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    text-decoration: none;
    color: #f8fafc;
    font-weight: 700;
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar-brand:hover { color: #f8fafc; }

.brand-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
}

#sidebarToggle {
    font-size: 1.1rem;
    flex-shrink: 0;
    color: #94a3b8 !important;
    transition: transform 0.25s;
}
#sidebarToggle:hover { color: #f8fafc !important; }

.sidebar.collapsed #collapseIcon {
    transform: rotate(180deg);
}

/* ===== Sidebar navigation ===== */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem 0;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }

.sidebar-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-item { position: relative; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1rem;
    color: #cbd5e1;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    border-left: 3px solid transparent;
    font-size: 0.875rem;
}

.sidebar-link:hover {
    background: #334155;
    color: #f1f5f9;
}

.sidebar-link.active {
    background: #334155;
    color: #38bdf8;
    border-left-color: #38bdf8;
}

.sidebar-link > i:first-child {
    font-size: 1.15rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

.link-text {
    overflow: hidden;
    transition: opacity 0.2s;
}

.sidebar.collapsed .link-text,
.sidebar.collapsed .submenu-arrow,
.sidebar.collapsed .sidebar-brand-text,
.sidebar.collapsed .external-icon {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.submenu-arrow {
    margin-left: auto;
    font-size: 0.7rem;
    transition: transform 0.25s, opacity 0.2s;
}

.sidebar-link[aria-expanded="true"] .submenu-arrow {
    transform: rotate(180deg);
}

/* ===== Submenu ===== */
.sidebar-submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    background: #162032;
}

.sidebar-submenu .sidebar-link {
    padding-left: 2.75rem;
    font-size: 0.825rem;
}

.sidebar-submenu .sidebar-link > i:first-child {
    font-size: 0.9rem;
}

.sidebar.collapsed .sidebar-submenu {
    display: none !important;
}

/* ===== Sidebar footer ===== */
.sidebar-footer {
    border-top: 1px solid #334155;
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-footer a {
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.8rem;
}
.sidebar-footer a:hover { color: #f1f5f9; }

.sidebar-footer form { display: inline; }
.sidebar-footer button.nav-link {
    color: #94a3b8 !important;
    font-size: 0.8rem;
    padding: 0;
    border: none;
    background: none;
}
.sidebar-footer button.nav-link:hover { color: #f1f5f9 !important; }

/* ===== Main content ===== */
.main-content {
    margin-left: 260px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.25s ease;
}

.sidebar.collapsed ~ .main-content {
    margin-left: 64px;
}

.main-content > main {
    flex: 1;
}

.main-footer {
    border-top: 1px solid #e2e8f0;
    padding: 1rem 0;
    font-size: 0.85rem;
}

/* ===== Mobile top bar ===== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: #1e293b;
    color: #f8fafc;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    min-height: 52px;
}

.topbar-brand {
    font-weight: 700;
    font-size: 1.05rem;
    flex: 1;
}

.topbar a { color: #94a3b8; font-size: 0.8rem; text-decoration: none; }
.topbar a:hover { color: #f1f5f9; }
.topbar form { display: inline; }
.topbar button.nav-link {
    color: #94a3b8 !important;
    font-size: 0.8rem;
    padding: 0;
    border: none;
    background: none;
}

/* ===== Sidebar overlay (mobile) ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1035;
}
.sidebar-overlay.show { display: block; }

/* ===== Responsive ===== */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px !important;
    }
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0 !important;
    }
}

/* ===== Dashboard cards ===== */
.dash-card {
    border: none;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: box-shadow 0.2s, transform 0.15s;
    text-decoration: none;
    color: inherit;
    display: block;
}
.dash-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    transform: translateY(-2px);
    color: inherit;
    text-decoration: none;
}
.dash-card .card-body { padding: 1.25rem; }
.dash-card .dash-icon {
    width: 48px;
    height: 48px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}
.dash-count {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}
.dash-label {
    font-size: 0.8rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Sync log cards ===== */
.log-card {
    border: none;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    background: #fff;
    overflow: hidden;
}

.log-card .card-header {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 0.875rem 1.25rem;
}

.log-card .card-header h2,
.log-card .card-header h5 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.filter-bar {
    display: flex;
    gap: 0.75rem;
    align-items: end;
    flex-wrap: wrap;
    padding: 1rem 1.25rem;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.filter-bar label {
    font-size: 0.8rem;
    font-weight: 500;
    color: #475569;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.filter-bar .form-control,
.filter-bar .form-select {
    font-size: 0.85rem;
    min-width: 130px;
}

/* Table styling */
.table-log {
    margin: 0;
    font-size: 0.85rem;
}
.table-log thead th {
    background: #f1f5f9;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #475569;
    border-bottom-width: 1px;
    padding: 0.65rem 0.75rem;
    white-space: nowrap;
}
.table-log td {
    vertical-align: middle;
    padding: 0.55rem 0.75rem;
}
.table-log tbody tr:hover {
    background: #f8fafc;
}

/* ===== Settings page ===== */
.settings-card {
    border: none;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    background: #fff;
    margin-bottom: 1.5rem;
}
.settings-card .card-header {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    font-weight: 600;
    padding: 0.875rem 1.25rem;
}
.settings-card .card-body { padding: 1.25rem; }

.setting-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f1f5f9;
}
.setting-row:last-child { border-bottom: none; }
.setting-label {
    font-size: 0.85rem;
    color: #64748b;
    font-weight: 500;
}
.setting-value {
    font-size: 0.85rem;
    color: #1e293b;
    font-family: 'Consolas', 'Courier New', monospace;
}

/* ===== Reveal panel ===== */
.reveal-panel {
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    overflow: hidden;
    background: #f8fafc;
}
.reveal-panel-header {
    background: #e9eef5;
    padding: 0.45rem 0.75rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: #475569;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.25rem;
    border-bottom: 1px solid #dde4ef;
}
.reveal-panel-warning {
    font-weight: 400;
    color: #92400e;
    font-size: 0.75rem;
}
.reveal-table {
    width: 100%;
    border-collapse: collapse;
}
.reveal-table tr {
    border-bottom: 1px solid #e9eef5;
}
.reveal-table tr:last-child {
    border-bottom: none;
}
.reveal-field-label {
    width: 120px;
    padding: 0.45rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: #64748b;
    white-space: nowrap;
    vertical-align: middle;
}
.reveal-field-value {
    padding: 0.35rem 0.5rem;
    vertical-align: middle;
}
.reveal-value-input {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.78rem;
    background: #fff;
    color: #1e293b;
    border: 1px solid #cbd5e1;
    cursor: default;
    word-break: break-all;
}
.reveal-value-input:focus {
    box-shadow: none;
    border-color: #94a3b8;
}
.reveal-absent-badge {
    font-size: 0.72rem;
    vertical-align: middle;
}
.reveal-field-copy {
    width: 44px;
    padding: 0.35rem 0.5rem;
    text-align: center;
    vertical-align: middle;
}

/* ===== Utility ===== */
.badge-success { background-color: #22c55e !important; }
.badge-danger { background-color: #ef4444 !important; }
.badge-warning { background-color: #f59e0b !important; color: #1e293b !important; }
.badge-info { background-color: #3b82f6 !important; }

.page-heading {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 0.25rem;
}
.page-subheading {
    font-size: 0.9rem;
    color: #64748b;
    margin-bottom: 1.5rem;
}

/* ===== Bulk sync pages ===== */
.bulk-sync-page .form-check-input:focus-visible,
.bulk-sync-page .btn:focus-visible,
.bulk-sync-page .form-control:focus-visible {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

.bulk-sync-page .bulk-progress-percent {
    font-size: 1.25rem;
    font-weight: 700;
    color: #0d6efd;
}

.bulk-sync-page .bulk-stat-card h6 {
    font-weight: 600;
    color: #334155;
    margin-bottom: 0.5rem;
}

.bulk-sync-page .bulk-error-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.bulk-sync-page .progress-bar-animated {
    animation: progress-bar-stripes 1s linear infinite;
}

.bulk-sync-page .table-hover tbody tr:hover {
    background-color: #f5f5f5;
}

@media (max-width: 575.98px) {
    .bulk-sync-page .dash-card .card-body {
        padding: 0.9rem;
    }
}
