/* Owner Project Management module */

.pm-page {
    --pm-primary: #1f6feb;
    --pm-border: #e3e8ef;
    --pm-muted: #6b7280;
    --pm-bg-soft: #f7f9fc;
}

/* ── Projects list toolbar (compact filters) ── */
.pm-projects-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    margin-bottom: 1.25rem;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--pm-border);
    border-radius: 12px;
    background: #fff;
}

.pm-projects-toolbar .ib-input,
.pm-projects-toolbar select.ib-input {
    width: auto !important;
    max-width: none !important;
    min-height: 38px !important;
    height: 38px;
    flex: 0 0 auto;
    padding: 0.35rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25;
}

.pm-projects-toolbar__select {
    min-width: 132px;
    max-width: 168px;
}

.pm-projects-toolbar__search {
    flex: 1 1 180px;
    min-width: 140px;
    max-width: 320px !important;
}

.pm-projects-toolbar__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.pm-projects-toolbar .ib-btn {
    min-height: 38px !important;
    height: 38px;
    padding: 0.35rem 0.9rem;
    font-size: 0.875rem;
    width: auto !important;
    flex: 0 0 auto;
    white-space: nowrap;
}

@media (max-width: 720px) {
    .pm-projects-toolbar {
        align-items: stretch;
    }

    .pm-projects-toolbar__select,
    .pm-projects-toolbar__search {
        width: 100% !important;
        max-width: none !important;
    }

    .pm-projects-toolbar__actions {
        margin-left: 0;
        width: 100%;
    }

    .pm-projects-toolbar__actions .ib-btn {
        flex: 1 1 auto;
    }
}

/* ── Project cards grid ── */
.pm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
}

.pm-card {
    border: 1px solid var(--pm-border);
    border-radius: 14px;
    background: #fff;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: box-shadow .15s ease, transform .15s ease;
}

.pm-card:hover {
    box-shadow: 0 8px 24px rgba(31, 111, 235, .12);
    transform: translateY(-2px);
}

.pm-card__cover {
    height: 130px;
    background: linear-gradient(135deg, #1f6feb 0%, #6f42c1 100%);
    background-size: cover;
    background-position: center;
    position: relative;
}

.pm-card__body { padding: 1rem; flex: 1; }
.pm-card__body h3 { margin: 0 0 .35rem; font-size: 1.05rem; }

.pm-card__meta {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    color: var(--pm-muted);
    font-size: .82rem;
    margin-bottom: .6rem;
}

.pm-card__stats {
    display: flex;
    justify-content: space-between;
    margin-top: .75rem;
    border-top: 1px solid var(--pm-border);
    padding-top: .6rem;
}
.pm-card__stats > div { display: flex; flex-direction: column; text-align: center; flex: 1; }
.pm-card__stats strong { font-size: .95rem; }
.pm-card__stats span { font-size: .7rem; color: var(--pm-muted); text-transform: uppercase; letter-spacing: .03em; }

.pm-card__actions {
    display: flex;
    gap: .5rem;
    padding: .75rem 1rem;
    border-top: 1px solid var(--pm-border);
    background: var(--pm-bg-soft);
}

/* ── Status badges ── */
.pm-status { position: absolute; top: .6rem; left: .6rem; }
.pm-status--planning { background: #64748b; color: #fff; }
.pm-status--inprogress { background: #1f6feb; color: #fff; }
.pm-status--onhold { background: #d97706; color: #fff; }
.pm-status--completed { background: #16a34a; color: #fff; }

/* ── Progress bars ── */
.pm-progress { display: flex; align-items: center; gap: .5rem; }
.pm-progress__bar { flex: 1; height: 8px; background: #e5e9f0; border-radius: 6px; overflow: hidden; }
.pm-progress__fill { height: 100%; background: linear-gradient(90deg, #1f6feb, #16a34a); border-radius: 6px; transition: width .3s ease; }
.pm-progress__label { font-size: .78rem; color: var(--pm-muted); min-width: 34px; text-align: right; }
.pm-progress--lg { margin: 1rem 0; }
.pm-progress--lg .pm-progress__bar { height: 12px; }

/* ── Project form page ── */
.pm-project-form-page { max-width: 820px; margin: 0 auto; }
.pm-project-form {
    background: #fff; border: 1px solid var(--pm-border); border-radius: 14px;
    box-shadow: 0 8px 30px rgba(15, 23, 42, .06); overflow: hidden;
}
.pm-project-form__header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--pm-border); }
.pm-project-form__header h1 { margin: .35rem 0 0; font-size: 1.25rem; }
.pm-project-form__body {
    padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: 0;
}
.pm-project-form__body .ib-label { display: block; margin: .75rem 0 .25rem; font-weight: 600; font-size: .85rem; }
.pm-project-form__body .ib-input { width: 100%; }
.pm-project-form__footer {
    display: flex; justify-content: flex-end; gap: .5rem;
    padding: 1rem 1.5rem; border-top: 1px solid var(--pm-border); background: var(--pm-bg-soft, #f8fafc);
}

/* ── Modal ── */
.pm-modal-backdrop {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
    display: flex; align-items: center; justify-content: center; z-index: 1050; padding: 1rem;
}
.pm-modal {
    background: #fff; border-radius: 14px; width: 100%; max-width: 560px;
    max-height: 90vh; display: flex; flex-direction: column;
}
.pm-modal--lg { max-width: 720px; }
.pm-modal__header, .pm-modal__footer {
    padding: 1rem 1.25rem; display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--pm-border);
}
.pm-modal__footer { border-bottom: none; border-top: 1px solid var(--pm-border); gap: .5rem; justify-content: flex-end; }
.pm-modal__header h2 { margin: 0; font-size: 1.15rem; }
.pm-modal__close { background: none; border: none; font-size: 1.6rem; cursor: pointer; line-height: 1; color: var(--pm-muted); }
.pm-modal__body { padding: 1.25rem; overflow-y: auto; }
.pm-modal__body .ib-label { display: block; margin: .75rem 0 .25rem; font-weight: 600; font-size: .85rem; }
.pm-modal__body .ib-input { width: 100%; }

.pm-draft-milestone {
    border: 1px solid var(--pm-border); border-radius: 10px; padding: .85rem; margin-top: .75rem;
    background: var(--pm-bg-soft, #f8fafc);
}
.pm-draft-milestone__head { display: flex; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.pm-draft-milestone__head .ib-input { flex: 1; }
.pm-draft-task {
    display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; align-items: start;
    margin-top: .65rem; padding: .65rem; border-left: 3px solid var(--pm-primary, #1f6feb);
    background: #fff; border-radius: 8px;
}
.pm-draft-task__full { grid-column: 1 / -1; }
.pm-draft-task__actions {
    grid-column: 1 / -1; display: flex; justify-content: flex-end;
}
.pm-draft-section { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--pm-border); }
.pm-inline-form--task { margin: .75rem 0 1rem; padding: 1rem; background: var(--pm-bg-soft, #f8fafc); border-radius: 10px; }
.pm-task-desc { font-size: .8rem; margin-top: .2rem; max-width: 360px; }
.pm-draft-section h3 { margin: 0 0 .25rem; font-size: 1rem; }
.pm-draft-hint { font-size: .82rem; color: var(--pm-muted); margin: 0 0 .5rem; }

.pm-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.pm-cover-preview { margin-top: .5rem; max-height: 120px; border-radius: 8px; }
.pm-check { display: flex; align-items: center; gap: .5rem; margin-top: .9rem; }

/* ── Detail header & tabs ── */
.pm-detail__header {
    display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between;
    gap: 1rem; margin-bottom: 1rem;
}
.pm-detail__header h1 { margin: .35rem 0; }
.pm-detail__actions { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }
.pm-back { color: var(--pm-primary); text-decoration: none; font-size: .85rem; }
.pm-portal-badge { background: #0d9488; color: #fff; }
.pm-portal-badge--card { position: absolute; top: .65rem; right: .65rem; }

.pm-tabs {
    display: flex; flex-wrap: wrap; gap: .25rem;
    border-bottom: 2px solid var(--pm-border); margin-bottom: 1.25rem;
}
.pm-tab {
    background: none; border: none; padding: .6rem 1rem; cursor: pointer;
    color: var(--pm-muted); font-weight: 600; font-size: .9rem;
    border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.pm-tab:hover { color: var(--pm-primary); }
.pm-tab--active { color: var(--pm-primary); border-bottom-color: var(--pm-primary); }

/* ── KPIs ── */
.pm-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.pm-kpi { background: var(--pm-bg-soft); border: 1px solid var(--pm-border); border-radius: 12px; padding: 1rem; display: flex; flex-direction: column; gap: .35rem; }
.pm-kpi__label { font-size: .75rem; color: var(--pm-muted); text-transform: uppercase; letter-spacing: .04em; }
.pm-kpi__value { font-size: 1.3rem; font-weight: 700; }

/* ── Panels & columns ── */
.pm-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-top: 1rem; }
.pm-panel { border: 1px solid var(--pm-border); border-radius: 12px; padding: 1rem; }
.pm-panel h3 { margin-top: 0; font-size: 1rem; }
.pm-mini-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px dashed var(--pm-border); }
.pm-mini-row .pm-progress { width: 45%; }

/* ── Section headers ── */
.pm-section-head { display: flex; align-items: center; justify-content: space-between; margin: 1rem 0 .5rem; }
.pm-section-head h3, .pm-section-head h4 { margin: 0; }

/* ── Inline forms ── */
.pm-inline-form { background: var(--pm-bg-soft); border: 1px solid var(--pm-border); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; display: flex; flex-direction: column; gap: .6rem; }
.pm-inline-form .pm-form-row { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); align-items: center; }
.pm-inline-form__actions { display: flex; gap: .5rem; align-items: center; }

/* ── Milestones ── */
.pm-milestone { border: 1px solid var(--pm-border); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }
.pm-milestone__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.pm-milestone__head h4 { margin: 0 0 .35rem; }
.pm-milestone__actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.pm-empty-row { padding: .5rem 0; }

/* ── Tables ── */
.pm-table { width: 100%; border-collapse: collapse; margin-top: .75rem; font-size: .88rem; }
.pm-table th, .pm-table td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--pm-border); }
.pm-table th { color: var(--pm-muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }
.pm-table__actions { display: flex; gap: .35rem; justify-content: flex-end; }
.pm-row--warn { background: #fff7ed; }

/* ── Gantt ── */
.pm-gantt { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.pm-gantt__row { display: grid; grid-template-columns: 160px 1fr; align-items: center; gap: .75rem; }
.pm-gantt__label { font-size: .85rem; font-weight: 600; }
.pm-gantt__track { background: var(--pm-bg-soft); border-radius: 6px; height: 26px; position: relative; overflow: hidden; }
.pm-gantt__bar { position: absolute; top: 3px; bottom: 3px; background: linear-gradient(90deg, #1f6feb, #6f42c1); border-radius: 5px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: .72rem; min-width: 24px; }

/* ── Feed / updates ── */
.pm-feed { display: flex; flex-direction: column; gap: 1rem; }
.pm-update { border: 1px solid var(--pm-border); border-radius: 12px; padding: 1rem; }
.pm-update--mini { border: none; border-bottom: 1px dashed var(--pm-border); border-radius: 0; padding: .5rem 0; }
.pm-update__head { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; flex-wrap: wrap; }
.pm-update__photos { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.pm-update__photos img { width: 110px; height: 110px; object-fit: cover; border-radius: 8px; }

/* ── BOQ ── */
.pm-boq-section { margin: 1.25rem 0 .25rem; font-size: .95rem; color: var(--pm-primary); }
.pm-boq-total { text-align: right; margin-top: .75rem; font-size: 1rem; }

/* ── Warnings ── */
.pm-warnings { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }

/* ── Documents ── */
.pm-doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
.pm-doc { border: 1px solid var(--pm-border); border-radius: 12px; padding: .75rem; display: flex; flex-direction: column; align-items: center; gap: .5rem; text-align: center; }
.pm-doc img { width: 100%; height: 110px; object-fit: cover; border-radius: 8px; }
.pm-doc__file { font-size: 2.5rem; text-decoration: none; }
.pm-doc__name { font-size: .78rem; word-break: break-word; }

/* ── Team ── */
.pm-team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.pm-team-card { border: 1px solid var(--pm-border); border-radius: 12px; padding: 1.25rem; text-align: center; }
.pm-team-card__avatar { width: 56px; height: 56px; border-radius: 50%; background: linear-gradient(135deg, #1f6feb, #6f42c1); color: #fff; font-size: 1.5rem; font-weight: 700; display: flex; align-items: center; justify-content: center; margin: 0 auto .5rem; text-transform: uppercase; }
.pm-team-card h4 { margin: .25rem 0; }
.pm-team-card p { margin: .2rem 0; font-size: .82rem; }
.pm-team-card__cost { font-weight: 700; color: #16a34a; margin-top: .5rem; }

.ib-input--sm { padding: .3rem .5rem; font-size: .82rem; }

.pm-card--clickable { cursor: pointer; transition: box-shadow .15s ease, transform .15s ease; }
.pm-card--clickable:hover { box-shadow: 0 8px 24px rgba(15, 23, 42, .08); transform: translateY(-2px); }
.pm-panel--results { margin-top: 1rem; }
.pm-result-list { list-style: none; padding: 0; margin: .5rem 0 0; }
.pm-result-list li { padding: .45rem .75rem; border-radius: 8px; margin-bottom: .35rem; font-size: .88rem; }
.pm-result--ok { background: #ecfdf3; color: #166534; }
.pm-result--fail { background: #fef2f2; color: #991b1b; }
.pm-bids-modal { max-width: 760px; width: 95vw; }
.pm-partner-modal { max-width: 640px; width: 95vw; }
.pm-partner-detail { margin-bottom: 1rem; }

@media (max-width: 768px) {
    .pm-columns, .pm-form-row { grid-template-columns: 1fr; }
    .pm-gantt__row { grid-template-columns: 100px 1fr; }

    /* Wide data tables scroll inside the page instead of breaking the layout */
    .pm-table {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .pm-table th, .pm-table td { white-space: nowrap; }
    .pm-table__actions { justify-content: flex-start; }

    .pm-draft-task { grid-template-columns: 1fr; }
    .pm-detail__actions { flex-wrap: wrap; }
    .pm-filter-bar .ib-input { max-width: none; flex: 1 1 160px; }
    .pm-mini-row { flex-wrap: wrap; }
    .pm-mini-row .pm-progress { width: 100%; }
    .pm-update__photos img { width: 84px; height: 84px; }
}

/* ── Construction PM hub + module pages ── */
.pm-hub-card { text-decoration: none; color: inherit; }
.pm-hub-card__icon { font-size: 2rem; padding: 1.25rem 1rem 0; }

.pm-module-page { max-width: 1180px; margin: 0 auto; }
.pm-module-page__header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.pm-module-page__header h1 { margin: .35rem 0; font-size: 1.4rem; }

.pm-row--critical { background: #fef2f2; }
.pm-row--critical td:first-child { border-left: 3px solid #dc2626; }
.pm-float-badge { font-weight: 600; }
.pm-float-badge--critical { color: #dc2626; }

.pm-filter-bar { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.pm-filter-bar .ib-input { max-width: 220px; }

.pm-schedule-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
