/* ==========================================================================
   app.css — site-wide theme
   --------------------------------------------------------------------------
   All colors, type, and shape values live as CSS custom properties in :root
   so the look can be retuned in one place. The palette is modern *slate*
   neutrals with an *emerald* primary.

   Light theme only for now, but the variables are named generically so a dark
   theme can be added later as a single override block, e.g.:

       [data-bs-theme="dark"] {
           --color-bg: #0f172a;
           --color-surface: #1e293b;
           --color-text: #e2e8f0;
           ... (override the same names) ...
       }

   Bootstrap 5.3 is re-themed by feeding these variables into its own --bs-*
   custom properties (see the "Bootstrap bridge" section), so stock components
   (buttons, links, pagination, focus rings) pick up the palette automatically.
   ========================================================================== */

:root {
    /* --- Brand / primary (emerald) --- */
    --color-primary: #059669;
    --color-primary-hover: #047857;
    --color-primary-active: #065f46;
    --color-primary-subtle: #ecfdf5;
    --color-primary-contrast: #ffffff;
    --color-primary-rgb: 5, 150, 105;

    /* --- Slate neutral scale --- */
    --color-bg: #f8fafc;          /* page background  (slate-50)  */
    --color-surface: #ffffff;     /* cards, bars, table surfaces  */
    --color-surface-2: #f1f5f9;   /* subtle alt surface (slate-100) */
    --color-border: #e2e8f0;      /* hairline borders   (slate-200) */
    --color-border-strong: #cbd5e1;/* (slate-300)                  */
    --color-text: #1e293b;        /* body text          (slate-800) */
    --color-heading: #0f172a;     /* headings           (slate-900) */
    --color-muted: #64748b;       /* secondary text     (slate-500) */

    /* --- Dark surface (navbar / footer) --- */
    --color-dark: #0f172a;        /* slate-900 */
    --color-on-dark: #e2e8f0;     /* slate-200 */
    --color-on-dark-muted: #94a3b8;/* slate-400 */

    /* --- Typography --- */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, "Noto Sans", sans-serif,
        "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";

    /* --- Shape & depth --- */
    --radius-sm: 0.25rem;
    --radius: 0.425rem;
    --radius-lg: 1rem;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06),
                 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.08),
              0 2px 4px -2px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 12px 24px -8px rgba(15, 23, 42, 0.14),
                 0 4px 8px -4px rgba(15, 23, 42, 0.08);
    --transition: 150ms ease;
}

/* ==========================================================================
   Bootstrap bridge — map our variables onto Bootstrap's --bs-* properties.
   Some Bootstrap components (buttons, pagination) hard-code their colors into
   component-scoped custom props at compile time, so those are re-pointed in
   their own rules below rather than via :root alone.
   ========================================================================== */

:root {
    --bs-body-bg: var(--color-bg);
    --bs-body-color: var(--color-text);
    --bs-emphasis-color: var(--color-heading);
    --bs-border-color: var(--color-border);
    --bs-border-radius: var(--radius);
    --bs-border-radius-sm: var(--radius-sm);
    --bs-border-radius-lg: var(--radius-lg);

    --bs-primary: var(--color-primary);
    --bs-primary-rgb: var(--color-primary-rgb);

    --bs-link-color: var(--color-primary);
    --bs-link-color-rgb: var(--color-primary-rgb);
    --bs-link-hover-color: var(--color-primary-hover);
    --bs-link-hover-color-rgb: var(--color-primary-rgb);

    --bs-focus-ring-color: rgba(var(--color-primary-rgb), 0.25);

    --bs-font-sans-serif: var(--font-sans);
}

/* ==========================================================================
   Base
   ========================================================================== */

body {
    font-family: var(--font-sans);
    background-color: var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--color-heading);
    font-weight: 600;
    letter-spacing: -0.01em;
}

a {
    text-underline-offset: 0.15em;
}

/* ==========================================================================
   Buttons — re-point Bootstrap's component custom props to the palette.
   ========================================================================== */

.btn-primary,
.btn-success {
    --bs-btn-bg: var(--color-primary);
    --bs-btn-border-color: var(--color-primary);
    --bs-btn-hover-bg: var(--color-primary-hover);
    --bs-btn-hover-border-color: var(--color-primary-hover);
    --bs-btn-active-bg: var(--color-primary-active);
    --bs-btn-active-border-color: var(--color-primary-active);
    --bs-btn-disabled-bg: var(--color-primary);
    --bs-btn-disabled-border-color: var(--color-primary);
    --bs-btn-color: var(--color-primary-contrast);
    --bs-btn-hover-color: var(--color-primary-contrast);
    --bs-btn-active-color: var(--color-primary-contrast);
    --bs-btn-disabled-color: var(--color-primary-contrast);
}

.btn-outline-secondary {
    --bs-btn-color: var(--color-muted);
    --bs-btn-border-color: var(--color-border-strong);
    --bs-btn-hover-bg: var(--color-surface-2);
    --bs-btn-hover-border-color: var(--color-border-strong);
    --bs-btn-hover-color: var(--color-heading);
    --bs-btn-active-bg: var(--color-surface-2);
    --bs-btn-active-color: var(--color-heading);
}

.btn {
    --bs-btn-border-radius: var(--radius-sm);
    font-weight: 500;
    transition: background-color var(--transition), border-color var(--transition),
                box-shadow var(--transition), transform var(--transition);
}

.btn-primary:hover,
.btn-success:hover {
    box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   Navbar
   ========================================================================== */

.app-navbar {
    background-color: var(--color-dark);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 1030;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.app-navbar .navbar-brand {
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-primary);
}

.app-navbar .navbar-brand:hover {
    color: var(--color-primary-hover);
}

.app-navbar .nav-link {
    color: var(--color-on-dark-muted);
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding-inline: 0.75rem;
    transition: color var(--transition), background-color var(--transition);
}

.app-navbar .nav-link:hover,
.app-navbar .nav-link:focus {
    color: var(--color-on-dark);
    background-color: rgba(255, 255, 255, 0.06);
}

.app-navbar .nav-link.active {
    color: #fff;
    background-color: rgba(var(--color-primary-rgb), 0.9);
}

/* ==========================================================================
   Cards & surfaces
   ========================================================================== */

.card {
    --bs-card-bg: var(--color-surface);
    --bs-card-border-color: var(--color-border);
    --bs-card-border-radius: var(--radius);
}

/* ==========================================================================
   Filter bar
   ========================================================================== */

.app-filter-bar {
    padding: 1rem;
    margin-bottom: 1rem;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.app-filter-bar .form-label {
    font-weight: 500;
    letter-spacing: 0.01em;
}

.form-control,
.form-select {
    border-color: var(--color-border-strong);
    border-radius: var(--radius-sm);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 0.2rem rgba(var(--color-primary-rgb), 0.2);
}

/* ==========================================================================
   Tables
   ========================================================================== */

.table {
    --bs-table-bg: var(--color-surface);
    --bs-table-color: var(--color-text);
    --bs-table-border-color: var(--color-border);
    --bs-table-striped-bg: var(--color-surface-2);
    --bs-table-hover-bg: var(--color-primary-subtle);
    margin-bottom: 0;
}

.table > thead {
    --bs-table-bg: var(--color-surface-2);
    border-bottom: 2px solid var(--color-border);
}

.table > thead th {
    color: var(--color-muted);
    font-weight: 600;
    white-space: nowrap;
}

/* Wrap data tables in a card-like surface */
.table-responsive {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

/* ==========================================================================
   Sortable column headers
   ========================================================================== */

.sort-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: inherit;
    text-decoration: none;
    transition: color var(--transition);
}

.sort-link:hover {
    color: var(--color-primary);
}

.sort-link .sort-arrow {
    font-size: 1.6em;
    line-height: 0.8;
    transition: opacity var(--transition), color var(--transition);
}

/* Inactive arrows are faint; active column's arrow is emerald */
.sort-link.is-inactive .sort-arrow {
    opacity: 0.35;
}

.sort-link.is-active {
    color: var(--color-primary);
}

.sort-link.is-active .sort-arrow {
    color: var(--color-primary);
    opacity: 1;
}

/* ==========================================================================
   Pagination
   ========================================================================== */

.pagination {
    --bs-pagination-color: var(--color-muted);
    --bs-pagination-bg: var(--color-surface);
    --bs-pagination-border-color: var(--color-border);
    --bs-pagination-hover-color: var(--color-primary-hover);
    --bs-pagination-hover-bg: var(--color-primary-subtle);
    --bs-pagination-hover-border-color: var(--color-border);
    --bs-pagination-focus-color: var(--color-primary-hover);
    --bs-pagination-focus-bg: var(--color-primary-subtle);
    --bs-pagination-focus-box-shadow: 0 0 0 0.2rem rgba(var(--color-primary-rgb), 0.2);
    --bs-pagination-active-bg: var(--color-primary);
    --bs-pagination-active-border-color: var(--color-primary);
    --bs-pagination-border-radius: var(--radius-sm);
    margin: 1rem 0;
}

.page-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.page-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* ==========================================================================
   Detail field table (key/value)
   ========================================================================== */

.detail-table {
    margin-bottom: 0;
}

/* When a data table sits inside a card, the card already provides the
   surface — don't double up the border/shadow. */
.card .table-responsive {
    border: 0;
    box-shadow: none;
    border-radius: 0;
    background-color: transparent;
}

.detail-table th {
    width: 32%;
    color: var(--color-muted);
    font-weight: 500;
    text-transform: capitalize;
    background-color: var(--color-surface-2);
    border-color: var(--color-border);
    white-space: nowrap;
    vertical-align: top;
}

.detail-table td {
    color: var(--color-text);
    border-color: var(--color-border);
    word-break: break-word;
}

.detail-table tbody tr:hover td,
.detail-table tbody tr:hover th {
    background-color: var(--color-primary-subtle);
}

/* ==========================================================================
   QBO typeahead (bulk mapping editor)
   --------------------------------------------------------------------------
   The menu is appended to <body> and positioned with `fixed`, because the
   editor table sits inside .table-responsive, which clips its overflow.
   ========================================================================== */

.qbo-picker {
    position: relative;
}

/* Room for the clear button so long names don't run under it. */
.qbo-picker .qbo-typeahead {
    padding-right: 1.75rem;
}

.qbo-clear {
    position: absolute;
    top: 50%;
    right: 0.4rem;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.15rem;
    height: 1.15rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--color-muted);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    transition: background-color var(--transition), color var(--transition);
}

.qbo-clear:hover {
    background-color: var(--color-surface-2);
    color: var(--color-heading);
}

.qbo-menu {
    position: fixed;
    z-index: 1080;               /* above the sticky navbar (1030) */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.qbo-menu[hidden] {
    display: none;
}

.qbo-menu-list {
    margin: 0;
    padding: 0.25rem;
    overflow-y: auto;
    list-style: none;
}

.qbo-option {
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    line-height: 1.35;
    color: var(--color-text);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.qbo-option.is-active {
    background-color: var(--color-primary);
    color: var(--color-primary-contrast);
}

/* Matched substrings: emerald on white, inverted inside the active row. */
.qbo-option mark {
    padding: 0;
    background: transparent;
    color: var(--color-primary);
    font-weight: 600;
}

.qbo-option.is-active mark {
    color: var(--color-primary-contrast);
    text-decoration: underline;
}

.qbo-menu-status {
    flex: none;
    padding: 0.3rem 0.6rem;
    border-top: 1px solid var(--color-border);
    background-color: var(--color-surface-2);
    color: var(--color-muted);
    font-size: 0.75rem;
}

/* ==========================================================================
   Forms (crispy create/edit)
   ========================================================================== */

.app-form .asteriskField {
    color: var(--color-primary);
    margin-left: 0.15rem;
}

.app-form label {
    font-weight: 500;
    color: var(--color-heading);
}
