/* ============================================================
   UI Component Library
   All components use Inter (--font-primary) and the project's
   dark-blue accent (--cdre-blue: #0f2c44).
   ============================================================ */

/* ── Form fields ─────────────────────────────────────────────── */

/* Shared token — change once to restyle all fields */
:root {
    --field-height:       36px;
    --field-font:         var(--font-primary, 'Inter', system-ui, sans-serif);
    --field-font-size:    13px;
    --field-color:        #111827;
    --field-placeholder:  #9ca3af;
    --field-bg:           #ffffff;
    --field-border:       #d1d5db;
    --field-border-focus: #0f2c44;
    --field-radius:       6px;
    --field-padding-x:    11px;
    --field-padding-y:    7px;
    --field-shadow-focus: 0 0 0 3px rgba(15, 44, 68, 0.12);
}

/* Label */
.ui-label {
    display: block;
    font-family: var(--field-font);
    font-size: 12px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 4px;
    line-height: 1.4;
}

/* Field wrapper — stacks label + control with consistent spacing */
.ui-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Base shared by input, select, textarea */
.ui-input,
.ui-select,
.ui-textarea {
    display: block;
    width: 100%;
    font-family: var(--field-font) !important;
    font-size: var(--field-font-size) !important;
    font-weight: 400 !important;
    color: var(--field-color) !important;
    background-color: var(--field-bg) !important;
    border: 1px solid var(--field-border) !important;
    border-radius: var(--field-radius) !important;
    padding: var(--field-padding-y) var(--field-padding-x) !important;
    line-height: 1.5 !important;
    box-sizing: border-box !important;
    transition: border-color 0.15s, box-shadow 0.15s !important;
    outline: none !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}

/* Fixed height for single-line fields */
.ui-input,
.ui-select {
    height: var(--field-height) !important;
}

/* Placeholder */
.ui-input::placeholder,
.ui-textarea::placeholder {
    color: var(--field-placeholder) !important;
    opacity: 1 !important;
}

/* Focus ring */
.ui-input:focus,
.ui-select:focus,
.ui-textarea:focus {
    border-color: var(--field-border-focus) !important;
    box-shadow: var(--field-shadow-focus) !important;
}

/* Disabled */
.ui-input:disabled,
.ui-select:disabled,
.ui-textarea:disabled {
    background-color: #f9fafb !important;
    color: #9ca3af !important;
    cursor: not-allowed !important;
}

/* Select — custom chevron, removes native arrow */
.ui-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 20 20' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 8l5 5 5-5'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 10px center !important;
    padding-right: 30px !important;
}

/* Textarea — auto height, min 3 rows */
.ui-textarea {
    height: auto !important;
    min-height: calc(var(--field-height) * 3) !important;
    resize: vertical !important;
}

/* Checkbox — kept simple, consistent size */
.ui-checkbox {
    width: 15px !important;
    height: 15px !important;
    border: 1px solid var(--field-border) !important;
    border-radius: 3px !important;
    accent-color: var(--field-border-focus) !important;
    cursor: pointer !important;
    flex-shrink: 0 !important;
    vertical-align: middle !important;
}

/* Inline checkbox + label pair */
.ui-check-row {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.ui-check-row .ui-label {
    margin-bottom: 0;
    font-weight: 400;
    cursor: pointer;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.ui-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border-radius: 6px;
    border: 1px solid transparent;
    font-family: var(--font-primary, 'Inter', sans-serif);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.ui-btn:disabled,
.ui-btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Primary */
.ui-btn-primary {
    background: #0f2c44;
    background: var(--cdre-blue, #0f2c44);
    color: #ffffff;
    border-color: transparent;
}
.ui-btn-primary:hover {
    background: #1a3f61;
    color: #ffffff;
    text-decoration: none;
}

/* Secondary / outline */
.ui-btn-secondary {
    background: #ffffff;
    color: #374151;
    border-color: #d1d5db;
}
.ui-btn-secondary:hover {
    background: #f9fafb;
    border-color: #9ca3af;
    color: #111827;
    text-decoration: none;
}

/* Danger */
.ui-btn-danger {
    background: #dc2626;
    color: #ffffff;
    border-color: transparent;
}
.ui-btn-danger:hover {
    background: #b91c1c;
    color: #ffffff;
    text-decoration: none;
}

/* Success */
.ui-btn-success {
    background: #16a34a;
    color: #ffffff;
    border-color: transparent;
}
.ui-btn-success:hover {
    background: #15803d;
    color: #ffffff;
    text-decoration: none;
}

/* Ghost */
.ui-btn-ghost {
    background: transparent;
    color: #374151;
    border-color: transparent;
}
.ui-btn-ghost:hover {
    background: #f3f4f6;
    color: #111827;
    text-decoration: none;
}

/* Sizes */
.ui-btn-sm { padding: 5px 11px; font-size: 12px; }
.ui-btn-lg { padding: 10px 22px; font-size: 15px; }


/* ── Cards ───────────────────────────────────────────────────── */
.ui-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 20px 24px;
    font-family: var(--font-primary, 'Inter', sans-serif);
}

.ui-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f3f4f6;
}

.ui-card-title {
    font-size: 15px;
    font-weight: 700;
    color: #111827;
    margin: 0;
}

.ui-card-subtitle {
    font-size: 12px;
    color: #6b7280;
    margin: 2px 0 0;
}

.ui-card-body {
    font-size: 14px;
    color: #374151;
    line-height: 1.6;
}

.ui-card-footer {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #f3f4f6;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Card shadow variants */
.ui-card-shadow { box-shadow: 0 1px 6px rgba(0,0,0,.06); }
.ui-card-flat   { box-shadow: none; border-color: #e5e7eb; }


/* ── Badges ──────────────────────────────────────────────────── */
.ui-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    border-radius: 999px;
    font-family: var(--font-primary, 'Inter', sans-serif);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
    line-height: 1.6;
}

.ui-badge-blue    { background: #dbeafe; color: #1e40af; }
.ui-badge-green   { background: #dcfce7; color: #15803d; }
.ui-badge-red     { background: #fee2e2; color: #b91c1c; }
.ui-badge-yellow  { background: #fef9c3; color: #854d0e; }
.ui-badge-gray    { background: #f3f4f6; color: #374151; }
.ui-badge-orange  { background: #ffedd5; color: #c2410c; }
.ui-badge-dark    { background: #1f2937; color: #f9fafb; }


/* ── Alerts ──────────────────────────────────────────────────── */
.ui-alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    border-width: 1px;
    border-style: solid;
    font-family: var(--font-primary, 'Inter', sans-serif);
    font-size: 13px;
    line-height: 1.5;
    margin-bottom: 16px;
}

.ui-alert-icon { flex-shrink: 0; margin-top: 1px; }

.ui-alert-title {
    font-weight: 700;
    margin-bottom: 2px;
    display: block;
}

.ui-alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.ui-alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #15803d; }
.ui-alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.ui-alert-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }


/* ── Page header ─────────────────────────────────────────────── */
.ui-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.ui-page-header-left {}

.ui-page-title {
    font-family: var(--font-primary, 'Inter', sans-serif);
    font-size: 20px;
    font-weight: 700;
    color: #111827;
    margin: 0 0 2px;
    line-height: 1.3;
}

.ui-page-description {
    font-family: var(--font-primary, 'Inter', sans-serif);
    font-size: 13px;
    color: #6b7280;
    margin: 0;
}

.ui-page-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}


/* ── Floating-label outlined field (Material Design style) ──────
   Usage:
     <div class="fl-field">
       <input  class="fl-input" id="x" type="text" placeholder=" ">
       <label  class="fl-label" for="x">Label</label>
     </div>
   For <select>: add class fl-select + fl-input, wrap same way.
   The placeholder=" " (single space) is required — CSS uses
   :placeholder-shown to detect an empty input.
   ─────────────────────────────────────────────────────────────── */
.fl-field {
    position: relative;
    font-family: var(--field-font);
}

/* The control — identical box to .ui-input but taller for label room */
.fl-input {
    display: block;
    width: 100%;
    height: 52px;
    padding: 18px 12px 6px;
    font-family: var(--field-font) !important;
    font-size: 14px !important;
    font-weight: 400 !important;
    color: var(--field-color) !important;
    background: var(--field-bg) !important;
    border: 1px solid var(--field-border) !important;
    border-radius: var(--field-radius) !important;
    box-sizing: border-box !important;
    outline: none !important;
    transition: border-color 0.15s !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    line-height: 1.4 !important;
}

/* Select variant — needs dropdown arrow */
select.fl-input {
    padding: 18px 32px 6px 12px !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 20 20' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 8l5 5 5-5'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 10px center !important;
    cursor: pointer !important;
}

/* Floating label */
.fl-label {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--field-font);
    font-size: 14px;
    font-weight: 400;
    color: #9ca3af;
    pointer-events: none;
    transition: top 0.15s, font-size 0.15s, color 0.15s, transform 0.15s;
    background: transparent;
    padding: 0 2px;
    line-height: 1;
    white-space: nowrap;
}

/* Float up when focused OR has a value (via :not(:placeholder-shown)) */
.fl-input:focus + .fl-label,
.fl-input:not(:placeholder-shown) + .fl-label,
select.fl-input + .fl-label {
    top: 10px;
    transform: translateY(0);
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    background: #fff;
    padding: 0 3px;
    left: 10px;
}

/* Accent color when focused */
.fl-input:focus {
    border-color: var(--field-border-focus) !important;
    box-shadow: var(--field-shadow-focus) !important;
}
.fl-input:focus + .fl-label {
    color: var(--field-border-focus);
}

/* Error state */
.fl-field.fl-error .fl-input {
    border-color: #dc2626 !important;
}
.fl-field.fl-error .fl-label,
.fl-field.fl-error .fl-input:focus + .fl-label {
    color: #dc2626;
}
.fl-helper {
    font-family: var(--field-font);
    font-size: 12px;
    color: #6b7280;
    margin-top: 4px;
}
.fl-field.fl-error .fl-helper { color: #dc2626; }

/* Disabled */
.fl-input:disabled {
    background: #f9fafb !important;
    color: #9ca3af !important;
    cursor: not-allowed !important;
}
.fl-input:disabled + .fl-label { color: #9ca3af; }


/* ── Divider ─────────────────────────────────────────────────── */
.ui-divider {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 20px 0;
}


/* ── Stat tile ───────────────────────────────────────────────── */
.ui-stat {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 16px 20px;
    font-family: var(--font-primary, 'Inter', sans-serif);
}
.ui-stat-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    margin-bottom: 6px;
}
.ui-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: #111827;
    line-height: 1;
}
.ui-stat-sub {
    font-size: 12px;
    color: #9ca3af;
    margin-top: 4px;
}

/* Stat grid helper */
.ui-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
}


/* ── Table wrapper ───────────────────────────────────────────── */
.ui-table-wrap {
    overflow-x: auto;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}
.ui-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-primary, 'Inter', sans-serif);
    font-size: 13px;
    color: #374151;
}
.ui-table thead th {
    background: #f9fafb;
    padding: 10px 14px;
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
    white-space: nowrap;
}
.ui-table tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}
.ui-table tbody tr:last-child td {
    border-bottom: none;
}
.ui-table tbody tr:hover td {
    background: #f9fafb;
}


/* ── Sub-navigation (page tabs) ─────────────────────────────────
   !important throughout — must survive phpgrid Bootstrap 3 cascade
   which resets font, box-model, and list styles globally.
   ──────────────────────────────────────────────────────────────── */
.app-subnav {
    background: #ffffff !important;
    border-bottom: 1px solid #e5e7eb !important;
    width: 100% !important;
    /* Sticks just below the 56px top-nav */
    position: sticky !important;
    top: 56px !important;
    z-index: 30 !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    padding: 0 !important;
}

.app-subnav .subnav-inner {
    width: 100% !important;
    max-width: 90rem !important;
    margin: 0 auto !important;
    padding: 0 1.5rem !important;
    /* Scroll only within this element — content wider than this box scrolls here */
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    box-sizing: border-box !important;
}
.app-subnav .subnav-inner::-webkit-scrollbar {
    display: none !important;
}

.app-subnav .subnav-list {
    display: inline-flex !important;
    flex-direction: row !important;
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
    white-space: nowrap !important;
    align-items: stretch !important;
}

.app-subnav .subnav-list li {
    display: flex !important;
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.app-subnav .subnav-link {
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    padding: 12px 14px !important;
    font-family: var(--font-primary, 'Inter', system-ui, sans-serif) !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    line-height: 1.4 !important;
    color: #6b7280 !important;
    text-decoration: none !important;
    border-bottom: 2px solid transparent !important;
    border-top: none !important;
    border-left: none !important;
    border-right: none !important;
    background: transparent !important;
    white-space: nowrap !important;
    transition: color 0.15s, border-color 0.15s, background 0.15s !important;
    box-sizing: border-box !important;
    cursor: pointer !important;
}

.app-subnav .subnav-link svg {
    width: 15px !important;
    height: 15px !important;
    flex-shrink: 0 !important;
    display: inline-block !important;
}

.app-subnav .subnav-link:hover {
    color: #111827 !important;
    background: #f9fafb !important;
    text-decoration: none !important;
    border-bottom-color: #d1d5db !important;
}

.app-subnav .subnav-link.subnav-active {
    color: #0f2c44 !important;
    font-weight: 700 !important;
    border-bottom-color: #0f2c44 !important;
    background: rgba(15, 44, 68, 0.07) !important;
    border-radius: 6px 6px 0 0 !important;
}

.app-subnav .subnav-link.subnav-active svg {
    color: #0f2c44 !important;
}

/* On very small screens, reduce tab padding slightly */
@media (max-width: 480px) {
    .app-subnav .subnav-link {
        padding: 10px 10px !important;
        font-size: 12px !important;
        gap: 4px !important;
    }
    .app-subnav .subnav-link svg {
        width: 13px !important;
        height: 13px !important;
    }
}
