/* Base Styling & Responsive System - Desktop First with Mobile Fluidity */
:root {
    --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --transition-speed: 0.2s;
    --sidebar-width: 260px;
    --topbar-height: 64px;
}

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

body {
    font-family: var(--font-main);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-color, #1e293b);
    background-color: var(--bg-body, #f8fafc);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--primary-color, #2563eb);
    text-decoration: none;
    transition: all var(--transition-speed);
}
a:hover {
    color: var(--primary-hover, #1d4ed8);
}

/* Layout Grid */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.app-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    z-index: 100;
    transition: all var(--transition-speed) ease-in-out;
}

.app-main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* Prevents flex children from overflowing */
}

.app-topbar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 90;
    flex-shrink: 0;
}

.app-content {
    flex-grow: 1;
    padding: 24px;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

/* Utility Flex */
.d-flex { display: flex; }
.flex-column { flex-direction: column; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.justify-content-center { justify-content: center; }
.justify-content-end { justify-content: flex-end; }
.flex-grow-1 { flex-grow: 1; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }
.gap-4 { gap: 24px; }

.m-0 { margin: 0; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.me-1 { margin-right: 4px; }
.me-2 { margin-right: 8px; }
.me-3 { margin-right: 16px; }
.ms-auto { margin-left: auto; }

.p-0 { padding: 0; }
.p-2 { padding: 8px; }
.p-3 { padding: 16px; }
.p-4 { padding: 24px; }

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { opacity: 0.75; }
.fw-bold { font-weight: 700; }
.fw-semibold { font-weight: 600; }
.text-danger { color: #ef4444; }
.text-success { color: #16a34a; }
.text-warning { color: #d97706; }
.text-primary { color: #2563eb; }

/* Grid System */
.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
}
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}
.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}
.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

/* Card Component */
.card {
    background: var(--card-bg, #ffffff);
    border: var(--card-border, 1px solid #e2e8f0);
    border-radius: var(--border-radius, 8px);
    box-shadow: var(--card-shadow, 0 1px 3px rgba(0,0,0,0.05));
    position: relative;
}
.card-header {
    padding: 16px 20px;
    border-bottom: var(--card-border, 1px solid #e2e8f0);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-title {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
}
.card-body {
    padding: 20px;
}
.card-footer {
    padding: 12px 20px;
    border-top: var(--card-border, 1px solid #e2e8f0);
    background: var(--card-footer-bg, rgba(0,0,0,0.02));
}

/* Form Styles */
.form-group {
    margin-bottom: 16px;
}
.form-label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 6px;
}
.form-control, .form-select {
    width: 100%;
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--input-border, #cbd5e1);
    border-radius: var(--input-radius, 6px);
    background: var(--input-bg, #ffffff);
    color: inherit;
    outline: none;
    transition: border-color var(--transition-speed);
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary-color, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
textarea.form-control {
    min-height: 90px;
    resize: vertical;
}

/* Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: var(--btn-radius, 6px);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-speed);
    white-space: nowrap;
    gap: 6px;
}
.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}
.btn-lg {
    padding: 12px 24px;
    font-size: 15px;
}
.btn-primary {
    background: var(--primary-color, #2563eb);
    color: #ffffff;
    border-color: var(--primary-color, #2563eb);
}
.btn-primary:hover {
    background: var(--primary-hover, #1d4ed8);
    color: #ffffff;
}
.btn-success {
    background: #16a34a;
    color: #ffffff;
    border-color: #16a34a;
}
.btn-success:hover { background: #15803d; color: #ffffff; }
.btn-danger {
    background: #dc2626;
    color: #ffffff;
    border-color: #dc2626;
}
.btn-danger:hover { background: #b91c1c; color: #ffffff; }
.btn-warning {
    background: #d97706;
    color: #ffffff;
    border-color: #d97706;
}
.btn-warning:hover { background: #b45309; color: #ffffff; }
.btn-outline {
    background: transparent;
    color: inherit;
    border-color: var(--input-border, #cbd5e1);
}
.btn-outline:hover {
    background: rgba(0,0,0,0.05);
}

/* Tables */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}
.table th {
    padding: 12px 14px;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--table-th-bg, #f1f5f9);
    border-bottom: 2px solid var(--card-border, #cbd5e1);
}
.table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--table-border, #e2e8f0);
    vertical-align: middle;
}
.table tr:hover {
    background: var(--table-hover, rgba(0,0,0,0.02));
}

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 700;
    border-radius: 9999px;
    line-height: 1.2;
}
.badge-primary { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: #f1f5f9; color: #475569; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-info { background: #e0f2fe; color: #0369a1; }
.badge-dark { background: #334155; color: #f8fafc; }

.badge-ext {
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.5px;
}

/* Checkerboard for transparent PNG/SVG assets */
.checkerboard-bg {
    background-color: #ffffff;
    background-image: linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
                      linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
                      linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
                      linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

/* Alert Notification */
.alert {
    padding: 12px 16px;
    border-radius: var(--border-radius, 6px);
    margin-bottom: 20px;
}
.alert-success { background: #dcfce7; color: #14532d; border: 1px solid #86efac; }
.alert-danger { background: #fee2e2; color: #7f1d1d; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #78350f; border: 1px solid #fde047; }
.alert-info { background: #e0f2fe; color: #0c4a6e; border: 1px solid #7dd3fc; }
.btn-close-alert {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    opacity: 0.6;
}
.btn-close-alert:hover { opacity: 1; }

/* Mobile Menu Button */
.btn-mobile-menu {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: inherit;
}

/* Mobile Responsiveness */
@media (max-width: 992px) {
    .btn-mobile-menu {
        display: block;
    }
    .app-sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 1000;
        box-shadow: 2px 0 10px rgba(0,0,0,0.15);
    }
    .app-sidebar.show {
        left: 0;
    }
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 999;
    }
    .sidebar-overlay.show {
        display: block;
    }
    .app-content {
        padding: 16px;
    }
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
    .app-topbar {
        padding: 0 16px;
    }
}
