/* ==========================================
   KONTROL APP BASE STYLES
   ========================================== */

/* Reset */
html, body {
    margin: 0 !important;
    padding: 0 !important;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    min-height: 100vh;
    width: 100%;
    overflow-x: hidden;
}

/* Light mode default */
html:not(.dark) body {
    background-color: #F9FAFB !important;
    color: #111827 !important;
}

/* Dark mode */
html.dark body {
    background-color: #0F172A !important;
    color: #F8FAFC !important;
}

#app {
    min-height: 100vh;
}

/* ==========================================
   TEXT SELECTION & FOCUS STYLING
   ========================================== */

/* Disable text selection on UI elements (not on content areas) */
h1, h2, h3, h4, h5, h6,
nav, aside, header, footer,
button, .button, .btn,
.sidebar, .navbar, .menu,
.card-header, .card-footer,
label:not(.form-check-label) {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Allow selection on content areas */
p, article, .content, .body-text,
input, textarea, [contenteditable="true"] {
    user-select: text;
    -webkit-user-select: text;
}

/* Remove focus outline from non-interactive elements */
h1, h2, h3, h4, h5, h6,
p, span, div, section, article,
img, svg {
    outline: none !important;
}

/* Ensure no focus styles on headings */
h1:focus, h2:focus, h3:focus, 
h4:focus, h5:focus, h6:focus {
    outline: none !important;
    box-shadow: none !important;
}

/* Keep focus visible for interactive elements (accessibility) */
/*a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid #10B981 !important;
    outline-offset: 2px;
}*/

/* Remove default focus outline but keep focus-visible for keyboard navigation */
a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
input:focus:not(:focus-visible) {
    outline: none;
}

/* Custom text selection color (optional, matches Emerald theme) */
::selection {
    background-color: rgba(16, 185, 129, 0.3);
    color: #064E3B;
}

::-moz-selection {
    background-color: rgba(16, 185, 129, 0.3);
    color: #064E3B;
}

/* Prevent outline on active/focused state for UI containers */
.dashboard-page:focus,
.login-container:focus,
.material-card:focus {
    outline: none !important;
}

/* Form validation */

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid red;
}

.validation-message {
    color: red;
}

/* Blazor error UI - light theme */
#blazor-error-ui {
    color-scheme: light only;
    background: #FEF3C7 !important;  /* Light yellow */
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: #78350F !important;  /* Dark yellow text */
}

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        right: 0.75rem;
        top: 0.5rem;
        color: #78350F !important;
    }

/* Error boundary - emerald theme */
.blazor-error-boundary {
    background: linear-gradient(135deg, #FEE2E2 0%, #FECACA 100%);
    padding: 1rem 1rem 1rem 3.7rem;
    color: #991B1B !important;
    border-left: 4px solid #DC2626;
    border-radius: 0.5rem;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }

/* Loading progress - emerald color */
.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto 0 auto;
}

    .loading-progress circle {
        fill: none;
        stroke: #E5E7EB;  /* Light gray */
        stroke-width: 0.6rem;
        transform-origin: 50% 50%;
        transform: rotate(-90deg);
    }

        .loading-progress circle:last-child {
            stroke: #10B981 !important;  /* Emerald green */
            stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
            transition: stroke-dasharray 0.05s ease-in-out;
        }

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
    color: #10B981 !important;  /* Emerald text */
}

    .loading-progress-text:after {
        content: var(--blazor-load-percentage-text, "Loading");
    }

code {
    color: #10B981;  /* Emerald for inline code */
    background: #F3F4F6;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
}

/* Form floating labels */
.form-floating > .form-control-plaintext::placeholder, 
.form-floating > .form-control::placeholder {
    color: #6B7280;  /* Medium gray */
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, 
.form-floating > .form-control:focus::placeholder {
    text-align: start;
}

/* Remove any potential dark backgrounds */
* {
    box-sizing: border-box;
}
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar-header {
    padding: 2rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-text h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    margin: 0;
    line-height: 1.2;
}

.logo-text p {
    font-size: 0.7rem;
    color: var(--sidebar-text);
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* User info */
.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10B981 0%, #34D399 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #e2e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.7rem;
    color: var(--sidebar-text);
}

/* Side navigation */
.side-nav {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
}

.side-nav-section {
    padding: 1.25rem 1.25rem 0.5rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #64748b;
}

.side-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.85rem;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.side-nav-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: #e2e8f0;
}

.side-nav-item.active {
    background: rgba(16, 185, 129, 0.15);
    color: #fff;
    border-left-color: var(--sidebar-active);
}

/* Sidebar footer */
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    margin-top: auto;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.6rem 0;
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 0.85rem;
    transition: color 0.15s;
}

.logout-btn:hover {
    color: #ef4444;
}

/* Main content */
main {
    flex: 1;
    margin-left: var(--sidebar-width);
    background: #F9FAFB;
    min-height: 100vh;
}

.content {
    padding: var(--content-padding);
}

/* Page containers */
.page-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 0.5rem;
}

.page-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
}

.page-header p {
    font-size: 0.85rem;
    color: #64748b;
    margin: 0.25rem 0 0;
}

/* Filter grids */
.filter-grid {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filter-grid > * {
    min-width: 180px;
}

/* ================================================
   MaterialTable Toolbar Override for Kontrol
   Force horizontal layout for all child components
   ================================================ */
.material-table-toolbar {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    gap: 0.75rem !important;
    align-items: center !important;
    padding: 1rem 1.25rem !important;
    background: #f8fafc !important;
    border-bottom: 1px solid #e2e8f0 !important;
}

/* First child (search) - flexible width */
.material-table-toolbar > *:first-child {
    flex: 1 1 200px !important;
    min-width: 200px !important;
    max-width: 400px !important;
    width: auto !important;
}

/* Search input wrapper can be full width within its parent */
.material-table-toolbar > *:first-child .flux-search-input {
    width: 100% !important;
}

/* All other children - fixed width, no grow */
.material-table-toolbar > *:not(:first-child) {
    flex: 0 0 auto !important;
    width: auto !important;
}

/* FluxSelect wrapper - CRITICAL: override width: 100% */
.material-table-toolbar > *:not(:first-child) .flux-select-wrapper,
.material-table-toolbar .flux-select-wrapper:not(:first-child) {
    width: auto !important;
    min-width: 140px !important;
    max-width: 180px !important;
}

/* Direct child selects (MaterialSelect renders FluxSelect) */
.material-table-toolbar > .flux-select-wrapper,
.material-table-toolbar > .material-select .flux-select-wrapper {
    width: auto !important;
    min-width: 140px !important;
    max-width: 180px !important;
}

/* MaterialTable Wrapper */
.material-table-wrapper {
    background: #ffffff !important;
    border-radius: 0.5rem;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.material-table-pagination {
    padding: 0.75rem 1rem;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
}

/* ================================================
   Toolbar Action Buttons (Add / Edit / Delete)
   Pushed to the right end of the toolbar
   ================================================ */
.toolbar-spacer {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: none !important;
}

.toolbar-actions {
    display: flex !important;
    align-items: center !important;
    gap: 0.375rem !important;
    flex: 0 0 auto !important;
    margin-left: auto !important;
}

.toolbar-sep {
    width: 1px;
    height: 24px;
    background: #e2e8f0;
    flex-shrink: 0;
    margin: 0 0.25rem;
}

/* Responsive - stack on mobile */
@media (max-width: 640px) {
    .material-table-toolbar {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    
    .material-table-toolbar > *,
    .material-table-toolbar > *:first-child,
    .material-table-toolbar > *:not(:first-child),
    .material-table-toolbar .flux-select-wrapper {
        max-width: 100% !important;
        width: 100% !important;
        flex: 1 1 100% !important;
    }
}

/* Tables */
.table-container {
    overflow-x: auto;
}

table.table {
    width: 100%;
    border-collapse: collapse;
}

table.table thead th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
}

table.table tbody td {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    color: #334155;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

table.table tbody tr:hover {
    background: #f8fafc;
}

/* Text utilities */
.text-end { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: #64748b; }
.text-sm { font-size: 0.8rem; }
.text-danger { color: #ef4444; }
.font-semibold { font-weight: 600; }

/* Spacing */
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mt-4 { margin-top: 1rem; }
.py-5 { padding-top: 3rem; padding-bottom: 3rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.gap-4 { gap: 1rem; }

/* Layout helpers */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

.grid { display: grid; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

/* Form rows */
.form-row {
    display: grid;
    gap: 0.75rem;
}

.form-row-2 { grid-template-columns: repeat(2, 1fr); }
.form-row-3 { grid-template-columns: repeat(3, 1fr); }

.manufacturer-lookup-modal {
    height: 70vh;
    min-height: 520px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

.manufacturer-lookup-table {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.manufacturer-lookup-table .material-table-wrapper {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.manufacturer-lookup-table .flux-table-wrapper {
    flex: 1;
    overflow: auto;
}

.manufacturer-lookup-table .material-table-pagination {
    margin-top: auto;
}

/* Input groups */
.input-group {
    display: flex;
    align-items: stretch;
}

.input-group input,
.input-group .flux-input {
    flex: 1;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    background: #f1f5f9;
    border: 1px solid #d1d5db;
    border-left: 0;
    border-radius: 0 var(--flux-radius, 6px) var(--flux-radius, 6px) 0;
    font-size: 0.8rem;
    color: #64748b;
}

/* Buttons */
.btn-group {
    display: flex;
    gap: 0.25rem;
}

.btn-sm {
    padding: 0.25rem 0.5rem !important;
    font-size: 0.8rem !important;
}

/* Image placeholder */
.img-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    border-radius: var(--flux-radius, 6px);
}

/* Loading / Empty states */
.loading-center {
    display: flex;
    justify-content: center;
    padding: 3rem;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 3rem;
    text-align: center;
    color: #64748b;
}

/* Pagination */
.pagination-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
}

.pagination {
    display: flex;
    gap: 0.25rem;
}

.pagination-btn {
    min-width: 36px;
}

/* Stats cards (Dashboard) */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: #fff;
    border-radius: 8px;
    padding: 1.25rem;
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #1e293b;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Login page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #064E3B 0%, #0F172A 100%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.login-card h2 {
    text-align: center;
    margin-bottom: 0.5rem;
    color: #1e293b;
}

.login-card p {
    text-align: center;
    color: #64748b;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

/* Category cards */
.category-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.category-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.category-card.inactive {
    opacity: 0.6;
}

.category-card-image {
    height: 150px;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.category-card-image img {
    max-width: 150px;
    max-height: 130px;
    width: auto;
    height: auto;
    object-fit: contain;
}

.category-card-body {
    padding: 1rem;
}

.category-card-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
}

/* Modal */
.kontrol-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.15s ease;
}

.kontrol-modal {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.2s ease;
}

.kontrol-modal.modal-small { width: 400px; }
.kontrol-modal.modal-medium { width: 600px; }
.kontrol-modal.modal-large { width: 900px; }

.kontrol-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.kontrol-modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0;
}

.kontrol-modal-close {
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: #94a3b8;
    border-radius: 4px;
    display: flex;
}

.kontrol-modal-close:hover {
    background: #f1f5f9;
    color: #64748b;
}

.kontrol-modal-body {
    padding: 1.5rem;
}

.kontrol-modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid #e2e8f0;
}

/* Confirm dialog */
.confirm-dialog-message {
    font-size: 0.95rem;
    color: #475569;
    line-height: 1.6;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Error UI */
#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* Order detail */
.order-info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.order-status-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ==========================================
   THEME TOGGLE BUTTON
   ========================================== */
.theme-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 0.5rem;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

.theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.theme-toggle-btn:active {
    transform: scale(0.95);
}

/* Dark mode button adjustments */
html.dark .theme-toggle-btn {
    background: rgba(16, 185, 129, 0.1);
}

html.dark .theme-toggle-btn:hover {
    background: rgba(16, 185, 129, 0.2);
}

/* ==========================================
   CONTEXT MENU (row right-click)
   ========================================== */
.ctx-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9998;
}

.ctx-menu {
    position: fixed;
    z-index: 9999;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    min-width: 160px;
    padding: 4px 0;
    animation: fadeIn 0.1s ease;
}

.ctx-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 16px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    color: #374151;
    text-align: left;
    transition: background 0.15s;
}

.ctx-menu-item:hover {
    background: #f3f4f6;
}

.ctx-menu-item--danger:hover {
    background: #fef2f2;
    color: #dc2626;
}

html.dark .ctx-menu {
    background: #1e293b;
    border-color: #334155;
}

html.dark .ctx-menu-item {
    color: #e2e8f0;
}

html.dark .ctx-menu-item:hover {
    background: #334155;
}

html.dark .ctx-menu-item--danger:hover {
    background: rgba(220, 38, 38, 0.15);
    color: #f87171;
}
