@import url('open-iconic/font/css/open-iconic-bootstrap.min.css');

/* ===== CSS Custom Properties (Variables) ===== */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --info-color: #06b6d4;
    
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #3b82f6;
    --sidebar-text: #cbd5e1;
    --sidebar-text-active: #ffffff;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    
    --header-bg: #ffffff;
    --header-height: 64px;
    --header-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --card-shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    
    --border-radius: 8px;
    --border-radius-lg: 12px;
    --border-radius-sm: 4px;
    
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.35s ease;
}

/* ===== Base Styles ===== */
html, body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background-color: var(--body-bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    min-height: 100vh;
    overflow-x: hidden;
}

/* ===== Typography ===== */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

h1 { font-size: 1.875rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }

/* ===== Links & Buttons ===== */
a, .btn-link {
    color: var(--primary-color);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover, .btn-link:hover {
    color: var(--primary-hover);
}

.btn {
    border-radius: var(--border-radius);
    padding: 0.5rem 1rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    border: none;
}

.btn-primary {
    color: #fff;
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.25);
}

.btn-outline-primary {
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    background: transparent;
}

.btn-outline-primary:hover {
    background-color: var(--primary-color);
    color: white;
}

.btn-success { background-color: var(--success-color); border-color: var(--success-color); }
.btn-warning { background-color: var(--warning-color); border-color: var(--warning-color); }
.btn-danger { background-color: var(--danger-color); border-color: var(--danger-color); }
.btn-info { background-color: var(--info-color); border-color: var(--info-color); }

/* ===== Layout Structure ===== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: width var(--transition-normal);
    overflow-x: hidden;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    min-height: var(--header-height);
}

.sidebar-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    white-space: nowrap;
}

.sidebar-brand-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-nav {
    padding: 1rem 0;
}

.nav-section {
    padding: 0.5rem 1.5rem;
    margin-top: 0.5rem;
}

.nav-section-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.nav-item {
    margin: 0.125rem 0.75rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--sidebar-text);
    border-radius: var(--border-radius);
    transition: all var(--transition-fast);
    text-decoration: none;
    font-weight: 500;
}

.nav-link:hover {
    background-color: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}

.nav-link.active {
    background-color: var(--sidebar-active);
    color: var(--sidebar-text-active);
}

.nav-link i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
}

.nav-link span {
    white-space: nowrap;
}

/* Main Content Area */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition-normal);
}

.sidebar.collapsed + .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

.top-header {
    background: var(--header-bg);
    height: var(--header-height);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--header-shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sidebar-toggle {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: var(--border-radius-sm);
    transition: all var(--transition-fast);
}

.sidebar-toggle:hover {
    background-color: var(--body-bg);
    color: var(--text-primary);
}

.page-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.content-wrapper {
    padding: 1.5rem;
    flex: 1;
    min-height: 0; /* Critical for flex children to shrink */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Page header should not grow */
.content-wrapper > .page-header {
    flex-shrink: 0;
}

/* Card fills remaining space */
.content-wrapper > .card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Card that should NOT expand to fill space */
.content-wrapper > .card.card-auto-height {
    flex: 0 0 auto;
}

.content-wrapper > .card > .card-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Grid fills the card body */
.content-wrapper .e-grid {
    flex: 1;
    min-height: 0;
}

/* ===== Cards ===== */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--card-shadow);
    transition: box-shadow var(--transition-normal);
}

.card:hover {
    box-shadow: var(--card-shadow-hover);
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    font-weight: 600;
    font-size: 1rem;
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    background: var(--body-bg);
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
}

/* ===== Form Elements ===== */
.form-control, .form-select {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.625rem 0.875rem;
    transition: all var(--transition-fast);
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-label {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.375rem;
}

.valid.modified:not([type=checkbox]) {
    outline: none;
    border-color: var(--success-color);
}

.invalid {
    outline: none;
    border-color: var(--danger-color);
}

.validation-message {
    color: var(--danger-color);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* ===== Badges ===== */
.badge {
    padding: 0.35em 0.65em;
    font-weight: 500;
    border-radius: 9999px;
}

.badge.bg-success { background-color: var(--success-color) !important; }
.badge.bg-danger { background-color: var(--danger-color) !important; }
.badge.bg-warning { background-color: var(--warning-color) !important; color: #1e293b !important; }
.badge.bg-info { background-color: var(--info-color) !important; }
.badge.bg-primary { background-color: var(--primary-color) !important; }

/* ===== Stats Cards / Dashboard ===== */
.stats-card {
    padding: 1.5rem;
    border-radius: var(--border-radius-lg);
    background: white;
    border: 1px solid var(--border-color);
    transition: all var(--transition-normal);
}

.stats-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--card-shadow-hover);
}

.stats-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stats-icon.primary { background: var(--primary-light); color: var(--primary-color); }
.stats-icon.success { background: #d1fae5; color: var(--success-color); }
.stats-icon.warning { background: #fef3c7; color: var(--warning-color); }
.stats-icon.danger { background: #fee2e2; color: var(--danger-color); }

.stats-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0.5rem 0 0.25rem;
}

.stats-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ===== Login Display ===== */
.login-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.login-display a, .login-display form .btn {
    color: var(--text-secondary);
    font-size: 1.25rem;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    transition: all var(--transition-fast);
}

.login-display a:hover, .login-display form .btn:hover {
    color: var(--primary-color);
    background-color: var(--primary-light);
}

/* ===== Error UI ===== */
#blazor-error-ui {
    background: #fef2f2;
    border-top: 2px solid var(--danger-color);
    bottom: 0;
    display: none;
    left: 0;
    padding: 1rem 1.5rem;
    position: fixed;
    width: 100%;
    z-index: 2000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 1.25rem;
}

/* ===== Dialog / Modal ===== */
.dialog-container {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    animation: dialog-container-entry 0.2s ease-out;
}

@keyframes dialog-container-entry {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

.dialog {
    background-color: white;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    z-index: 2000;
    align-self: center;
    margin: auto;
    width: 700px;
    max-width: 90vw;
    max-height: calc(100% - 3rem);
    border-radius: var(--border-radius-lg);
    animation: dialog-entry 0.3s ease-out;
}

@keyframes dialog-entry {
    0% {
        transform: translateY(20px) scale(0.98);
        opacity: 0;
    }
    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.dialog-title {
    background: linear-gradient(135deg, var(--sidebar-bg), #334155);
    color: white;
    padding: 1.25rem 1.5rem;
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
}

.dialog-title h2 {
    color: white;
    font-size: 1.25rem;
    margin: 0;
    font-weight: 600;
}

.dialog-body {
    flex-grow: 1;
    padding: 1.5rem;
    overflow-y: auto;
}

.dialog-buttons {
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    background-color: var(--body-bg);
    border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
    border-top: 1px solid var(--border-color);
}

.dialog-body > div {
    display: flex;
    margin-top: 1rem;
    align-items: center;
}

.dialog-body label {
    text-align: right;
    width: 200px;
    margin: 0 1.5rem;
    color: var(--text-secondary);
}

.dialog-body input, .dialog-body select {
    flex-grow: 1;
    width: unset;
}

/* ===== Page Headers ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    margin: 0;
    font-size: 1.5rem;
}

.page-header-actions {
    display: flex;
    gap: 0.75rem;
}

/* ===== Tables ===== */
.table {
    margin-bottom: 0;
}

.table th {
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom-width: 1px;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.table td {
    padding: 0.875rem 1rem;
    vertical-align: middle;
}

.table tbody tr {
    transition: background-color var(--transition-fast);
}

.table tbody tr:hover {
    background-color: var(--body-bg);
}

/* ===== Loading States ===== */
.loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* ===== Empty States ===== */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

/* ===== Alerts ===== */
.alert {
    border-radius: var(--border-radius);
    border: none;
    padding: 0.875rem 1rem;
}

.alert-success { background-color: #d1fae5; color: #065f46; }
.alert-warning { background-color: #fef3c7; color: #92400e; }
.alert-danger { background-color: #fee2e2; color: #991b1b; }
.alert-info { background-color: #e0f2fe; color: #075985; }

/* ===== Responsive ===== */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
    }
    
    .sidebar.show {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
    }
    
    .sidebar-overlay.show {
        display: block;
    }
}

@media (max-width: 575.98px) {
    .content-wrapper {
        padding: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
}

/* ===== Utility Classes ===== */
.text-primary { color: var(--primary-color) !important; }
.text-success { color: var(--success-color) !important; }
.text-warning { color: var(--warning-color) !important; }
.text-danger { color: var(--danger-color) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }

.bg-primary-light { background-color: var(--primary-light) !important; }
.bg-success-light { background-color: #d1fae5 !important; }
.bg-warning-light { background-color: #fef3c7 !important; }
.bg-danger-light { background-color: #fee2e2 !important; }

.rounded-lg { border-radius: var(--border-radius-lg) !important; }
.shadow-sm { box-shadow: var(--card-shadow) !important; }
.shadow-md { box-shadow: var(--card-shadow-hover) !important; }

/* ===== Quick Actions Grid ===== */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.quick-action-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    text-decoration: none;
    color: var(--text-primary);
    transition: all var(--transition-normal);
}

.quick-action-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--card-shadow-hover);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.quick-action-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
    background: var(--body-bg);
    transition: all var(--transition-normal);
}

.quick-action-card:hover .quick-action-icon {
    background: var(--primary-light);
    color: var(--primary-color);
}

.quick-action-label {
    font-weight: 500;
    text-align: center;
}

/* ===== Grid Container Fixes ===== */
/* Grid styling */
.card .e-grid {
    border: none;
}

.e-grid .e-gridcontent {
    overflow: auto;
}