:root {
    --ff-red: #a72920;
    --ff-red-dark: #8b0a1f;
    --ff-black: #1a1a1a;
    --ff-grey: #595959;
    --ff-bg: #f5f5f5;
    --ff-surface: #ffffff;
    --ff-border: #e2e2e2;
    --ff-error-bg: #fdecef;
    --ff-error-fg: #8b0a1f;
    --ff-success-bg: #e6f4ea;
    --ff-success-fg: #1e6f3c;
}

* { box-sizing: border-box; }
input, select, textarea, button { font-family: 'Roboto Condensed', Arial, sans-serif; }
input[type="file"]::file-selector-button,
input[type="file"]::-webkit-file-upload-button { font-family: 'Roboto Condensed', Arial, sans-serif; }
body {
    margin: 0;
    font-family: 'Roboto Condensed', Arial, sans-serif;
    background: var(--ff-bg);
    color: var(--ff-black);
}
h1, h2, h3 { font-family: 'Roboto Condensed', Arial, sans-serif; font-weight: 700; letter-spacing: .3px; }
a { color: var(--ff-red); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex; align-items: center; gap: 1rem;
    padding: .9rem 1.2rem;
    background: var(--ff-red);
    color: #fff;
    border-bottom: 3px solid var(--ff-red-dark);
}
.topbar a, .topbar .user { color: #fff; }
.topbar .brand {
    font-family: 'Roboto Condensed', Arial, sans-serif;
    font-weight: 700;
    font-size: 1.15rem;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.topbar nav { display: flex; gap: 1.2rem; flex: 1; }
.topbar nav a { font-weight: 600; }
.topbar form.logout { display: flex; align-items: center; gap: .6rem; margin: 0; }
.topbar button {
    background: rgba(255,255,255,.18);
    color: #fff; border: 1px solid rgba(255,255,255,.35);
    padding: .35rem .8rem; border-radius: 6px;
    cursor: pointer; font: inherit;
}
.topbar button:hover { background: rgba(255,255,255,.28); }

main { padding: 1.2rem; }

/* Board view controls */
.board-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    margin-bottom: .8rem;
    padding: .5rem .75rem;
    background: var(--ff-surface);
    border: 1px solid var(--ff-border);
    border-radius: 6px;
    font-size: .85rem;
    color: var(--ff-grey);
}
.board-controls .view-opt { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; }
.board-controls input[type=checkbox] { accent-color: var(--ff-red); }
.board-controls select {
    font: inherit;
    color: var(--ff-black);
    background: #fff;
    border: 1px solid var(--ff-border);
    border-radius: 6px;
    padding: .25rem .5rem;
}
.board-controls select:focus {
    outline: none;
    border-color: var(--ff-red);
    box-shadow: 0 0 0 2px rgba(200,16,46,.15);
}

/* Board */
.board { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 1rem; }

/* Swimlane layout */
.board.swimlanes { display: flex; flex-direction: column; gap: 1rem; }
.swimlane {
    background: var(--ff-surface);
    border: 1px solid var(--ff-border);
    border-left: 3px solid var(--ff-red);
    border-radius: 6px;
    padding: .6rem .8rem .8rem;
}
.swimlane-header {
    font-family: 'Roboto Condensed', Arial, sans-serif;
    font-weight: 700;
    font-size: .85rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--ff-black);
    padding: .2rem 0 .5rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    cursor: pointer;
    user-select: none;
}
.swimlane-header .lane-toggle {
    background: none;
    border: none;
    padding: 0;
    color: var(--ff-grey);
    font: inherit;
    cursor: pointer;
    width: 1.4rem;
    text-align: center;
}
.swimlane-header .lane-toggle::before { content: '▾'; display: inline-block; font-size: 1.5rem; line-height: 1; transition: transform .15s; }
.swimlane.collapsed .swimlane-header .lane-toggle::before { transform: rotate(-90deg); }
.swimlane.collapsed .swimlane-columns { display: none; }
.swimlane-columns {
    display: grid;
    grid-template-columns: repeat(5, minmax(180px, 1fr));
    gap: .6rem;
}
.swimlane .column { max-height: none; }
.swimlane .cards { min-height: 60px; }

/* "My tasks only" filter — hide cards assigned to others; dim unassigned ones */
.board.filter-mine .card:not(.mine):not(.unassigned) { display: none; }
.board.filter-mine .card.unassigned:not(.mine) { opacity: .45; }
.board.filter-mine .card.unassigned:not(.mine):hover { opacity: .75; }

/* In assignee-swimlane mode the filter operates on whole lanes:
   keep only the current user's lane and the unassigned lane visible. */
.board.swimlanes-assignee.filter-mine .swimlane:not(.mine-lane):not(.unassigned-lane) { display: none; }
.board.swimlanes-assignee.filter-mine .swimlane.unassigned-lane { opacity: .65; }
.column {
    background: #ececec;
    border: 1px solid var(--ff-border);
    border-radius: 6px;
    display: flex; flex-direction: column;
    max-height: calc(100vh - 140px);
}
.column header { display: flex; justify-content: space-between; align-items: center; padding: .7rem .9rem; }
.column h2 {
    margin: 0;
    font-family: 'Roboto Condensed', Arial, sans-serif;
    font-size: .85rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .6px;
    color: var(--ff-grey);
}
.column .add-task {
    background: none; border: none;
    font-size: 1.4rem; cursor: pointer;
    color: var(--ff-red); line-height: 1;
}
.cards { flex: 1; padding: 0 .6rem .6rem; overflow-y: auto; min-height: 40px; }

.card {
    background: var(--ff-surface);
    border: 1px solid var(--ff-border);
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
    padding: .55rem .7rem;
    margin-bottom: .5rem;
    cursor: pointer;
}
.card:hover { background: #fafafa; }
.card h3.card-title {
    margin: 0 0 .3rem;
    font-family: 'Roboto Condensed', Arial, sans-serif;
    font-size: .95rem; font-weight: 600;
}
.card-desc {
    margin: 0 0 .4rem;
    font-size: .8rem;
    color: var(--ff-grey);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
}
.card-meta { display: flex; flex-wrap: wrap; gap: .3rem; font-size: .75rem; color: var(--ff-grey); }
.chip { background: #e6e6e6; color: var(--ff-black); padding: 1px 8px; border-radius: 10px; }
.due.overdue, .card.overdue .due { color: var(--ff-red); font-weight: 700; }
.card.overdue { border-left: 3px solid var(--ff-red); }

@media (hover: none) and (pointer: coarse) {
    .card { cursor: default; }
    .card h3.card-title {
        cursor: grab;
        touch-action: none;
        padding: .35rem .5rem;
        margin: -.2rem -.2rem .3rem;
        background: rgba(0,0,0,.03);
        border-radius: 6px;
    }
    .card h3.card-title:active { cursor: grabbing; }
}

/* Modal */
.modal {
    position: fixed; inset: 0;
    background: rgba(26,26,26,.55);
    display: flex; justify-content: center;
    overflow-y: auto;
    z-index: 100;
}
.modal-body { margin: auto 0; }
.modal.hidden { display: none; }
.modal-body {
    background: var(--ff-surface);
    border-radius: 6px;
    padding: 1.6rem; width: 100%; max-width: 480px;
    position: relative;
    box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.modal .close {
    position: absolute; top: .5rem; right: .6rem;
    background: none; border: none;
    font-size: 1.4rem; cursor: pointer; color: var(--ff-grey);
}
.modal h2 { margin-top: 0; font-family: 'Roboto Condensed', Arial, sans-serif; }
.modal form label { display: block; margin-bottom: .8rem; font-size: .85rem; color: var(--ff-grey); }
.modal form input[type=text], .modal form input[type=date], .modal form input[type=password],
.modal form textarea, .modal form select {
    display: block; width: 100%; margin-top: .25rem; padding: .45rem .55rem;
    border: 1px solid var(--ff-border); border-radius: 6px; font: inherit;
    background: #fff;
}
.modal form input:focus, .modal form textarea:focus, .modal form select:focus {
    outline: none; border-color: var(--ff-red);
    box-shadow: 0 0 0 2px rgba(200,16,46,.15);
}
.modal .row { display: flex; gap: .8rem; }
.modal .row label { flex: 1; }
.modal .actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.1rem; }
.modal .actions button {
    padding: .5rem 1.1rem; border: none; border-radius: 6px;
    cursor: pointer; background: var(--ff-red); color: #fff;
    font: inherit; font-weight: 600;
}
.modal .actions button:hover { background: var(--ff-red-dark); }
.modal .actions button.danger { margin-right: auto; }
.modal .actions button.hidden { display: none; }
.modal.is-busy .modal-body { pointer-events: none; cursor: wait; }
.modal.is-busy .modal-body > * { opacity: .65; }
.modal.is-busy::after {
    content: ''; position: absolute; inset: 0;
}

.task-history { margin-top: 1.4rem; border-top: 1px solid var(--ff-border); padding-top: .9rem; }
.task-history.hidden { display: none; }
.task-history h3 { margin: 0 0 .6rem; font-size: .95rem; font-family: 'Roboto Condensed', Arial, sans-serif; }
.task-history .history-list { list-style: none; padding: 0; margin: 0; }
.task-history .history-list li { padding: .4rem 0; border-bottom: 1px solid var(--ff-border); }
.task-history .history-list li:last-child { border-bottom: none; }
.task-history .history-meta { font-size: .75rem; color: var(--ff-grey); }
.task-history .history-body { font-size: .85rem; }
.task-history .history-older.hidden { display: none; }
.section-toggle { display: flex; align-items: center; gap: .5rem; cursor: pointer; user-select: none; }
.section-toggle-btn { background: none; border: none; padding: 0; color: var(--ff-grey); font: inherit; cursor: pointer; width: 1.4rem; text-align: center; }
.section-toggle-btn::before { content: '▾'; display: inline-block; font-size: 1.5rem; line-height: 1; transition: transform .15s; }
.collapsed > .section-toggle .section-toggle-btn::before { transform: rotate(-90deg); }
.collapsed > .section-body { display: none; }
.task-history .history-toggle { padding: .4rem 0; border-bottom: 1px solid var(--ff-border); }
.task-history .history-toggle-btn { background: none; border: none; padding: 0; color: var(--ff-accent, #2563eb); cursor: pointer; font: inherit; font-size: .8rem; }
.task-history .history-toggle-btn:hover { text-decoration: underline; }

/* Admin */
.admin {
    max-width: 1500px; margin: 0 auto;
    background: var(--ff-surface);
    border: 1px solid var(--ff-border);
    border-top: 4px solid var(--ff-red);
    padding: 1.6rem; border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.admin h1 { margin-top: 0; font-family: 'Roboto Condensed', Arial, sans-serif; }
.admin table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.admin th, .admin td {
    padding: .55rem; border-bottom: 1px solid var(--ff-border);
    text-align: left; font-size: .9rem; vertical-align: middle;
}
.admin th { font-family: 'Roboto Condensed', Arial, sans-serif; text-transform: uppercase; font-size: .75rem; letter-spacing: .5px; color: var(--ff-grey); }
.inline-form { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin: 0; }
.inline-form input, .inline-form select {
    padding: .35rem .55rem; border: 1px solid var(--ff-border);
    border-radius: 6px; font: inherit;
}
.inline-form button,
.admin form > button[type="submit"] {
    padding: .35rem .9rem; background: var(--ff-red); color: #fff;
    border: none; border-radius: 6px; cursor: pointer; font: inherit; font-weight: 600;
}
.inline-form button:hover,
.admin form > button[type="submit"]:hover { background: var(--ff-red-dark); }

/* Danger button — secondary/destructive, readable on all surfaces */
button.danger, .inline-form button.danger, .modal .actions button.danger {
    background: #4a4a4a;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: .5rem 1.1rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
button.danger:hover, .inline-form button.danger:hover, .modal .actions button.danger:hover {
    background: #2a2a2a;
}
.inline-form button.danger { padding: .35rem .9rem; }

/* Login */
.login-card {
    max-width: 340px; margin: 4rem auto;
    background: var(--ff-surface);
    border-top: 4px solid var(--ff-red);
    padding: 1.8rem; border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,.08);
}
.login-card h1 { margin-top: 0; font-family: 'Roboto Condensed', Arial, sans-serif; }
.login-card label { display: block; margin-bottom: .9rem; font-size: .85rem; color: var(--ff-grey); }
.login-card input {
    display: block; width: 100%; margin-top: .25rem; padding: .5rem .55rem;
    border: 1px solid var(--ff-border); border-radius: 6px; font: inherit;
}
.login-card input:focus {
    outline: none; border-color: var(--ff-red);
    box-shadow: 0 0 0 2px rgba(200,16,46,.15);
}
.login-card button {
    width: 100%; padding: .6rem;
    background: var(--ff-red); color: #fff;
    border: none; border-radius: 6px; cursor: pointer;
    font: inherit; font-size: 1rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .5px;
}
.login-card button:hover { background: var(--ff-red-dark); }

.error { background: var(--ff-error-bg); color: var(--ff-error-fg); padding: .6rem .9rem; border-radius: 6px; border-left: 3px solid var(--ff-red); }
.success { background: var(--ff-success-bg); color: var(--ff-success-fg); padding: .6rem .9rem; border-radius: 6px; border-left: 3px solid var(--ff-success-fg); }

.sortable-ghost { opacity: .3; }
.sortable-drag { opacity: .9; }

/* Suppress transient scrollbars while dragging a card */
body.is-dragging .cards { overflow: hidden; }

/* Tablet */
@media (max-width: 1024px) {
    .board { grid-template-columns: repeat(2, minmax(260px, 1fr)); }
    .column { max-height: none; }
}

/* Phone */
@media (max-width: 640px) {
    main { padding: .8rem; }

    .topbar {
        flex-wrap: wrap;
        gap: .6rem;
        padding: .7rem .9rem;
    }
    .topbar .brand { font-size: 1rem; flex: 1 1 auto; }
    .topbar nav {
        order: 3;
        flex-basis: 100%;
        gap: .9rem;
        font-size: .9rem;
    }
    .topbar form.logout { gap: .4rem; }
    .topbar .user { font-size: .85rem; }

    .board {
        grid-template-columns: 1fr;
        gap: .8rem;
    }
    .column { max-height: none; }
    .cards { max-height: 60vh; }
    .swimlane-columns { grid-template-columns: 1fr; }

    .modal { padding: .8rem; }
    .modal-body {
        padding: 1.1rem;
        max-width: 100%;
        max-height: calc(100vh - 1.6rem);
        overflow-y: auto;
    }
    .modal .row { flex-direction: column; gap: 0; }
    .modal .actions { flex-wrap: wrap; }
    .modal .actions button { flex: 1 1 auto; min-width: 44%; }
    .modal .actions button.danger { flex-basis: 100%; margin-right: 0; order: 99; }

    .admin { padding: 1rem; }
    .admin table, .admin thead, .admin tbody, .admin tr, .admin th, .admin td {
        display: block; width: 100%;
    }
    .admin thead { display: none; }
    .admin tr {
        border-bottom: 1px solid var(--ff-border);
        padding: .6rem 0;
    }
    .admin td { border: none; padding: .25rem 0; }
    .inline-form { width: 100%; }
    .inline-form input, .inline-form select { flex: 1 1 100%; }

    .login-card {
        margin: 1.5rem auto;
        padding: 1.3rem;
        max-width: 100%;
    }

    /* Tap target comfort */
    button, .add-task { min-height: 38px; }
    .add-task { min-width: 38px; }
    .card { padding: .7rem .8rem; }
}

.info { background: var(--ff-success-bg); color: var(--ff-success-fg); padding: .6rem .9rem; border-radius: 6px; border-left: 3px solid var(--ff-success-fg); }
.muted { color: #666; font-size: .9em; }
.login-card label.remember { display: flex; align-items: center; gap: .4rem; font-weight: normal; }
.login-card label.remember input { width: auto; }

/* Attachments */
.attach-indicator {
    display: inline-flex;
    align-items: center;
    gap: .15rem;
    font-size: .8rem;
    font-weight: 600;
    color: var(--ff-grey, #555);
    margin-left: .1rem;
}
.attach-icon {
    width: 16px;
    height: 16px;
    display: block;
}
.task-attachments { margin-top: 1rem; border-top: 1px solid var(--ff-border); padding-top: .6rem; }
.task-attachments h3 { margin: 0 0 .4rem; font-size: 1rem; }
.attach-list { list-style: none; padding: 0; margin: 0 0 .6rem; }
.attach-item {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .2rem 0;
    border-bottom: 1px solid var(--ff-border);
}
.attach-item:last-child { border-bottom: none; }
.attach-item a { flex: 1 1 auto; word-break: break-all; }
.attach-meta { color: #666; font-size: .85em; }
.attach-delete {
    background: #4a4a4a;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: .15rem .5rem;
    font: inherit;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
}
.attach-delete:hover { background: #2a2a2a; }
.attach-form {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
}
.attach-form input[type="file"] {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
    padding: .35rem .55rem;
    border: 1px solid var(--ff-border);
    border-radius: 6px;
    font: inherit;
    background: #fff;
    box-sizing: border-box;
}
.attach-form button {
    padding: .5rem 1.1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    background: var(--ff-red);
    color: #fff;
    font: inherit;
    font-weight: 600;
}
.attach-form button:hover { background: var(--ff-red-dark); }
.attach-hint { color: #666; font-size: .85em; }
.attach-progress {
    flex-basis: 100%;
    width: 100%;
    height: 8px;
    margin-bottom: .2rem;
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid var(--ff-border);
    border-radius: 6px;
    background: #eee;
    overflow: hidden;
}
.attach-progress.hidden { display: none; }
.attach-progress::-webkit-progress-bar { background: #eee; }
.attach-progress::-webkit-progress-value { background: var(--ff-red); transition: width .15s linear; }
.attach-progress::-moz-progress-bar { background: var(--ff-red); }
.attach-empty, .attach-loading, .attach-error { color: #666; font-style: italic; list-style: none; }
.attach-error { color: #a72920; }

/* Global top progress bar */
.global-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: transparent;
    opacity: 0;
    pointer-events: none;
    z-index: 10000;
    transition: opacity .15s ease;
    overflow: hidden;
}
.global-progress.active { opacity: 1; }
.global-progress::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, transparent, #fff, transparent);
    animation: global-progress-slide 1.2s linear infinite;
}
@keyframes global-progress-slide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}
@media (prefers-reduced-motion: reduce) {
    .global-progress::before {
        animation: none;
        width: 100%;
        background: #fff;
        opacity: .8;
    }
}

/* Button loading state */
button.is-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
    cursor: progress;
}
button.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1em;
    height: 1em;
    margin: -0.5em 0 0 -0.5em;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: button-spin .7s linear infinite;
    box-sizing: border-box;
}
@keyframes button-spin {
    to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
    button.is-loading::after { animation-duration: 2s; }
}
