/* =====================================================
   CSS custom properties
   ===================================================== */
:root {
    /* Status colours */
    --green:        #1D9E75;
    --green-bg:     #EAF3DE;
    --green-text:   #27500A;
    --amber:        #EF9F27;
    --amber-bg:     #FAEEDA;
    --amber-text:   #633806;
    --red:          #E24B4A;
    --red-bg:       #FCEBEB;
    --red-text:     #791F1F;
    --blue:         #378ADD;
    --blue-bg:      #E6F1FB;
    --blue-text:    #0C447C;

    /* Neutrals */
    --surface:      #ffffff;
    --surface-2:    #f5f5f3;
    --border:       rgba(0,0,0,0.10);
    --text:         #1a1a18;
    --text-2:       #6b6b67;
    --text-3:       #9a9a95;

    /* Layout tokens */
    --r:            8px;
    --r-lg:         12px;
    --gap:          12px;
}

/* =====================================================
   Reset & base
   ===================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--surface-2);
    -webkit-tap-highlight-color: transparent;
}

a, button, [type="submit"], [type="button"], [type="reset"] {
    touch-action: manipulation;
}

/* =====================================================
   Login page
   ===================================================== */
.login-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    background: var(--surface-2);
}

.login-wrap h1 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text);
    text-align: center;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--r-lg);
    padding: 1.5rem;
}

.login-card label {
    display: block;
    font-size: 13px;
    color: var(--text-2);
    margin-bottom: 4px;
    margin-top: 14px;
}

.login-card label:first-of-type { margin-top: 0; }

.login-card input[type="email"],
.login-card input[type="password"] {
    display: block;
    width: 100%;
    font-size: 16px;
    font-family: inherit;
    padding: 10px 12px;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    color: var(--text);
    background: var(--surface);
    -webkit-appearance: none;
    appearance: none;
}

.login-card input:focus {
    outline: 2px solid var(--green);
    outline-offset: 1px;
}

.login-btn {
    display: block;
    width: 100%;
    min-height: 44px;
    margin-top: 1.25rem;
    background: var(--green);
    color: #fff;
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    border: none;
    border-radius: var(--r);
    cursor: pointer;
}

.login-btn:active { opacity: 0.85; }

/* =====================================================
   Flash messages
   ===================================================== */
.flash {
    padding: 12px 16px;
    border-radius: var(--r);
    margin-bottom: var(--gap);
    font-size: 13px;
    transition: opacity 0.4s ease;
}

.flash-success {
    background: var(--green-bg);
    color: var(--green-text);
}

.flash-error {
    background: var(--red-bg);
    color: var(--red-text);
}

.flash-hide { opacity: 0; }

/* =====================================================
   Viewer top bar
   ===================================================== */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    height: 48px;
    background: var(--surface);
    border-bottom: 0.5px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}

.top-bar-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.top-bar-user {
    font-size: 13px;
    color: var(--text-2);
}

.top-bar-right a {
    font-size: 13px;
    color: var(--green);
    text-decoration: none;
}

.top-bar-right a:hover { text-decoration: underline; }

/* =====================================================
   Viewer page layout
   ===================================================== */
.viewer-body {
    padding: var(--gap);
    max-width: 900px;
    margin: 0 auto;
}

.viewer-body > .flash { margin-top: var(--gap); }

/* =====================================================
   Stat summary row
   ===================================================== */
.stat-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--gap);
    margin-bottom: var(--gap);
}

@media (min-width: 640px) {
    .stat-row { grid-template-columns: repeat(4, 1fr); }
}

.stat-card {
    background: var(--surface-2);
    border-radius: var(--r);
    padding: 12px 14px;
    border: 0.5px solid var(--border);
}

.stat-label {
    font-size: 11px;
    color: var(--text-3);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-value {
    font-size: 22px;
    font-weight: 500;
    line-height: 1.1;
    color: var(--text);
}

.stat-value.green { color: var(--green); }
.stat-value.amber { color: var(--amber); }
.stat-value.red   { color: var(--red); }

/* =====================================================
   Project card
   ===================================================== */
.proj-card {
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
    margin-bottom: var(--gap);
}

.proj-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    user-select: none;
    min-height: 56px;
}

.proj-header:active { opacity: 0.7; }

.status-pip {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.pip-on_track  { background: var(--green); }
.pip-attention { background: var(--amber); }
.pip-at_risk   { background: var(--red); }
.pip-complete  { background: var(--text-3); }

.proj-title-group { flex: 1; min-width: 0; }

.proj-name {
    font-size: 15px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.proj-meta {
    font-size: 12px;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.proj-chevron {
    font-size: 12px;
    color: var(--text-3);
    flex-shrink: 0;
    transition: transform 0.25s ease;
}

.proj-card.expanded .proj-chevron {
    transform: rotate(180deg);
}

/* =====================================================
   Phase strip — mobile vertical (default)
   ===================================================== */
.phase-strip-vertical  { display: block; }
.phase-strip-horizontal { display: none; }

.phase-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border-left: 4px solid transparent;
}

.phase-row.state-done,
.phase-row.state-active {
    border-left-color: var(--green);
    background: rgba(234,243,222,0.4);
}

.phase-row.state-blocked {
    border-left-color: var(--red);
    background: rgba(252,235,235,0.4);
}

.phase-row.state-upcoming {
    border-left-color: var(--border);
    background: transparent;
}

.phase-state-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    flex-shrink: 0;
    width: 54px;
}

.phase-name-v {
    font-size: 13px;
    font-weight: 500;
    flex: 1;
}

.phase-weeks-v {
    font-size: 11px;
    color: var(--text-3);
    text-align: right;
    white-space: nowrap;
}

/* =====================================================
   Phase strip — horizontal (640px+)
   ===================================================== */
@media (min-width: 640px) {
    .phase-strip-vertical  { display: none; }
    .phase-strip-horizontal { display: flex; border-top: 0.5px solid var(--border); }

    .phase-seg {
        flex: 1;
        padding: 10px 12px;
        border-right: 0.5px solid var(--border);
    }

    .phase-seg:last-child { border-right: none; }

    .phase-seg.state-done,
    .phase-seg.state-active {
        background: var(--green-bg);
    }

    .phase-seg.state-blocked {
        background: var(--red-bg);
    }

    .phase-seg.state-upcoming {
        background: var(--surface-2);
    }

    .phase-seg-state {
        font-size: 10px;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--text-3);
        margin-bottom: 3px;
    }

    .phase-seg-name {
        font-size: 12px;
        font-weight: 500;
    }

    .phase-seg-weeks {
        font-size: 11px;
        color: var(--text-3);
        margin-top: 2px;
    }
}

/* =====================================================
   Detail section
   ===================================================== */
.proj-detail {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.proj-card.expanded .proj-detail {
    max-height: 1200px;
}

.proj-detail-inner {
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

@media (min-width: 640px) {
    .proj-detail-inner {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 16px;
    }
}

.detail-section-heading {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    margin-bottom: 10px;
}

/* =====================================================
   Action items
   ===================================================== */
.action-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 0.5px solid var(--border);
}

.action-item:last-child { border-bottom: none; }

.action-item-body { flex: 1; min-width: 0; }

.action-label {
    font-size: 13px;
    line-height: 1.4;
}

.action-due {
    font-size: 11px;
    color: var(--text-3);
    margin-top: 2px;
}

.no-actions {
    font-size: 12px;
    color: var(--green-text);
}

/* =====================================================
   Badges
   ===================================================== */
.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 4px;
    flex-shrink: 0;
    white-space: nowrap;
}

.badge-urgent { background: var(--red-bg);   color: var(--red-text); }
.badge-due    { background: var(--amber-bg); color: var(--amber-text); }
.badge-info   { background: var(--blue-bg);  color: var(--blue-text); }

/* =====================================================
   Milestone rows
   ===================================================== */
.milestone-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 0.5px solid var(--border);
}

.milestone-row:last-child { border-bottom: none; }

.ms-icon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 10px;
    line-height: 1;
}

.ms-icon-done     { background: var(--green-bg); color: var(--green-text); }
.ms-icon-active   { background: var(--amber-bg); color: var(--amber-text); }
.ms-icon-upcoming { background: var(--surface-2); color: var(--text-3); }

.ms-label {
    font-size: 13px;
    flex: 1;
    line-height: 1.4;
}

.ms-label.muted { color: var(--text-3); }

.ms-date {
    font-size: 11px;
    color: var(--text-3);
    white-space: nowrap;
    flex-shrink: 0;
}

/* =====================================================
   Footer note
   ===================================================== */
.proj-footer-note {
    font-size: 12px;
    text-align: center;
    color: var(--text-2);
    border-top: 0.5px solid var(--border);
    padding-top: 12px;
    margin-top: 4px;
}

/* =====================================================
   No projects message
   ===================================================== */
.no-projects {
    text-align: center;
    color: var(--text-2);
    padding: 3rem 1rem;
    font-size: 15px;
}

/* =====================================================
   Editor layout
   ===================================================== */
.editor-body {
    max-width: 1000px;
    margin: 0 auto;
    padding: var(--gap);
}

.editor-nav {
    background: var(--surface);
    border-bottom: 0.5px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 16px;
    height: 48px;
}

.editor-nav a {
    display: inline-flex;
    align-items: center;
    height: 48px;
    padding: 0 14px;
    font-size: 14px;
    color: var(--text-2);
    text-decoration: none;
    border-bottom: 2px solid transparent;
}

.editor-nav a:hover { color: var(--text); }
.editor-nav a.active { color: var(--green); border-bottom-color: var(--green); font-weight: 500; }

.editor-nav .nav-spacer { flex: 1; }

.editor-nav .nav-logout {
    font-size: 13px;
    color: var(--red);
}

/* =====================================================
   Editor common elements
   ===================================================== */
.editor-section {
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px 18px;
    margin-bottom: 18px;
}

.editor-section h2 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--text);
}

.editor-section h3 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

label {
    display: block;
    font-size: 13px;
    color: var(--text-2);
    margin-bottom: 4px;
    margin-top: 10px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
select,
textarea {
    display: block;
    width: 100%;
    font-size: 16px;
    font-family: inherit;
    padding: 8px 10px;
    min-height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    color: var(--text);
    background: var(--surface);
    -webkit-appearance: none;
    appearance: none;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b6b67' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--green);
    outline-offset: 1px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 6px 14px;
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    border-radius: var(--r);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary   { background: var(--green); color: #fff; border-color: var(--green); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-danger    { background: var(--red-bg); color: var(--red-text); border-color: var(--red-bg); }
.btn-sm        { min-height: 30px; padding: 4px 10px; font-size: 12px; }
.btn:disabled  { opacity: 0.45; cursor: not-allowed; }
.btn:active    { opacity: 0.8; }

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
}

.form-row .field { flex: 1; min-width: 140px; }
.form-row .field label { margin-top: 0; }
.form-row .btn { align-self: flex-end; }

/* =====================================================
   Editor tables
   ===================================================== */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th {
    text-align: left;
    padding: 8px 10px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-weight: 500;
    color: var(--text-2);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

td {
    padding: 9px 10px;
    border-bottom: 0.5px solid var(--border);
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: var(--surface-2); }

.td-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* =====================================================
   Resolved actions toggle
   ===================================================== */
.resolved-toggle {
    font-size: 13px;
    color: var(--text-3);
    cursor: pointer;
    padding: 8px 0;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
    border-top: 0.5px solid var(--border);
    margin-top: 4px;
}

.resolved-section { display: none; }
.resolved-section.open { display: block; }

.resolved-row td { opacity: 0.55; }

/* =====================================================
   Project access checkboxes
   ===================================================== */
.project-access-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.project-access-list label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text);
    margin: 0;
    cursor: pointer;
    background: var(--surface-2);
    padding: 6px 10px;
    border-radius: var(--r);
    border: 1px solid var(--border);
}

.project-access-list input[type="checkbox"] {
    width: auto;
    min-height: auto;
    display: inline;
}

/* =====================================================
   Misc utilities
   ===================================================== */
.mt { margin-top: var(--gap); }
.mb { margin-bottom: var(--gap); }
.text-muted { color: var(--text-3); font-size: 13px; }
.text-small { font-size: 12px; color: var(--text-2); }
