:root {
    --bulma-primary-h: 0;
    --bulma-primary-s: 0%;
    --bulma-primary-l: 96%;
}

.navbar {
    --bulma-navbar-background-color: var(--bulma-primary);
}

/* ===========================================
   Navbar z-index and stacking - using custom classes
   =========================================== */

/* System navbar (py4web) - must be above modules navbar */
.navbar-system {
    position: relative;
    z-index: 1000;
}

.navbar-system .navbar-item.has-dropdown {
    position: relative;
    z-index: 1001;
}

.navbar-system .navbar-dropdown {
    z-index: 1002;
}

/* Modules navbar (web2py) - lower z-index so system dropdowns appear above */
.navbar-modules {
    position: relative;
    z-index: 1;
    min-height: 2.5rem;
}

/* Navbar logo styling */
.navbar-logo {
    font-size: larger;
    font-weight: bold;
}

/* ===========================================
   Navbar styling - colors and appearance
   =========================================== */

/* Primary navbar (light gray with dark text) */
.navbar.is-primary {
    background-color: #f5f5f5;
    color: #4a4a4a;
}

.navbar.is-primary .navbar-item,
.navbar.is-primary .navbar-link {
    color: #4a4a4a;
}

.navbar.is-primary .navbar-item:hover,
.navbar.is-primary .navbar-link:hover {
    color: #0a0a0a;
    background-color: #e8e8e8;
}

.navbar.is-primary .navbar-dropdown {
    background-color: #fff;
    border-top: 1px solid #dbdbdb;
}

.navbar.is-primary .navbar-dropdown .navbar-item {
    color: #4a4a4a;
    background-color: #fff;
}

.navbar.is-primary .navbar-dropdown .navbar-item:hover {
    background-color: #f5f5f5;
    color: #0a0a0a;
}

/* Light navbar (gray - for web2py modules) */
.navbar.is-light {
    background-color: #f5f5f5;
    color: rgba(0, 0, 0, 0.7);
}

.navbar.is-light .navbar-dropdown {
    background-color: #fff;
    border-top: 1px solid #dbdbdb;
}

.navbar.is-light .navbar-dropdown .navbar-item {
    color: #4a4a4a;
    background-color: #fff;
}

.navbar.is-light .navbar-dropdown .navbar-item:hover {
    background-color: #f5f5f5;
    color: #0a0a0a;
}

/* ===========================================
   Layout - reduce side margins for more space
   =========================================== */

.section {
    padding: 1rem 0.75rem;
}

.container {
    max-width: none !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 0.5rem !important;
}

/* ===========================================
   Grid/Table styling - compact, no borders
   =========================================== */

.table {
    --bulma-table-cell-border-style: none;
    --bulma-table-cell-border-width: 0;
    --bulma-table-cell-padding: 0.25em 0.5em;
    border-collapse: collapse;
    width: 100%;
}

/* Grid wrapper and content should be full width */
.content {
    width: 100%;
    max-width: none;
}

div.grid-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
}

.grid-table-wrapper,
.table-container {
    width: 100%;
    max-width: none;
    overflow-x: auto;
    display: block;
}

div.grid-wrapper table,
.table.is-fullwidth,
.grid-table {
    width: 100% !important;
    min-width: 100% !important;
}

/* Action buttons column - fixed narrow width */
div.grid-wrapper table th:last-child,
div.grid-wrapper table td:last-child {
    width: 1%;
    white-space: nowrap;
}

/* Remove all table borders */
.table,
.table th,
.table td,
.table thead,
.table tbody,
.table tr {
    border: none !important;
    border-width: 0 !important;
}

/* Compact table cells */
div.grid-wrapper .table td {
    vertical-align: middle;
    padding: 0.15em 0.5em;
    font-size: 15px;
    line-height: 1.2;
}

/* Compact column headers */
div.grid-wrapper .table th {
    background-color: #f5f5f5;
    padding: 0.25em 0.5em;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    border: none !important;
}

div.grid-wrapper .table th a {
    color: var(--bulma-table-head-cell-color);
}

/* Subtle row hover effect */
div.grid-wrapper .table tbody tr:hover {
    background-color: #fafafa;
}

/* Alternating row colors for readability */
div.grid-wrapper .table tbody tr:nth-child(even) {
    background-color: #fcfcfc;
}

/* Grid action buttons - more compact */
div.grid-wrapper .table td .button {
    padding: 0.15em 0.4em;
    font-size: 12px;
    height: auto;
}

/* Search and pagination controls - more compact */
div.grid-wrapper .field {
    margin-bottom: 0.5rem;
}

div.grid-wrapper .pagination {
    margin-top: 0.5rem;
}

a.white {
    color: var(--bulma-text-weak);
    padding: 1em;
    position: absolute;
}

/* ===========================================
   Page titles - smaller size
   =========================================== */

h1.title {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

h2.subtitle {
    font-size: 1rem;
    margin-top: 0;
}

/* ===========================================
   Horizontal Form styling
   =========================================== */

/* Horizontal form field label - fixed width for alignment */
.field.is-horizontal .field-label {
    flex-basis: 120px;
    flex-grow: 0;
    flex-shrink: 0;
    margin-right: 0.5rem;
    text-align: right;
}

.field.is-horizontal .field-label .label {
    font-size: 1rem;
}

/* Field body takes remaining space */
.field.is-horizontal .field-body {
    flex-grow: 1;
    flex-shrink: 1;
}

/* Compact spacing between horizontal fields */
.field.is-horizontal {
    margin-bottom: 0.5rem;
}

/* Ensure inputs fill available width */
.field.is-horizontal .field-body .input,
.field.is-horizontal .field-body .textarea {
    width: 100%;
}

/* Fix for py4web adding 'select' class directly to <select> elements
   instead of using Bulma's wrapper div structure */
select.select {
    display: inline-block;
    max-width: 100%;
    width: 100%;
    height: 2.5em;
    padding: calc(0.5em - 1px) calc(0.75em - 1px);
    padding-right: 2.5em;
    font-size: 1rem;
    border: 1px solid #dbdbdb;
    border-radius: 4px;
    background-color: white;
    cursor: pointer;
    /* Use only native browser arrow - remove any Bulma background arrow */
    background-image: none !important;
}

select.select:hover {
    border-color: #b5b5b5;
}

select.select:focus {
    border-color: #485fc7;
    outline: none;
    box-shadow: 0 0 0 0.125em rgba(72, 95, 199, 0.25);
}

.field.is-horizontal .field-body select.select {
    width: 100%;
}

/* Checkbox styling - add spacing between checkbox and label */
.field.is-horizontal .control input[type="checkbox"] {
    margin-right: 0.5em;
    vertical-align: middle;
}

.field.is-horizontal .control label.checkbox {
    vertical-align: middle;
}

/* from py4web standard layout.html */
.py4web-validation-error {
    font-size: 0.8em;
    color: red
}

 /* image upload progress styling */

#progress-popup {
    display: none; 
    position: fixed; 
    top: 50%;
    left: 50%; 
    transform: translate(-50%, -50%); 
    background: rgba(0, 0, 0, 0.5); 
    z-index: 100003; 
    justify-content: center; 
    align-items: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#progress-popup div {
    background: white;
    padding: 20px;
    border-radius: 2px;
    text-align: center;
    width: 300px;
}

/* ===========================================
   Notification badge styling
   =========================================== */

.notification-badge {
    background-color: #e74c3c;
    color: white;
    border-radius: 50%;
    padding: 2px 6px;
    font-size: 12px;
    font-weight: bold;
    margin-right: 6px;
    min-width: 20px;
    text-align: center;
    display: inline-block;
}

/* ===========================================
   Search box styling (shared component)
   =========================================== */

.search-box {
    background-color: #fafafa;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

/* Compact field spacing */
.search-box .field.is-horizontal {
    margin-bottom: 0.2rem;
}

/* Remove extra margin from field-body */
.search-box .field-body .field {
    margin-bottom: 0;
}

/* Narrower labels */
.search-box .field.is-horizontal .field-label {
    flex-basis: 70px;
    padding-top: 0.15em;
    margin-right: 0.25rem;
}

.search-box .field.is-horizontal .field-label .label {
    font-size: 0.85rem;
    margin-bottom: 0;
}

/* Smaller inputs */
.search-box .input,
.search-box .textarea {
    font-size: 0.85rem;
    height: 26px;
    padding: 2px 8px;
}

/* Smaller select dropdowns - let Bulma's div.select handle the arrow */
.search-box select {
    font-size: 0.85rem;
    height: 26px;
    padding: 2px 8px;
    padding-right: 24px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: none !important;
}

/* Adjust Bulma's select wrapper for smaller height */
.search-box .select {
    height: 26px;
}

.search-box .select:not(.is-multiple):after {
    margin-top: -0.5em;
}

/* Smaller checkbox and label */
.search-box .control input[type="checkbox"] {
    transform: scale(0.9);
}

.search-box .control label,
.search-box label.checkbox {
    font-size: 0.85rem;
}

/* Smaller submit button */
.search-box .button {
    font-size: 0.85rem;
    height: 26px;
    padding: 2px 12px;
    margin-top: 0.2rem;
}

.search-toggle {
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
}

.search-toggle .icon {
    transition: transform 0.2s;
}

.search-toggle.is-open .icon {
    transform: rotate(90deg);
}

/* ===========================================
   Mobile Responsive Styles
   =========================================== */

/* Tablet: modules navbar horizontal scroll */
@media screen and (max-width: 1023px) {
    .navbar-modules .navbar-menu.is-active {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .navbar-modules .navbar-start {
        display: flex;
        flex-wrap: nowrap;
    }

    .navbar-modules .navbar-item {
        flex-shrink: 0;
    }
}

/* Mobile: stack forms and improve touch targets */
@media screen and (max-width: 768px) {
    /* Stack label above input for horizontal forms */
    .field.is-horizontal {
        flex-direction: column;
        align-items: stretch;
    }

    .field.is-horizontal .field-label {
        flex-basis: auto;
        text-align: left;
        margin-right: 0;
        margin-bottom: 0.25rem;
        padding-top: 0;
    }

    .field.is-horizontal .field-body {
        flex-grow: 1;
    }

    /* Search box adjustments */
    .search-box .field.is-horizontal .field-label {
        flex-basis: auto;
        text-align: left;
    }

    .search-box .button {
        width: 100%;
    }

    /* Larger touch targets for grid buttons */
    div.grid-wrapper .table td .button {
        padding: 0.5em 0.75em;
        font-size: 14px;
        min-width: 44px;
        min-height: 44px;
    }

    /* Better cell spacing for touch */
    div.grid-wrapper .table td {
        padding: 0.5em 0.5em;
    }

    /* Smooth touch scrolling for tables */
    .grid-table-wrapper {
        -webkit-overflow-scrolling: touch;
    }
}