/*
 * Tracker theme: a thin layer over Bootstrap 5.3 that changes the palette,
 * the radii and the typography so the app does not look like stock Bootstrap.
 * Everything else is plain Bootstrap components.
 */

:root {
    --tr-accent: #4c6ef5;
    --tr-accent-strong: #3b5bdb;
    --tr-accent-soft: rgba(76, 110, 245, 0.12);

    --bs-primary: var(--tr-accent);
    --bs-primary-rgb: 76, 110, 245;
    --bs-link-color: var(--tr-accent-strong);
    --bs-link-hover-color: var(--tr-accent);

    --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --bs-body-font-size: 0.9375rem;

    --bs-border-radius: 0.5rem;
    --bs-border-radius-sm: 0.375rem;
    --bs-border-radius-lg: 0.75rem;
}

[data-bs-theme="light"] {
    --bs-body-bg: #f6f7f9;
    --bs-secondary-bg: #ffffff;
    --bs-border-color: #e3e6ea;
}

[data-bs-theme="dark"] {
    --tr-accent: #748ffc;
    --tr-accent-strong: #91a7ff;
    --tr-accent-soft: rgba(116, 143, 252, 0.16);

    --bs-primary: var(--tr-accent);
    --bs-primary-rgb: 116, 143, 252;
    --bs-link-color: var(--tr-accent);
    --bs-link-hover-color: var(--tr-accent-strong);

    --bs-body-bg: #16181d;
    --bs-secondary-bg: #1e2128;
    --bs-border-color: #2c313a;
}

/* --- buttons ------------------------------------------------------------ */

.btn-primary {
    --bs-btn-bg: var(--tr-accent);
    --bs-btn-border-color: var(--tr-accent);
    --bs-btn-hover-bg: var(--tr-accent-strong);
    --bs-btn-hover-border-color: var(--tr-accent-strong);
    --bs-btn-active-bg: var(--tr-accent-strong);
    --bs-btn-active-border-color: var(--tr-accent-strong);
}

.btn-outline-primary {
    --bs-btn-color: var(--tr-accent);
    --bs-btn-border-color: var(--tr-accent);
    --bs-btn-hover-bg: var(--tr-accent);
    --bs-btn-hover-border-color: var(--tr-accent);
    --bs-btn-active-bg: var(--tr-accent);
    --bs-btn-active-border-color: var(--tr-accent);
}

/* --- shell -------------------------------------------------------------- */

body {
    min-height: 100vh;
}

.tr-navbar {
    background-color: var(--bs-secondary-bg);
    border-bottom: 1px solid var(--bs-border-color);
}

.tr-brand {
    font-weight: 600;
    letter-spacing: -0.01em;
}

.tr-sidebar .nav-link {
    border-radius: var(--bs-border-radius);
    color: var(--bs-body-color);
    padding: 0.4rem 0.65rem;
}

.tr-sidebar .nav-link:hover {
    background-color: var(--tr-accent-soft);
}

.tr-sidebar .nav-link.active {
    background-color: var(--tr-accent-soft);
    color: var(--tr-accent-strong);
    font-weight: 600;
}

.tr-sidebar .nav-link i {
    width: 1.25rem;
}

/* --- cards and numbers -------------------------------------------------- */

.card {
    border-color: var(--bs-border-color);
    /* Cards must sit above the page ground, not on it. */
    background-color: var(--bs-secondary-bg);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

[data-bs-theme="dark"] .card {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.tr-stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--bs-secondary-color);
}

.tr-stat-value {
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.tr-num {
    font-variant-numeric: tabular-nums;
}

/* --- login -------------------------------------------------------------- */

.tr-login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.tr-login-card {
    width: 100%;
    max-width: 22rem;
}

/* --- board -------------------------------------------------------------- */

/*
 * Six columns share the available width instead of each claiming a fixed
 * 17rem, so a normal desktop shows the whole board with no sideways scroll.
 * The scroll only comes back below ~66rem of board area, where the columns
 * would otherwise be too narrow to read.
 */
.tr-board {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(11rem, 1fr);
    gap: 0.75rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    padding-bottom: 0.5rem;
    /* Columns run to the bottom of the viewport and scroll on their own,
       so the page itself never grows a vertical scrollbar. */
    height: calc(100vh - 9.5rem);
}

.tr-board-col {
    min-width: 0;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
}

.tr-board-head {
    flex: 0 0 auto;
    padding-bottom: 0.35rem;
}

/* Client and project outrank the task name on a card, so the name is the
   one that shrinks. */
.tr-card-title {
    line-height: 1.3;
}

/* Logged minutes pinned to the top-right corner of a board card. The title
   is padded away from it so long names wrap before they collide. */
.tr-card .card-body {
    position: relative;
}

.tr-card-time {
    position: absolute;
    top: 0.4rem;
    right: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--bs-secondary-color);
}

.tr-card-title {
    padding-right: 3rem;
}

/* Long titles wrap rather than forcing the column wider. */
.tr-card .card-body a {
    overflow-wrap: anywhere;
}

/* Badges wrap onto a second line instead of spilling past the card edge. */
.tr-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
}

.tr-card-meta .badge {
    max-width: 100%;
    white-space: normal;
    text-align: left;
}

.tr-board-drop {
    min-height: 6rem;
    border: 1px dashed var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    padding: 0.5rem;
    background-color: var(--tr-board-lane);
    flex: 1 1 auto;
    overflow-y: auto;
}

/* Lane is a recessed tray; the cards on it are raised and accented. */
[data-bs-theme="light"] {
    --tr-board-lane: #eceef2;
}

[data-bs-theme="dark"] {
    --tr-board-lane: #121419;
}

.tr-card {
    cursor: grab;
    border-left: 3px solid var(--tr-accent);
    transition: box-shadow 0.12s ease, transform 0.12s ease;
}

.tr-card:hover {
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.1);
    transform: translateY(-1px);
}

[data-bs-theme="dark"] .tr-card:hover {
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

/* Priority reads off the left edge, so the eye finds urgent work first. */
.tr-card.tr-q-danger { border-left-color: var(--bs-danger); }
.tr-card.tr-q-warning { border-left-color: var(--bs-warning); }
.tr-card.tr-q-primary { border-left-color: var(--tr-accent); }
.tr-card.tr-q-secondary { border-left-color: var(--bs-secondary-color); }

.tr-card-ghost {
    opacity: 0.4;
    border-color: var(--tr-accent);
}

/* --- task history ------------------------------------------------------- */

.tr-timeline {
    list-style: none;
    margin: 0;
    padding: 0 0 0 1.25rem;
    border-left: 2px solid var(--bs-border-color);
}

.tr-timeline > li {
    position: relative;
    padding-bottom: 0.85rem;
}

.tr-timeline > li::before {
    content: "";
    position: absolute;
    left: -1.65rem;
    top: 0.35rem;
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    background-color: var(--tr-accent);
}

/* Logged time is the quieter half of the story; reopening is the loud one. */
.tr-timeline > li.tr-timeline-time::before {
    background-color: var(--bs-border-color);
}

.tr-timeline > li.tr-timeline-reopen::before {
    background-color: var(--bs-warning);
}

/* Anything belonging to a closed accounting period: the minutes are invoiced
   and untouchable, so they step back visually instead of disappearing. */
.tr-billed {
    opacity: 0.6;
}

/* The dot itself keeps its fill: hollowing it out made it vanish against the
   muted row. Closedness is carried by the badge and the dimming. */

/* --- board: a move is a request, and it should look like one ------------- */

/* While the server has not answered yet the card is visibly not settled. */
.tr-card-saving {
    opacity: 0.65;
    border-left-color: var(--bs-warning) !important;
}

/* And when it has: one short green flash, then back to normal. */
.tr-card-saved {
    animation: tr-saved-flash 1.1s ease-out;
}

@keyframes tr-saved-flash {
    0% { box-shadow: 0 0 0 2px var(--bs-success); }
    60% { box-shadow: 0 0 0 2px var(--bs-success); }
    100% { box-shadow: 0 0 0 2px rgba(0, 0, 0, 0); }
}

.tr-card-failed {
    border-left-color: var(--bs-danger) !important;
}

.tr-toasts {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    pointer-events: none;
}

.tr-toast {
    padding: 0.4rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    color: #fff;
    background-color: var(--bs-success);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.25);
    animation: tr-toast-in 0.15s ease-out;
}

.tr-toast.tr-toast-error {
    background-color: var(--bs-danger);
}

.tr-toast.tr-toast-pending {
    background-color: var(--bs-secondary-color);
}

@keyframes tr-toast-in {
    from { opacity: 0; transform: translateY(0.5rem); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .tr-card-saved, .tr-toast { animation: none; }
}

/* Date line between runs of cards created on the same day, borrowed from the
   way chats separate days. The rule is drawn through the label, so it reads as
   a divider even in a dense column. */
.tr-day-sep {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: .25rem 0 .5rem;
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--bs-secondary-color);
    text-transform: uppercase;
}

.tr-day-sep::before,
.tr-day-sep::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    background-color: var(--bs-border-color);
}

.tr-board-drop > .tr-day-sep:first-child {
    margin-top: 0;
}

/* --- board: "updated N s ago" next to Refresh ------------------------------ */

/* The ring fills up over the minute between two automatic refreshes and
   empties again the moment the cards are pulled. */
.tr-refresh-status {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .8rem;
    color: var(--bs-secondary-color);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* A fixed width, sized for the longest label ("Updated 59 min ago"), so the
   filters next to it do not twitch every second as the digits change. */
.tr-refresh-status .tr-refresh-label {
    display: inline-block;
    width: 8.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

.tr-refresh-ring {
    width: 1rem;
    height: 1rem;
    transform: rotate(-90deg);
}

.tr-refresh-ring circle {
    fill: none;
    stroke-width: 2.5;
}

.tr-refresh-ring-track {
    stroke: var(--bs-border-color);
}

.tr-refresh-ring-fill {
    stroke: var(--bs-primary);
    stroke-linecap: round;
    /* 2πr for r = 8; the script moves the offset from full to zero. */
    stroke-dasharray: 50.27;
    stroke-dashoffset: 50.27;
    transition: stroke-dashoffset 1s linear;
}

.tr-refresh-status.tr-refresh-busy .tr-refresh-ring {
    animation: tr-spin .8s linear infinite;
}

.tr-refresh-status.tr-refresh-busy .tr-refresh-ring-fill {
    stroke-dashoffset: 37.7;
    transition: none;
}

.tr-refresh-status.tr-refresh-failed {
    color: var(--bs-danger);
}

.tr-refresh-status.tr-refresh-failed .tr-refresh-ring-fill {
    stroke: var(--bs-danger);
}

/* The label blinks once when fresh cards have just been pulled. */
.tr-refresh-status.tr-refresh-fresh .tr-refresh-label {
    animation: tr-fresh .9s ease-out;
}

@keyframes tr-spin {
    from { transform: rotate(-90deg); }
    to { transform: rotate(270deg); }
}

@keyframes tr-fresh {
    0% { color: var(--bs-success); }
    100% { color: var(--bs-secondary-color); }
}

/* A card that was not on the board before the last refresh. */
.tr-card-new {
    animation: tr-new-glow 2.5s ease-out;
}

@keyframes tr-new-glow {
    0%, 50% { box-shadow: 0 0 0 2px var(--bs-primary); }
    100% { box-shadow: 0 0 0 2px rgba(0, 0, 0, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .tr-refresh-ring-fill { transition: none; }
    .tr-refresh-status.tr-refresh-busy .tr-refresh-ring,
    .tr-refresh-status.tr-refresh-fresh .tr-refresh-label,
    .tr-card-new { animation: none; }
}

/* Icons are a web font with font-display: block — until it arrives the glyphs
   are invisible and take the width of whatever the fallback font does with a
   private-use character. Every Bootstrap icon is 1em wide, so reserve exactly
   that and nothing moves when the font lands. */
.bi::before {
    width: 1em;
    text-align: center;
}
