/*
 * Ridey admin panel: the shared page system.  Loaded after admin-theme.css (see AdminPanelProvider) and plain CSS on purpose: nothing here needs a Tailwind rebuild.
 *
 * What it is for: every authenticated page uses the same building blocks, so this file defines them once instead of each page patching itself.
 *   1. design tokens (lines, input borders, header tint, spacing) derived from the active theme's own --tk-* colours, so all five themes and dark mode follow
 *   2. page header and breadcrumbs
 *   3. cards (sections) with a heading, a description and a clear body
 *   4. form controls: a real visible border (the old theme removed Filament's ring and put nothing back), labels, helper text, errors, switches
 *   5. tables: Filament's own tables and the hand-written ones share one look and always scroll inside their card instead of hiding or bleeding out
 *   6. tabs, buttons, row actions, modals
 *   7. small screens
 *
 * Presentation only: no markup, route, permission or behaviour depends on anything in here.
 */

/* ------------------------------------------------------------------ 1. tokens */

html[data-taara-theme] {
    --ui-line: color-mix(in srgb, var(--tk-text) 9%, transparent);
    --ui-line-strong: color-mix(in srgb, var(--tk-text) 16%, transparent);
    --ui-input-bg: var(--tk-card-bg);
    --ui-input-border: color-mix(in srgb, var(--tk-text) 28%, var(--tk-card-bg));
    --ui-input-border-hover: color-mix(in srgb, var(--tk-text) 42%, var(--tk-card-bg));
    --ui-th-bg: color-mix(in srgb, var(--tk-text) 5.5%, var(--tk-card-bg));
    --ui-row-hover: color-mix(in srgb, var(--tk-accent) 7%, var(--tk-card-bg));
    --ui-subtle: color-mix(in srgb, var(--tk-text) 3.5%, var(--tk-card-bg));
    --ui-radius: var(--tk-card-radius, 0.75rem);
    --ui-gap: 1.5rem;
}

/* dark mode: the top bar was a fixed navy on every theme, which clashed with the warm dark canvas of the Taara theme */
html.dark[data-taara-theme] {
    --tk-topbar-bg: color-mix(in srgb, var(--tk-canvas) 90%, transparent);
    --ui-input-bg: color-mix(in srgb, #ffffff 4%, var(--tk-card-bg));
    --ui-input-border: color-mix(in srgb, #ffffff 24%, var(--tk-card-bg));
    --ui-input-border-hover: color-mix(in srgb, #ffffff 38%, var(--tk-card-bg));
    --ui-th-bg: color-mix(in srgb, #ffffff 7%, var(--tk-card-bg));
    --ui-line: rgba(255, 255, 255, 0.09);
    --ui-line-strong: rgba(255, 255, 255, 0.17);
}

/* ------------------------------------------------------------------ 2. page frame and header */

html[data-taara-theme] .fi-main {
    padding-top: 1rem;
    padding-bottom: 3rem;
}

html[data-taara-theme] .fi-page {
    row-gap: var(--ui-gap);
}

html[data-taara-theme] .fi-header {
    padding-bottom: 0.25rem;
    gap: 1rem;
}

html[data-taara-theme] .fi-header-heading {
    font-size: 1.625rem;
    line-height: 1.2;
}

html[data-taara-theme] .fi-header-subheading {
    margin-top: 0.375rem;
    max-width: 60rem;
    color: var(--tk-text-soft);
    font-size: 0.9375rem;
    line-height: 1.5;
}

html[data-taara-theme] .fi-header .fi-ac {
    gap: 0.5rem;
}

html[data-taara-theme] .fi-breadcrumbs {
    margin-bottom: 0.375rem;
}

/* a short line under a page heading that a page prints itself (many pages write "Manage ..." in a plain paragraph) */
html[data-taara-theme] .fi-page > section > p,
html[data-taara-theme] .fi-page-content > p {
    color: var(--tk-text-soft);
}

/* ------------------------------------------------------------------ 3. cards */

html[data-taara-theme] .fi-section,
html[data-taara-theme] .fi-ta-ctn,
html[data-taara-theme] .fi-fo-tabs,
html[data-taara-theme] .fi-in-tabs,
html[data-taara-theme] .fi-wi-stats-overview-stat,
html[data-taara-theme] .fi-wi-chart {
    border-color: var(--ui-line-strong);
}

/* (no overflow:hidden on cards: a select or date picker opened inside a card must be able to extend past its edge) */
/* heading band: the title and description sit on a faint tint above the body, separated by a hairline */
html[data-taara-theme] .fi-section-header {
    padding: 1.125rem 1.5rem;
    background: var(--ui-subtle);
    border-bottom: 1px solid var(--ui-line);
    border-radius: calc(var(--tk-card-radius, 0.75rem) - 1px) calc(var(--tk-card-radius, 0.75rem) - 1px) 0 0;
}

html[data-taara-theme] .fi-section-header-heading {
    font-size: 1rem;
    line-height: 1.4;
}

html[data-taara-theme] .fi-section-header-description {
    margin-top: 0.125rem;
    color: var(--tk-text-soft);
    font-size: 0.8125rem;
    line-height: 1.45;
}

html[data-taara-theme] .fi-section-content-ctn {
    border-top: 0;
}

html[data-taara-theme] .fi-section-content {
    padding: 1.5rem;
}

html[data-taara-theme] .fi-section-footer {
    padding: 0.875rem 1.5rem;
    background: var(--ui-subtle);
    border-radius: 0 0 calc(var(--tk-card-radius, 0.75rem) - 1px) calc(var(--tk-card-radius, 0.75rem) - 1px);
}

/* a section that has no heading is just a padded card: no band */
html[data-taara-theme] .fi-section:not(:has(.fi-section-header)) > .fi-section-content-ctn {
    border-top: 0;
}

/* cards stacked inside a tab or a form keep an even rhythm */
html[data-taara-theme] .fi-fo-tabs-tab > .fi-fo-component-ctn,
html[data-taara-theme] .fi-fo-tabs-tab {
    row-gap: var(--ui-gap);
}

/* ------------------------------------------------------------------ 4. forms */

/* ROOT CAUSE of the borderless fields: admin-theme.css set `box-shadow: none !important` on .fi-input-wrp. Filament draws the outline of every
   input (text, select, textarea, date, number) as a ring, which IS a box-shadow, so the outline vanished and nothing replaced it.
   The wrapper now carries a real border of its own, which no shadow rule can remove. */
html[data-taara-theme] .fi-input-wrp {
    background: var(--ui-input-bg);
    border: 1px solid var(--ui-input-border) !important;
    box-shadow: none !important;
}

html[data-taara-theme] .fi-input-wrp:hover:not(:focus-within) {
    border-color: var(--ui-input-border-hover) !important;
}

html[data-taara-theme] .fi-input-wrp:focus-within {
    border-color: var(--tk-accent) !important;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--tk-accent) 22%, transparent) !important;
}

html[data-taara-theme] .fi-input-wrp.fi-disabled,
html[data-taara-theme] .fi-input-wrp:has(:disabled) {
    background: var(--ui-subtle);
}

html[data-taara-theme] .fi-input-wrp .fi-input,
html[data-taara-theme] .fi-input-wrp .fi-select-input {
    color: var(--tk-text);
    font-size: 0.875rem;
    min-height: 2.5rem;
}

html[data-taara-theme] .fi-input-wrp-prefix,
html[data-taara-theme] .fi-input-wrp-suffix {
    color: var(--tk-text-soft);
}

html[data-taara-theme] .fi-input::placeholder {
    color: color-mix(in srgb, var(--tk-text) 42%, transparent);
}

/* the filled field wrapper outside an input wrapper: textarea, file upload, rich text, key-value, repeater, checkbox list */
html[data-taara-theme] .fi-fo-file-upload .filepond--root,
html[data-taara-theme] .fi-fo-file-upload .filepond--panel-root {
    background: var(--ui-input-bg);
}

html[data-taara-theme] .fi-fo-file-upload .filepond--panel-root {
    border: 1px dashed var(--ui-input-border);
}

/* checkboxes and radios: a visible outline in both modes */
html[data-taara-theme] .fi-checkbox-input,
html[data-taara-theme] .fi-radio-input {
    --tw-ring-color: var(--ui-input-border) !important;
    background-color: var(--ui-input-bg);
}

html[data-taara-theme] .fi-checkbox-input:checked,
html[data-taara-theme] .fi-radio-input:checked {
    background-color: var(--tk-accent);
}

/* labels, hints, helper text and errors read as four different things */
html[data-taara-theme] .fi-fo-field-wrp {
    row-gap: 0.375rem;
}

html[data-taara-theme] .fi-fo-field-wrp-label,
html[data-taara-theme] .fi-fo-field-wrp-label span {
    color: var(--tk-text);
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.35;
}

html[data-taara-theme] .fi-fo-field-wrp-helper-text,
html[data-taara-theme] .fi-fo-field-wrp-hint {
    color: var(--tk-text-soft);
    font-size: 0.8125rem;
    font-weight: 400;
    line-height: 1.5;
}

html[data-taara-theme] .fi-fo-field-wrp-error-message {
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.4;
}

/* a field inside a form grid never stretches past its column */
html[data-taara-theme] .fi-fo-field-wrp,
html[data-taara-theme] .fi-fo-component-ctn > * {
    min-width: 0;
}

/* on/off switches: the "off" track was a pale grey that disappeared on the cream canvas */
html[data-taara-theme] button[role="switch"][aria-checked="false"] {
    background-color: color-mix(in srgb, var(--tk-text) 24%, var(--tk-card-bg));
}

html[data-taara-theme] button[role="switch"][aria-checked="true"] {
    background-color: var(--tk-accent);
}

/* ------------------------------------------------------------------ 5. tables */

/* Filament's own tables (every Resource list and every relation manager) */
html[data-taara-theme] .fi-ta-ctn {
    background: var(--tk-card-bg) !important;
}

html[data-taara-theme] .fi-ta-header-ctn,
html[data-taara-theme] .fi-ta-content,
html[data-taara-theme] .fi-ta-content > table {
    border-color: var(--ui-line);
}

html[data-taara-theme] .fi-ta-header-toolbar {
    padding-top: 0.875rem;
    padding-bottom: 0.875rem;
    gap: 0.75rem;
    flex-wrap: wrap;
}

html[data-taara-theme] .fi-ta-content {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

html[data-taara-theme] .fi-ta-table {
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

/* the heading row: a clearly tinted band, readable titles, one height */
html[data-taara-theme] .fi-ta-table > thead > tr {
    background: var(--ui-th-bg);
}

html[data-taara-theme] .fi-ta-header-cell,
html[data-taara-theme] .fi-ta-table > thead th {
    background: var(--ui-th-bg);
    color: color-mix(in srgb, var(--tk-text) 72%, var(--tk-card-bg));
    border-bottom: 1px solid var(--ui-line-strong);
    font-size: 0.75rem;
    font-weight: 650;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    white-space: nowrap;
}

html[data-taara-theme] .fi-ta-header-cell button {
    color: inherit;
}

/* rows: a visible hairline between rows, a hover tint, comfortable height */
html[data-taara-theme] .fi-ta-row > td,
html[data-taara-theme] .fi-ta-table > tbody > tr > td {
    border-bottom: 1px solid var(--ui-line);
    color: var(--tk-text);
    vertical-align: middle;
}

html[data-taara-theme] .fi-ta-table > tbody > tr:last-child > td {
    border-bottom: 0;
}

html[data-taara-theme] .fi-ta-row {
    background: transparent;
}

html[data-taara-theme] .fi-ta-row:hover {
    background: var(--ui-row-hover) !important;
}

html[data-taara-theme] .fi-ta-row.fi-selected,
html[data-taara-theme] .fi-ta-row[aria-selected="true"] {
    background: color-mix(in srgb, var(--tk-accent) 11%, var(--tk-card-bg)) !important;
}

html[data-taara-theme] .fi-ta-cell,
html[data-taara-theme] .fi-ta-text-item,
html[data-taara-theme] .fi-ta-text-item-label {
    color: var(--tk-text);
}

html[data-taara-theme] .fi-ta-text-item-description,
html[data-taara-theme] .fi-ta-col-wrp .text-gray-500 {
    color: var(--tk-text-soft);
}

/* row actions: one icon size, one hit area, always visible and never wrapped onto two lines */
html[data-taara-theme] .fi-ta-actions {
    flex-wrap: nowrap;
    gap: 0.25rem;
    white-space: nowrap;
}

html[data-taara-theme] .fi-ta-actions .fi-icon-btn,
html[data-taara-theme] .fi-ta-actions .fi-link {
    min-width: 2rem;
    min-height: 2rem;
}

html[data-taara-theme] .fi-ta-cell:last-child {
    padding-right: 0.75rem;
}

/* A wide table scrolls sideways inside its card; the row actions (View, Edit, Delete ...) stay pinned at the right edge so they are never scrolled
   out of sight. When the table fits, the pinned cell looks exactly like any other. */
html[data-taara-theme] .fi-ta-table td:last-child:has(.fi-ta-actions),
html[data-taara-theme] .fi-ta-table th.fi-ta-actions-header-cell:last-child {
    position: sticky;
    right: 0;
    z-index: 1;
    box-shadow: -1px 0 0 var(--ui-line);
}

html[data-taara-theme] .fi-ta-table td:last-child:has(.fi-ta-actions) {
    background: var(--tk-card-bg);
}

html[data-taara-theme] .fi-ta-table th.fi-ta-actions-header-cell:last-child {
    background: var(--ui-th-bg);
    z-index: 2;
}

html[data-taara-theme] .fi-ta-row:hover > td:last-child:has(.fi-ta-actions) {
    background: var(--ui-row-hover);
}

html[data-taara-theme] .fi-ta-empty-state {
    padding: 2.5rem 1.5rem;
}

html[data-taara-theme] .fi-ta-pagination {
    border-top: 1px solid var(--ui-line);
    background: var(--ui-subtle);
}

html[data-taara-theme] .fi-ta-filters-above-content-ctn,
html[data-taara-theme] .fi-ta-filters-below-content {
    background: var(--ui-subtle);
}

/* The hand-written tables (reports, overviews, monitoring). They sit in a `.tk-table-wrap` card, which scrolls sideways when a table is wider than
   the screen, and they share Filament's table look. A table that is not inside a Filament table and not inside a wrapper still gets the look. */
.tk-table-wrap {
    width: 100%;
    overflow-x: auto;
    background: var(--tk-card-bg);
    border: 1px solid var(--ui-line-strong);
    border-radius: calc(var(--ui-radius) - 0.125rem);
    -webkit-overflow-scrolling: touch;
}

/* a table that sits under a card's own heading is flush with that card: no second frame, just a rule between heading and table */
html[data-taara-theme] :is(.fi-section, .rounded-xl, .rounded-lg, .fi-wi-chart) .tk-table-wrap {
    border-width: 1px 0 0;
    border-radius: 0;
    background: transparent;
}

html[data-taara-theme] .fi-main table:not(.fi-ta-table):not(.fi-ta-table *) {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    color: var(--tk-text);
}

html[data-taara-theme] .fi-main table:not(.fi-ta-table):not(.fi-ta-table *) thead th {
    background: var(--ui-th-bg);
    color: color-mix(in srgb, var(--tk-text) 72%, var(--tk-card-bg));
    border-bottom: 1px solid var(--ui-line-strong);
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 650;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-align: left;
    white-space: nowrap;
}

html[data-taara-theme] .fi-main table:not(.fi-ta-table):not(.fi-ta-table *) thead th.text-right,
html[data-taara-theme] .fi-main table:not(.fi-ta-table):not(.fi-ta-table *) thead th.num {
    text-align: right;
}

html[data-taara-theme] .fi-main table:not(.fi-ta-table):not(.fi-ta-table *) tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--ui-line);
    vertical-align: middle;
    color: var(--tk-text);
}

html[data-taara-theme] .fi-main table:not(.fi-ta-table):not(.fi-ta-table *) tbody tr:last-child td {
    border-bottom: 0;
}

html[data-taara-theme] .fi-main table:not(.fi-ta-table):not(.fi-ta-table *) tbody tr:hover {
    background: var(--ui-row-hover);
}

html[data-taara-theme] .fi-main table:not(.fi-ta-table):not(.fi-ta-table *) tfoot td,
html[data-taara-theme] .fi-main table:not(.fi-ta-table):not(.fi-ta-table *) tfoot th {
    background: var(--ui-subtle);
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--ui-line-strong);
    font-weight: 600;
}

/* Small grey notes under a figure (text-gray-500 and the like) sit on the card itself, so in dark mode they take the soft text colour. Pills that carry
   their own light background (bg-gray-50, bg-white ...) are left alone: their text colour was chosen for that background. */
html.dark[data-taara-theme] .fi-main table:not(.fi-ta-table):not(.fi-ta-table *) :is(.text-gray-500, .text-gray-600, .text-gray-700):not([class*="bg-"]) {
    color: var(--tk-text-soft);
}

/* ------------------------------------------------------------------ 6. tabs, buttons, modals */

/* tab bar: a tinted track with the active tab lifted out of it */
html[data-taara-theme] .fi-fo-tabs > .fi-tabs,
html[data-taara-theme] .fi-in-tabs > .fi-tabs {
    padding: 0.5rem 0.75rem;
    gap: 0.25rem;
    background: var(--ui-subtle);
    border-bottom: 1px solid var(--ui-line);
    border-radius: calc(var(--tk-card-radius, 0.75rem) - 1px) calc(var(--tk-card-radius, 0.75rem) - 1px) 0 0;
}

html[data-taara-theme] .fi-tabs-item {
    padding: 0.5rem 0.875rem;
    font-weight: 550;
    color: var(--tk-text-soft);
}

html[data-taara-theme] .fi-tabs-item:hover {
    color: var(--tk-text);
    background: color-mix(in srgb, var(--tk-text) 6%, transparent);
}

html[data-taara-theme] .fi-tabs-item.fi-active,
html[data-taara-theme] .fi-tabs-item-active {
    background: var(--tk-card-bg) !important;
    color: var(--tk-text);
    box-shadow: 0 0 0 1px var(--ui-line-strong), 0 1px 2px rgba(15, 23, 42, 0.08);
}

html[data-taara-theme] .fi-tabs-item.fi-active .fi-tabs-item-label,
html[data-taara-theme] .fi-tabs-item.fi-active .fi-tabs-item-icon {
    color: var(--tk-accent-text, var(--tk-accent)) !important;
}

html[data-taara-theme] .fi-fo-tabs-tab {
    padding: 1.5rem;
}

/* secondary buttons keep a visible outline on the cream canvas */
html[data-taara-theme] .fi-btn.fi-color-gray {
    border: 1px solid var(--ui-input-border);
    background: var(--tk-card-bg);
    color: var(--tk-text);
}

html[data-taara-theme] .fi-btn.fi-color-gray:hover {
    background: var(--ui-subtle);
    border-color: var(--ui-input-border-hover);
}

html[data-taara-theme] .fi-modal-header,
html[data-taara-theme] .fi-modal-footer {
    border-color: var(--ui-line);
}

html[data-taara-theme] .fi-dropdown-panel {
    border: 1px solid var(--ui-line-strong);
}

/* the badge colours used for status keep their own contrast; only the shape is unified */
html[data-taara-theme] .fi-badge {
    font-weight: 600;
}

/* ------------------------------------------------------------------ 7. small screens */

@media (max-width: 1023.98px) {
    html[data-taara-theme] .fi-section-content,
    html[data-taara-theme] .fi-fo-tabs-tab {
        padding: 1.125rem;
    }
}

@media (max-width: 767.98px) {
    html[data-taara-theme] .fi-main {
        padding-inline: 1rem;
    }

    html[data-taara-theme] .fi-header {
        flex-direction: column;
        align-items: stretch;
    }

    html[data-taara-theme] .fi-header .fi-ac {
        flex-wrap: wrap;
        width: 100%;
    }

    html[data-taara-theme] .fi-header-heading {
        font-size: 1.375rem;
    }

    html[data-taara-theme] .fi-section-header {
        padding: 0.875rem 1rem;
    }

    html[data-taara-theme] .fi-section-content,
    html[data-taara-theme] .fi-fo-tabs-tab {
        padding: 1rem;
    }

    html[data-taara-theme] .fi-fo-tabs > .fi-tabs,
    html[data-taara-theme] .fi-in-tabs > .fi-tabs {
        padding: 0.375rem;
    }

    html[data-taara-theme] .fi-tabs-item {
        padding: 0.4375rem 0.625rem;
        font-size: 0.8125rem;
    }

    html[data-taara-theme] .fi-ta-header-toolbar {
        padding-inline: 0.75rem;
    }

    html[data-taara-theme] .fi-ta-header-cell,
    html[data-taara-theme] .fi-ta-cell {
        white-space: nowrap;
    }
}
