/* ============================================================================
 *  theme.css — design system for team.raevolution.com
 *
 *  ONE file holds:
 *    - All design tokens (colors, spacing, radii, shadows, animation timings)
 *    - Typography (Inter font, type scale, heading rules)
 *    - Base component styles (cards, buttons, inputs, tables, flashes)
 *    - The animation/transition layer
 *    - Toast notifications
 *    - prefers-reduced-motion fallback
 *
 *  Page-specific styles still live inside their own .php files, but pull
 *  from these tokens via the CSS variables defined in :root below.
 *
 *  Linked from header.php and login.php as:
 *      <link rel="stylesheet" href="/theme.css">
 * ========================================================================== */

/* ---------------------------------------------------------------------------
 *  TOKENS
 *  Every color, radius, timing the app uses comes from here. To rebrand or
 *  tweak the palette, change these variables — nothing else.
 * --------------------------------------------------------------------------- */
:root {
    /* Brand red — primary action color */
    --red:          #d92e1f;
    --red-dark:     #b8261a;
    --red-soft:     #fdecea;
    --red-soft-2:   #f8d4d0;
    --red-grad:     linear-gradient(180deg, #ec4030 0%, #d92e1f 60%, #c0291b 100%);
    --red-grad-hov: linear-gradient(180deg, #f04a3a 0%, #e23323 60%, #ca2f1e 100%);

    /* Neutrals */
    --ink:          #1a1a1a;
    --muted:        #5a5a5a;
    --muted-2:      #8c8c8c;
    --border:       #e2e3e7;
    --border-strong:#cfd1d6;
    --card:         #ffffff;
    --bg:           #f5f6f8;

    /* Dark chrome (nav, login background) */
    --dark:         #1f1f1f;
    --dark-2:       #2a2a2a;
    --dark-line:    #353535;
    --on-dark:      #f0f0f0;
    --on-dark-mute: #a8a8a8;

    /* Semantic */
    --ok:           #2c6e2c;
    --ok-soft:      #eef7ee;
    --warn:         #8b4513;
    --warn-soft:    #fdf3e7;
    --err:          var(--red);
    --err-soft:     var(--red-soft);

    /* Calendar greens (completion states — different semantic from brand) */
    --green-me:     #bee5be;
    --green-me-ink: #1f4f1f;
    --green-team:   #4a8a4a;

    /* Radii (echoing the rounded-but-not-pill corners of the logo letters) */
    --r-sm:         3px;
    --r:            5px;
    --r-lg:         8px;
    --r-pill:       999px;

    /* Shadows */
    --shadow-1:     0 1px 2px rgba(15,15,20,0.04), 0 1px 1px rgba(15,15,20,0.04);
    --shadow-2:     0 2px 6px rgba(15,15,20,0.06), 0 1px 2px rgba(15,15,20,0.04);
    --shadow-3:     0 6px 18px rgba(15,15,20,0.08), 0 2px 4px rgba(15,15,20,0.05);
    --shadow-focus: 0 0 0 3px rgba(217,46,31,0.18);

    /* Animation timings — kept short so the app stays snappy */
    --t-fast:       120ms;
    --t-med:        200ms;
    --t-slow:       280ms;
    --ease:         cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out:     cubic-bezier(0.16, 1, 0.3, 1);
}


/* ---------------------------------------------------------------------------
 *  RESET + BASE
 * --------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Headings — slightly tightened tracking to echo the wordmark */
h1, h2, h3, h4 {
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--ink);
}
h1.page {
    font-size: 1.5rem;
    margin: 0 0 1rem;
    color: var(--ink);
    letter-spacing: -0.015em;
}
h2 {
    font-size: 1.05rem;
    letter-spacing: -0.005em;
    text-transform: none;
}
h3 {
    font-size: 1rem;
    letter-spacing: -0.005em;
}


/* ---------------------------------------------------------------------------
 *  LAYOUT — main content area
 * --------------------------------------------------------------------------- */
main {
    max-width: 980px;
    margin: 1.5rem auto 3rem;
    padding: 0 1.5rem;
}


/* ---------------------------------------------------------------------------
 *  TOP NAV (the dark bar)
 * --------------------------------------------------------------------------- */
header.site {
    background: var(--dark);
    border-bottom: 1px solid var(--dark-line);
    color: var(--on-dark);
    padding: 0.55rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 50;
}
header.site .brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    text-decoration: none;
    color: var(--on-dark);
    transition: opacity var(--t-fast) var(--ease);
}
header.site .brand:hover { opacity: 0.85; text-decoration: none; }
header.site .brand-mark {
    width: 28px;
    height: 28px;
    object-fit: contain;
    display: block;
}
header.site .brand-wordmark {
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
header.site .brand-wordmark .word-ra { color: var(--red); }
header.site .brand-wordmark .word-team {
    color: var(--on-dark-mute);
    font-weight: 500;
    letter-spacing: 0.02em;
    margin-left: 0.25rem;
}

header.site nav {
    display: flex;
    align-items: center;
    gap: 1.3rem;
    font-size: 0.93rem;
}
header.site nav a {
    position: relative;
    color: var(--on-dark-mute);
    text-decoration: none;
    padding: 0.35rem 0;
    transition: color var(--t-fast) var(--ease);
}
header.site nav a:hover { color: var(--on-dark); text-decoration: none; }
header.site nav a::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -3px;
    height: 2px;
    background: var(--red-grad);
    border-radius: 2px;
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform var(--t-med) var(--ease-out);
}
header.site nav a:hover::after { transform: scaleX(1); }
header.site nav a.active {
    color: var(--on-dark);
    font-weight: 600;
}
header.site nav a.active::after { transform: scaleX(1); }

header.site .user {
    color: var(--on-dark-mute);
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
header.site .user strong { color: var(--on-dark); font-weight: 600; }
header.site .user a {
    color: var(--on-dark-mute);
    text-decoration: none;
    transition: color var(--t-fast) var(--ease);
}
header.site .user a:hover { color: var(--on-dark); text-decoration: none; }


/* ---------------------------------------------------------------------------
 *  BADGES
 * --------------------------------------------------------------------------- */
.badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 0.15rem 0.5rem;
    border-radius: var(--r-sm);
    vertical-align: middle;
}
.badge-admin    { background: var(--red-soft); color: var(--red-dark); }
.badge-inactive { background: #eee; color: #777; }

/* Top-nav unread badge (gradient red) */
.badge-notes {
    background: var(--red-grad);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.1rem 0.5rem;
    border-radius: var(--r-pill);
    margin-left: 0.3rem;
    vertical-align: middle;
    display: none;
    box-shadow: 0 1px 3px rgba(217,46,31,0.4);
}
.badge-notes.visible { display: inline-block; animation: badgePulse 1.2s var(--ease-out); }

@keyframes badgePulse {
    0%   { transform: scale(0.6); opacity: 0; }
    50%  { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1);   opacity: 1; }
}


/* ---------------------------------------------------------------------------
 *  CARDS (panels with white background — main content blocks)
 * --------------------------------------------------------------------------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-1);
    /* card-enter is added by JS on page-load stagger */
}
.card h2 {
    margin: 0 0 0.85rem;
    font-size: 1.02rem;
    color: var(--ink);
}

/* Subtle staggered fade-in on first paint */
.card.card-enter {
    animation: cardEnter 360ms var(--ease-out) both;
}
@keyframes cardEnter {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}


/* ---------------------------------------------------------------------------
 *  FLASHES (success / error / warning banners at top of page)
 * --------------------------------------------------------------------------- */
.flash {
    padding: 0.7rem 0.95rem;
    border-radius: var(--r);
    border: 1px solid;
    margin-bottom: 1rem;
    font-size: 0.92rem;
    animation: flashIn 240ms var(--ease-out);
}
.flash-ok   { background: var(--ok-soft);   color: var(--ok);  border-color: #b9dab9; }
.flash-err  { background: var(--err-soft);  color: var(--err); border-color: var(--red-soft-2); }
.flash-warn { background: var(--warn-soft); color: var(--warn);border-color: #ead4b1; }
@keyframes flashIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}


/* ---------------------------------------------------------------------------
 *  TABLES
 * --------------------------------------------------------------------------- */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.93rem;
}
th, td {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
th {
    color: var(--muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
tbody tr:last-child td { border-bottom: none; }


/* ---------------------------------------------------------------------------
 *  FORMS
 * --------------------------------------------------------------------------- */
label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin: 0.8rem 0 0.3rem;
    color: var(--ink);
}
input[type="text"], input[type="password"], input[type="email"],
input[type="file"], input[type="date"], textarea, select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
    transition: border-color var(--t-fast) var(--ease),
                box-shadow var(--t-fast) var(--ease);
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--red);
    box-shadow: var(--shadow-focus);
}


/* ---------------------------------------------------------------------------
 *  BUTTONS
 *  - Primary buttons use the brand gradient
 *  - Secondary buttons are outlined in red
 *  - Danger reuses primary (already red)
 *  - Subtle lift on hover, push on press
 * --------------------------------------------------------------------------- */
.btn, button {
    display: inline-block;
    padding: 0.55rem 1.1rem;
    font-size: 0.92rem;
    font-weight: 600;
    color: #fff;
    background: var(--red-grad);
    border: none;
    border-radius: var(--r);
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
    line-height: 1.2;
    box-shadow: 0 1px 2px rgba(184,38,26,0.2), 0 1px 1px rgba(15,15,20,0.04);
    transition: transform var(--t-fast) var(--ease),
                box-shadow var(--t-fast) var(--ease),
                background var(--t-fast) var(--ease),
                opacity var(--t-fast) var(--ease);
    will-change: transform;
}
.btn:hover, button:hover {
    background: var(--red-grad-hov);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(184,38,26,0.28), 0 1px 2px rgba(15,15,20,0.05);
    text-decoration: none;
    color: #fff;
}
.btn:active, button:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(184,38,26,0.2);
}
.btn:disabled, button:disabled, .btn[disabled], button[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
}

.btn-secondary {
    background: #fff;
    color: var(--red);
    border: 1px solid var(--red);
    box-shadow: none;
}
.btn-secondary:hover {
    background: var(--red-soft);
    color: var(--red-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-1);
}

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border-strong);
    box-shadow: none;
}
.btn-ghost:hover {
    background: #fff;
    color: var(--ink);
    border-color: var(--border-strong);
    transform: translateY(-1px);
}

.btn-danger { background: var(--red-grad); }  /* same as primary */

.btn-sm {
    padding: 0.32rem 0.65rem;
    font-size: 0.82rem;
}


/* ---------------------------------------------------------------------------
 *  UTILITY
 * --------------------------------------------------------------------------- */
.muted     { color: var(--muted); font-size: 0.88rem; }
.muted-sm  { color: var(--muted-2); font-size: 0.82rem; }
.stack > * + * { margin-top: 0.5rem; }
.row-actions { display: inline-flex; gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; }
.row-actions form { display: inline; }

.password-display {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 1.05rem;
    background: #fff8d6;
    border: 1px dashed #c8b97a;
    padding: 0.55rem 0.8rem;
    border-radius: var(--r);
    display: inline-block;
    user-select: all;
}


/* ---------------------------------------------------------------------------
 *  PRESENCE — "last active" indicators
 * --------------------------------------------------------------------------- */
.presence {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: var(--muted);
    white-space: nowrap;
}
.presence-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--muted-2);
}
.presence-online .presence-dot,
.presence-dot.presence-online {
    background: #34a853;
    box-shadow: 0 0 0 3px rgba(52,168,83,0.18);
}
.presence-away .presence-dot,
.presence-dot.presence-away {
    background: var(--muted-2);
}
.presence-never .presence-dot,
.presence-dot.presence-never {
    background: #d0d0d0;
}
.presence-label { line-height: 1; }

/* Online dot gets a soft pulse so "someone's here right now" reads at a glance */
.presence-dot.presence-online { animation: presencePulse 2.4s var(--ease) infinite; }
@keyframes presencePulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(52,168,83,0.18); }
    50%      { box-shadow: 0 0 0 5px rgba(52,168,83,0.08); }
}

/* The team roster card on the dashboard */
.team-roster {
    list-style: none;
    padding: 0;
    margin: 0;
}
.team-roster li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}
.team-roster li:last-child { border-bottom: none; }
.team-roster .roster-name {
    font-weight: 600;
    font-size: 0.93rem;
}
.team-roster .roster-name .roster-you {
    font-weight: 400;
    color: var(--muted);
    font-size: 0.85rem;
}


/* ---------------------------------------------------------------------------
 *  TASK CONTROL RAIL
 *  Two side-by-side, full-row-height buttons (toggle + star) sitting flush
 *  on the left of a task row. Shared by the dashboard, call detail, and
 *  watchlist pages so task controls look and behave identically everywhere.
 *
 *  Structure expected:
 *    <li class="trow">
 *      <div class="task-rail">
 *        <button class="rail-btn rail-toggle"> ... </button>
 *        <button class="rail-btn rail-star"> ... </button>
 *      </div>
 *      <div class="trow-body"> ...task text, meta, details... </div>
 *    </li>
 * --------------------------------------------------------------------------- */
.trow {
    display: flex;
    flex-wrap: wrap;             /* only the details panel wraps to its own line */
    align-items: stretch;        /* rail stretches to full row height */
    gap: 0;                      /* gap removed: it caused rail+body to wrap apart */
    padding: 0;
    border-bottom: 1px solid var(--border);
    transition: opacity 0.25s var(--ease), transform 0.25s var(--ease),
                background 0.24s var(--ease), border-color 0.24s var(--ease);
}
.trow:last-child { border-bottom: none; }
.trow.fading-out { opacity: 0; transform: translateX(8px); }
/* The details panel, when present as a child of .trow, takes its own line.
   It carries a 42px left margin (set per-page) to align under the body, so
   its basis subtracts that to avoid overflowing the row on the right. */
.trow > .task-details-panel { flex: 0 0 calc(100% - 42px); }

.task-rail {
    display: flex;
    align-items: stretch;
    align-self: stretch;         /* rail fills the row's full height */
    flex-shrink: 0;
    border-right: 1px solid var(--border);
}
.rail-btn {
    /* reset button chrome */
    background: none;
    border: none;
    box-shadow: none;
    margin: 0;
    padding: 0;
    /* sizing — a proper square-ish target, full row height */
    width: 42px;
    align-self: stretch;         /* button fills the rail's height */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    color: var(--muted-2);
    transition: background var(--t-fast) var(--ease),
                color var(--t-fast) var(--ease),
                transform var(--t-fast) var(--ease);
}
.rail-btn:hover { transform: none; box-shadow: none; }
.rail-btn + .rail-btn { border-left: 1px solid var(--border); }

/* --- toggle button --- */
.rail-toggle { color: var(--muted-2); }
.rail-toggle:hover { background: var(--ok-soft); color: var(--ok); }
.rail-toggle .rail-icon-done   { display: none; }
.rail-toggle .rail-icon-open   { display: block; }
.rail-toggle.is-done           { color: var(--ok); background: var(--ok-soft); }
.rail-toggle.is-done .rail-icon-done { display: block; }
.rail-toggle.is-done .rail-icon-open { display: none; }
/* read-only variant (someone else's task — shows status, no interaction) */
.rail-toggle.readonly {
    cursor: default;
    opacity: 0.7;
}
.rail-toggle.readonly:hover { background: none; color: var(--muted-2); }
.rail-toggle.readonly.is-done:hover { color: var(--ok); }

/* --- star button --- */
.rail-star { color: #c2c2c2; }
.rail-star:hover { background: #fff8e1; color: #d9a400; }
.rail-star.starred { color: #e1b300; }
.rail-star.starred:hover { color: #c99700; }
.rail-star.popping { animation: starPop 280ms var(--ease-out); }
@keyframes starPop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.32); }
    100% { transform: scale(1); }
}

/* the body to the right of the rail */
.trow-body {
    flex: 1 1 0;                 /* basis 0 so it never forces a wrap */
    min-width: 0;                /* allow text to truncate properly */
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.6rem 0 0.6rem 0.85rem;   /* left pad replaces the removed flex gap */
}
/* The body is clickable to expand Details. The cursor + hover tint make
   that discoverable. The rail buttons, the Details button and any links
   inside stop propagation so they keep their own behaviour. */
.trow-body.is-clickable { cursor: pointer; }
.trow:hover > .trow-body.is-clickable { background: rgba(15,15,20,0.015); }

/* Task text — single line, truncated with an ellipsis when too long.
   The full text is always available in the Details panel, and on desktop
   also via the native hover tooltip (title attribute). */
.task-text,
.task-text-detail {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.5;
}
.task-text.strike,
.trow.done .task-text-detail {
    text-decoration: line-through;
    color: var(--muted);
}

/* Full task text shown at the top of the Details panel — wraps fully. */
.details-full-text {
    font-weight: 600;
    line-height: 1.45;
    margin-bottom: 0.7rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
    white-space: normal;
    word-wrap: break-word;
}
.details-full-text.strike,
.trow.done .details-full-text {
    text-decoration: line-through;
    color: var(--muted);
    font-weight: 500;
}

/* completion + note-state row highlights (applied to .trow) */
.trow.just-done   { animation: rowDoneFlash 420ms var(--ease-out); }
@keyframes rowDoneFlash {
    0%   { background-color: transparent; }
    40%  { background-color: rgba(44,110,44,0.16); }
    100% { background-color: transparent; }
}
.trow.has-notes {
    box-shadow: inset 3px 0 0 0 #6f9fc7;
    background: linear-gradient(to right, rgba(111,159,199,0.09), transparent 38%);
}
.trow.has-unread {
    box-shadow: inset 3px 0 0 0 var(--red);
    background: linear-gradient(to right, rgba(217,46,31,0.09), transparent 42%);
}
/* When a row has the colored left border, keep the rail border tidy */
.trow.has-notes .task-rail,
.trow.has-unread .task-rail { border-right-color: var(--border); }

@media (max-width: 520px) {
    .rail-btn { width: 38px; font-size: 1.1rem; }
}


/* ---------------------------------------------------------------------------
 *  TOAST NOTIFICATIONS (replace browser alert())
 * --------------------------------------------------------------------------- */
#toast-host {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 200;
    pointer-events: none;
}
.toast {
    background: var(--ink);
    color: #fff;
    padding: 0.7rem 1rem;
    border-radius: var(--r);
    font-size: 0.9rem;
    box-shadow: var(--shadow-3);
    max-width: 360px;
    pointer-events: auto;
    animation: toastIn 260ms var(--ease-out);
    border-left: 3px solid var(--red);
}
.toast.is-leaving { animation: toastOut 220ms var(--ease) forwards; }
.toast.toast-ok   { border-left-color: var(--ok); }
.toast.toast-warn { border-left-color: var(--warn); }
.toast.toast-err  { border-left-color: var(--red); }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(10px) translateX(10px); }
    to   { opacity: 1; transform: translateY(0) translateX(0); }
}
@keyframes toastOut {
    to { opacity: 0; transform: translateY(0) translateX(20px); }
}


/* ---------------------------------------------------------------------------
 *  ACCESSIBILITY — respect reduced-motion preference
 *  Strip all animations and transitions to bare minimum.
 * --------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}


/* ---------------------------------------------------------------------------
 *  RESPONSIVE — mobile tweaks
 * --------------------------------------------------------------------------- */
@media (max-width: 640px) {
    header.site {
        padding: 0.45rem 0.85rem;
        gap: 0.4rem;
    }
    header.site nav {
        order: 3;
        flex-basis: 100%;
        gap: 1rem;
        font-size: 0.88rem;
        padding-top: 0.25rem;
        border-top: 1px solid var(--dark-line);
        margin-top: 0.25rem;
    }
    header.site .user { font-size: 0.82rem; }
    header.site .brand-wordmark .word-team { display: none; }
    main { padding: 0 0.85rem; margin: 1rem auto 2rem; }
    .card { padding: 1rem 1.1rem; }
    h1.page { font-size: 1.25rem; }
}
