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

/* Reset */
html, body {
    margin: 0 !important;
    padding: 0 !important;
    font-family: var(--font-sans);
    min-height: 100vh;
    width: 100%;
    overflow-x: hidden;
}

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

/* 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 var(--m-success);
}

.invalid {
    outline: 1px solid var(--m-danger);
}

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

    /* The close button is a real button: it takes the look of the bar's text. */
    #blazor-error-ui button.dismiss {
        padding: 0.25rem;
        border: 0;
        background: none;
        font: inherit;
        line-height: 1;
    }

/* 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 - brand green */
.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: var(--m-bg-tertiary);
        stroke-width: 0.6rem;
        transform-origin: 50% 50%;
        transform: rotate(-90deg);
    }

        .loading-progress circle:last-child {
            stroke: var(--m-primary);
            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: var(--m-primary);
}

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

code {
    color: var(--m-primary);
    background: var(--m-bg-tertiary);
    padding: 0.125rem 0.375rem;
    border-radius: var(--m-radius-sm);
    font-family: var(--font-mono);
    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;
}

* {
    box-sizing: border-box;
}

/* Page containers */
.page-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 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: var(--m-spacing-3) !important;
    align-items: center !important;
    padding: var(--m-spacing-4) var(--m-spacing-5) !important;
    border-bottom: 1px solid var(--m-border) !important;
}

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

/* Search input wrapper can be full width within its parent */
.material-table-toolbar > *:first-child .m-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;
}

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

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

/* Combo boxes in the toolbar (MaterialCombobox renders .m-combobox as a direct child) */
.material-table-toolbar > .m-combobox,
.material-table-toolbar > .material-combobox {
    width: auto !important;
    min-width: 180px !important;
    max-width: 220px !important;
}

/* ================================================
   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: var(--m-spacing-2) !important;
    flex: 0 0 auto !important;
    margin-left: auto !important;
}

.toolbar-sep {
    width: 1px;
    height: 24px;
    background: var(--m-border);
    flex-shrink: 0;
    margin: 0 var(--m-spacing-1);
}

/* 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 .m-select-wrapper,
    .material-table-toolbar > .m-combobox,
    .material-table-toolbar > .material-combobox {
        max-width: 100% !important;
        width: 100% !important;
        min-width: 0 !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: var(--m-font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--m-text-secondary);
    border-bottom: 1px solid var(--m-border);
    white-space: nowrap;
}

table.table tbody td {
    padding: 0.75rem 1rem;
    font-size: var(--m-font-size-sm);
    color: var(--m-text-primary);
    border-bottom: 1px solid var(--m-border);
    vertical-align: middle;
}

table.table tbody tr:hover {
    background: var(--m-bg-hover);
}

/* Text utilities (.text-muted, .text-danger and .font-semibold live in emerald-theme.css) */
.text-end { text-align: right; }
.text-center { text-align: center; }
.text-sm { font-size: var(--m-font-size-xs); }

/* 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 itself lives in emerald-theme.css) */
.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 .m-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 .m-input,
.input-group .m-input-base {
    flex: 1;
    min-width: 0;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: 0 var(--m-spacing-3);
    background: var(--m-bg-tertiary);
    border: 1px solid var(--m-border-strong);
    border-left: 0;
    border-radius: 0 var(--m-radius-md) var(--m-radius-md) 0;
    font-size: var(--m-font-size-sm);
    font-weight: var(--m-font-weight-semibold);
    color: var(--m-text-secondary);
}

/* Image placeholder */
.img-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--m-bg-tertiary);
    border-radius: var(--m-radius-md);
}

/* Loading and empty states (.loading-center, .empty-state) live in emerald-theme.css */

/* 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: var(--m-bg-primary);
    border-radius: var(--m-radius-xl);
    padding: var(--m-spacing-5);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stat-card .stat-value {
    font-size: var(--m-font-size-2xl);
    font-weight: var(--m-font-weight-semibold);
    font-variant-numeric: tabular-nums;
    color: var(--m-text-primary);
}

.stat-card .stat-label {
    font-size: var(--m-font-size-sm);
    font-weight: var(--m-font-weight-semibold);
    color: var(--m-text-secondary);
}

/* Category cards */
.category-card {
    background: var(--m-bg-primary);
    border-radius: var(--m-radius-xl);
    overflow: hidden;
    transition: box-shadow var(--m-transition-base);
}

.category-card:hover {
    box-shadow: var(--m-shadow-md);
}

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

.category-card-image {
    height: 150px;
    background: var(--m-bg-secondary);
    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 var(--m-border);
    background: var(--m-bg-secondary);
}

/* 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: var(--m-font-size-lg);
    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: var(--m-font-size-sm);
    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: var(--m-bg-primary);
    color: var(--m-text-primary);
    border: 1px solid var(--m-border);
    border-radius: var(--m-radius-lg);
    box-shadow: var(--m-shadow-lg);
    min-width: 220px;
    padding: 6px;
    animation: fadeIn 0.1s ease;
}

.ctx-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: 40px;
    padding: 0 var(--m-spacing-3);
    background: transparent;
    border: 0;
    border-radius: var(--m-radius-md);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--m-font-size-sm);
    font-weight: var(--m-font-weight-medium);
    color: var(--m-text-primary);
    text-align: left;
    transition: background-color var(--m-transition-fast);
}

.ctx-menu-item .m-icon {
    color: var(--m-text-secondary);
}

.ctx-menu-item:hover {
    background: var(--m-bg-hover);
}

.ctx-menu-item:focus-visible {
    outline: 2px solid transparent;
    box-shadow: inset 0 0 0 2px var(--m-border-focus);
}

.ctx-menu-item--danger {
    color: var(--m-danger-text);
}

.ctx-menu-item--danger .m-icon {
    color: inherit;
}

.ctx-menu-item--danger:hover {
    background: var(--m-danger-light);
}

.ctx-menu-separator {
    height: 1px;
    margin: 6px 4px;
    background: var(--m-border);
}
