/* ===== 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;
}

.dash-stat-meta {
    font-size: 0.8rem;
}

/* ===== 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; }

/* ===== Operations status widget ===== */
.ops-status-card .card-header {
    background: linear-gradient(90deg, #f8fafc 0%, #eef2ff 100%);
}

.ops-stat-tile {
    border: 1px solid #e2e8f0;
    border-radius: 0.6rem;
    padding: 0.75rem;
    background: #f8fafc;
}

.ops-stat-label {
    font-size: 0.78rem;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.25rem;
}

.ops-stat-value {
    font-size: 1.45rem;
    font-weight: 700;
    line-height: 1.1;
    color: #0f172a;
}

.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;
}

/* ===== 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;
}

/* ===== Page shell & empty state ===== */
.page-shell {
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
}

.page-section-header .page-subheading {
    margin-bottom: 0;
}

.empty-state-icon {
    font-size: 2.75rem;
    color: #cbd5e1;
    line-height: 1;
}

.empty-state-text {
    color: #64748b;
    font-size: 0.95rem;
    max-width: 28rem;
    margin-left: auto;
    margin-right: auto;
}

.table-log thead.table-sticky-light th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f1f5f9;
    box-shadow: inset 0 -1px 0 #e2e8f0;
}

/* Dashboard metric icon pills (avoid inline styles) */
.dash-icon-pill-product { background: #dbeafe; color: #2563eb; }
.dash-icon-pill-replen { background: #dcfce7; color: #16a34a; }
.dash-icon-pill-order { background: #fef3c7; color: #d97706; }
.dash-icon-pill-customer { background: #ede9fe; color: #7c3aed; }

.alert-live-region[role="status"] {
    border-radius: 0.5rem;
}

.btn-copy-success {
    background-color: #16a34a !important;
    border-color: #16a34a !important;
    color: #ffffff !important;
}

.btn-copy-error {
    background-color: #dc2626 !important;
    border-color: #dc2626 !important;
    color: #ffffff !important;
}

.btn-copy-muted {
    background-color: #64748b !important;
    border-color: #64748b !important;
    color: #ffffff !important;
}
