/* ========================================================================
   FreeSurfer Monitor — Custom CSS
   ======================================================================== */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-bg:        #f4f6f9;
    --color-surface:   #ffffff;
    --color-header:    #1a2332;
    --color-text:      #1f2937;
    --color-muted:     #6b7280;
    --color-border:    #e5e7eb;

    --color-running:   #2563eb;
    --color-running-bg: #eff6ff;
    --color-done:      #16a34a;
    --color-done-bg:   #f0fdf4;
    --color-error:     #dc2626;
    --color-error-bg:  #fef2f2;
    --color-idle:      #6b7280;
    --color-idle-bg:   #f9fafb;

    --radius:          8px;
    --shadow:          0 1px 4px rgba(0,0,0,.08), 0 2px 12px rgba(0,0,0,.05);
    --font:            system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---- Header ---- */

.site-header {
    background: var(--color-header);
    color: #fff;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: space-between;
}

.site-title {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: .01em;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.back-link {
    color: rgba(255,255,255,.7);
    text-decoration: none;
    font-size: 1.2rem;
    transition: color .15s;
}
.back-link:hover { color: #fff; }

.header-meta {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: .82rem;
    color: rgba(255,255,255,.7);
    white-space: nowrap;
}

.header-meta strong { color: #fff; }
.separator { opacity: .4; }

.btn-refresh {
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.2);
    color: #fff;
    border-radius: 4px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    transition: background .15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-refresh:hover { background: rgba(255,255,255,.22); }

/* ---- Main layout ---- */

.main-content {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1.5rem 2rem;
}

/* ---- Status bar ---- */

.status-bar {
    padding: .6rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.2rem;
    font-size: .875rem;
    font-weight: 500;
}
.status-bar.status-bar--error { background: var(--color-error-bg); color: var(--color-error); border: 1px solid #fecaca; }
.status-bar.status-bar--info  { background: var(--color-running-bg); color: var(--color-running); border: 1px solid #bfdbfe; }
.hidden { display: none !important; }

/* ---- Subject grid ---- */

.subject-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 600px) {
    .subject-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1000px) {
    .subject-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---- Subject card ---- */

.subject-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem 1.2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    transition: box-shadow .15s;
    text-decoration: none;
    color: inherit;
}
.subject-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,.1);
    border-color: #c7d2fe;
}

.card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .5rem;
}

.card-name {
    font-size: 1rem;
    font-weight: 600;
    word-break: break-all;
    line-height: 1.3;
}

.card-stage {
    font-size: .8rem;
    color: var(--color-muted);
    min-height: 1.1em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-elapsed {
    font-size: .78rem;
    color: var(--color-muted);
}

/* ---- Progress bar ---- */

.progress-wrap {
    height: 6px;
    background: var(--color-border);
    border-radius: 99px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--color-running);
    border-radius: 99px;
    transition: width .4s ease;
}

.progress-bar--animated {
    background: repeating-linear-gradient(
        -45deg,
        var(--color-running) 0px,
        var(--color-running) 8px,
        #60a5fa 8px,
        #60a5fa 16px
    );
    background-size: 200% 100%;
    animation: stripe 1.2s linear infinite;
}

@keyframes stripe {
    0%   { background-position: 0 0; }
    100% { background-position: 40px 0; }
}

.progress-label {
    font-size: .75rem;
    color: var(--color-muted);
    display: block;
    margin-top: .2rem;
}

/* When status is done: green bar */
.subject-card.status-done   .progress-bar { background: var(--color-done); }
.subject-card.status-error  .progress-bar { background: var(--color-error); }
.subject-card.status-idle   .progress-bar { background: var(--color-idle); }

/* ---- Badge ---- */

.badge {
    display: inline-flex;
    align-items: center;
    padding: .18em .55em;
    border-radius: 99px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
    flex-shrink: 0;
}

.badge-running { background: var(--color-running-bg); color: var(--color-running); border: 1px solid #bfdbfe; }
.badge-done    { background: var(--color-done-bg);    color: var(--color-done);    border: 1px solid #bbf7d0; }
.badge-error   { background: var(--color-error-bg);   color: var(--color-error);   border: 1px solid #fecaca; }
.badge-idle    { background: var(--color-idle-bg);    color: var(--color-idle);    border: 1px solid #d1d5db; }
.badge-unknown { background: #f3f4f6;                 color: var(--color-muted);   border: 1px solid var(--color-border); }

/* ---- Stage list on cards ---- */

.stage-list-inline {
    list-style: none;
    margin-top: .6rem;
    max-height: 180px;
    overflow-y: auto;
    border-top: 1px solid var(--color-border);
    padding-top: .4rem;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}

.stage-inline {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .76rem;
    padding: .15rem 0;
    line-height: 1.3;
}

.stage-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Done: gray */
.stage-inline--done {
    color: var(--color-muted);
}
.stage-inline--done .stage-dot {
    background: #9ca3af;
}

/* Active: red with pulse */
.stage-inline--active {
    color: var(--color-error);
    font-weight: 600;
}
.stage-inline--active .stage-dot {
    background: var(--color-error);
    animation: pulse-dot 1.2s ease-in-out infinite;
}

/* Future: blue */
.stage-inline--future {
    color: #60a5fa;
}
.stage-inline--future .stage-dot {
    background: #93c5fd;
}

.stage-dur {
    margin-left: auto;
    padding-left: .4rem;
    font-variant-numeric: tabular-nums;
    opacity: .75;
    white-space: nowrap;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: .5; transform: scale(1.4); }
}

/* ---- Empty message ---- */

.empty-msg {
    text-align: center;
    color: var(--color-muted);
    padding: 4rem 1rem;
    font-size: .95rem;
}

/* ---- Detail view ---- */

.detail-view {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    max-width: 780px;
}

.detail-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.4rem 1.5rem;
}

.detail-card h2 {
    font-size: .9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--color-muted);
    margin-bottom: 1rem;
}

.detail-card--error {
    border-color: #fecaca;
    background: var(--color-error-bg);
}
.detail-card--error h2 { color: var(--color-error); }

.detail-list {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: .55rem 1rem;
}

.detail-list dt {
    font-weight: 600;
    font-size: .85rem;
    color: var(--color-muted);
    align-self: center;
}
.detail-list dd {
    font-size: .9rem;
    align-self: center;
}

.stage-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: .3rem;
}

.stage-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .875rem;
    padding: .3rem .5rem;
    border-radius: 4px;
}
.stage-item--done   { color: var(--color-muted); }
.stage-item--active { color: var(--color-error); font-weight: 600; }
.stage-item--future { color: #60a5fa; }
.stage-check  { font-size: .85rem; flex-shrink: 0; width: 1em; text-align: center; }
.stage-name   { flex: 1; }
.stage-duration {
    margin-left: auto;
    font-size: .78rem;
    font-variant-numeric: tabular-nums;
    color: var(--color-muted);
    white-space: nowrap;
}

/* ---- Footer ---- */

.site-footer {
    text-align: center;
    padding: 1rem;
    font-size: .78rem;
    color: var(--color-muted);
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
    margin-top: auto;
}
