/* =====================================================
   Platform.Core - Base Design System
   Neutral defaults - apps override via theme CSS
   ===================================================== */

:root {
    /* Primary - App overrides these */
    --platform-primary: #3b82f6;
    --platform-primary-dark: #2563eb;
    --platform-primary-light: #60a5fa;
    --platform-primary-rgb: 59, 130, 246;

    /* Secondary */
    --platform-secondary: #8b5cf6;
    --platform-secondary-dark: #7c3aed;
    --platform-secondary-light: #a78bfa;

    /* Accent */
    --platform-accent: #f59e0b;
    --platform-accent-dark: #d97706;
    --platform-accent-light: #fbbf24;
    --platform-accent-rgb: 245, 158, 11;

    /* Sidebar - App overrides */
    --sidebar-bg: linear-gradient(180deg, #1e293b 0%, #334155 100%);
    --sidebar-header-bg: rgba(0, 0, 0, 0.1);
    --sidebar-text: rgba(255, 255, 255, 0.8);
    --sidebar-text-muted: rgba(255, 255, 255, 0.5);
    --sidebar-hover-bg: rgba(255, 255, 255, 0.1);
    --sidebar-active-bg: var(--platform-accent);
    --sidebar-active-shadow: rgba(var(--platform-accent-rgb), 0.35);
    --sidebar-border: rgba(255, 255, 255, 0.1);
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 80px;

    /* Fixed - Don't override */
    --platform-background: #ffffff;
    --platform-background-alt: #f8fafc;
    --platform-text: #1e293b;
    --platform-text-muted: #64748b;
    --platform-border: #e2e8f0;
    --platform-border-light: #f1f5f9;

    /* Status colors - Fixed */
    --platform-success: #22c55e;
    --platform-success-light: #dcfce7;
    --platform-warning: #f59e0b;
    --platform-warning-light: #fef3c7;
    --platform-error: #ef4444;
    --platform-error-light: #fee2e2;
    --platform-info: #3b82f6;
    --platform-info-light: #dbeafe;
}

/* =====================================================
   BASE STYLES
   ===================================================== */

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--platform-text);
    background: var(--platform-background);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-weight: 600;
    color: var(--platform-text);
    line-height: 1.3;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }

p { margin: 0 0 1rem; }

a {
    color: var(--platform-primary);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--platform-primary-dark);
}

/* =====================================================
   APP SHELL LAYOUT
   ===================================================== */

.app-shell {
    display: flex;
    min-height: 100vh;
}

/* =====================================================
   SIDEBAR
   ===================================================== */

.platform-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.platform-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.platform-sidebar .sidebar-header {
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--sidebar-border);
    min-height: 70px;
}

.platform-sidebar .logo-full {
    max-height: 45px;
    max-width: 180px;
    object-fit: contain;
}

.platform-sidebar .logo-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.platform-sidebar .sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.platform-sidebar .nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.platform-sidebar .sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--sidebar-border);
}

.platform-sidebar .collapse-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.85rem;
}

.platform-sidebar .collapse-btn:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text);
}

.platform-sidebar .collapse-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.platform-sidebar .collapse-icon.rotated {
    transform: rotate(180deg);
}

.platform-sidebar.collapsed .collapse-text {
    display: none;
}

.platform-sidebar.collapsed .collapse-btn {
    justify-content: center;
}

/* Sidebar collapsed state */
.app-shell.sidebar-collapsed .platform-sidebar {
    width: var(--sidebar-collapsed-width);
}

.app-shell.sidebar-collapsed .platform-sidebar .sidebar-header {
    padding: 1rem 0.5rem;
}

.app-shell.sidebar-collapsed .platform-sidebar .collapse-text {
    display: none;
}

.app-shell.sidebar-collapsed .platform-sidebar .collapse-btn {
    justify-content: center;
}

.app-shell.sidebar-collapsed .app-main {
    margin-left: var(--sidebar-collapsed-width);
}

/* =====================================================
   SIDEBAR ITEMS
   ===================================================== */

.sidebar-section {
    padding: 0 0.75rem;
    margin-bottom: 0.5rem;
}

.sidebar-section-title {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-text-muted);
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.25rem;
}

.sidebar-section-divider {
    height: 1px;
    background: var(--sidebar-border);
    margin: 0.75rem 0;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.15s ease;
    position: relative;
}

.sidebar-item:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text);
}

.sidebar-item.active {
    background: var(--sidebar-active-bg);
    color: white;
    box-shadow: 0 2px 8px var(--sidebar-active-shadow);
}

.sidebar-item-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-item-icon svg {
    width: 20px;
    height: 20px;
}

.sidebar-item-label {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Collapsed sidebar - hide labels, show tooltips */
.app-shell.sidebar-collapsed .sidebar-section-title {
    display: none;
}

.app-shell.sidebar-collapsed .sidebar-item {
    justify-content: center;
    padding: 0.6rem;
}

.app-shell.sidebar-collapsed .sidebar-item-label {
    display: none;
}

.app-shell.sidebar-collapsed .sidebar-item::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 10px);
    background: var(--platform-text);
    color: white;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 1000;
}

.app-shell.sidebar-collapsed .sidebar-item:hover::after {
    opacity: 1;
}

/* Mobile sidebar */
@media (max-width: 767.98px) {
    .platform-sidebar {
        width: var(--sidebar-width) !important;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .platform-sidebar.mobile-open {
        transform: translateX(0);
    }

    .mobile-nav-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .mobile-nav-backdrop.active {
        opacity: 1;
        pointer-events: auto;
    }
}

/* =====================================================
   MOBILE HEADER
   ===================================================== */

.mobile-header {
    display: none;
}

@media (max-width: 767.98px) {
    .mobile-header {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: var(--platform-background);
        border-bottom: 1px solid var(--platform-border);
        z-index: 98;
        align-items: center;
        justify-content: space-between;
        padding: 0 1rem;
    }

    .mobile-header .hamburger-btn {
        width: 44px;
        height: 44px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 5px;
        background: transparent;
        border: none;
        cursor: pointer;
        padding: 0;
    }

    .mobile-header .hamburger-line {
        display: block;
        width: 22px;
        height: 2px;
        background: var(--platform-text);
        transition: all 0.3s ease;
    }

    .mobile-header .hamburger-btn.open .hamburger-line:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }
    .mobile-header .hamburger-btn.open .hamburger-line:nth-child(2) {
        opacity: 0;
    }
    .mobile-header .hamburger-btn.open .hamburger-line:nth-child(3) {
        transform: rotate(-45deg) translate(5px, -5px);
    }

    .mobile-header .mobile-logo {
        height: 36px;
    }
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    background: var(--platform-background-alt);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-content {
    padding: 1.5rem;
}

/* Mobile */
@media (max-width: 767.98px) {
    .app-shell {
        flex-direction: column;
    }

    .app-main {
        margin-left: 0 !important;
        padding-top: 60px;
    }

    .app-content {
        padding: 1rem;
    }
}

/* =====================================================
   BUTTONS
   ===================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    text-decoration: none;
    line-height: 1.5;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.85rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }

.btn-primary {
    background: var(--platform-primary);
    color: white;
}
.btn-primary:hover:not(:disabled) {
    background: var(--platform-primary-dark);
}

.btn-secondary {
    background: white;
    color: var(--platform-text);
    border: 1px solid var(--platform-border);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--platform-background-alt);
    border-color: var(--platform-primary-light);
}

.btn-accent {
    background: var(--platform-accent);
    color: white;
}
.btn-accent:hover:not(:disabled) {
    background: var(--platform-accent-dark);
}

.btn-ghost {
    background: transparent;
    color: var(--platform-text-muted);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--platform-background-alt);
    color: var(--platform-text);
}

.btn-danger {
    background: var(--platform-error);
    color: white;
}
.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn-icon {
    padding: 0.5rem;
    width: 36px;
    height: 36px;
}

/* =====================================================
   CARDS
   ===================================================== */

.card {
    background: white;
    border: 1px solid var(--platform-border);
    border-radius: 12px;
    padding: 1.5rem;
    transition: box-shadow 0.15s ease;
}

.card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--platform-border-light);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

/* =====================================================
   FORMS
   ===================================================== */

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--platform-text);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--platform-border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    background: white;
    color: var(--platform-text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--platform-primary);
    box-shadow: 0 0 0 3px rgba(var(--platform-primary-rgb), 0.15);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--platform-text-muted);
    opacity: 0.7;
}

/* =====================================================
   TABLES
   ===================================================== */

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--platform-border-light);
}

.table th {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--platform-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--platform-background-alt);
}

.table tbody tr:hover {
    background: var(--platform-background-alt);
}

/* =====================================================
   BADGES
   ===================================================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.badge-primary {
    background: rgba(var(--platform-primary-rgb), 0.15);
    color: var(--platform-primary);
}

.badge-success {
    background: var(--platform-success-light);
    color: #166534;
}

.badge-warning {
    background: var(--platform-warning-light);
    color: #92400e;
}

.badge-error {
    background: var(--platform-error-light);
    color: #991b1b;
}

/* =====================================================
   MODALS
   ===================================================== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.15s ease;
}

.modal {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: auto;
    animation: slideUp 0.2s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--platform-border-light);
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--platform-border-light);
}

/* =====================================================
   UTILITIES
   ===================================================== */

.text-muted { color: var(--platform-text-muted); }
.text-primary { color: var(--platform-primary); }
.text-success { color: var(--platform-success); }
.text-warning { color: var(--platform-warning); }
.text-error { color: var(--platform-error); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.text-center { text-align: center; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.flex-1 { flex: 1; }

.hidden { display: none; }
.w-full { width: 100%; }

/* =====================================================
   ANIMATIONS
   ===================================================== */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* =====================================================
   SCROLLBAR
   ===================================================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--platform-background-alt);
}

::-webkit-scrollbar-thumb {
    background: var(--platform-border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--platform-text-muted);
}

/* =====================================================
   BLAZOR
   ===================================================== */

h1:focus { outline: none; }

.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--platform-success);
}

.invalid {
    outline: 1px solid var(--platform-error);
}

.validation-message {
    color: var(--platform-error);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

#blazor-error-ui {
    background: var(--platform-warning-light);
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: #92400e;
}
