﻿/* KRAMEL Project Tracking — KRAMEL Brand Style */

:root {
    --bg: #07080a;
    --bg2: #0b0d12;
    --card: #0c0f16;
    --surface-pane: #12141b;
    --text: #e9ecf1;
    --muted: #a8b0bf;
    --faint: #707a8c;
    --line: rgba(255,255,255,.10);
    --line2: rgba(255,255,255,.06);
    --section-line-strong: rgba(255,255,255,.10);
    --accent: #e9ecf1;
    --accent2: #c7d2ff;
    --gold: #d6c08a;
    --shadow: 0 30px 90px rgba(0,0,0,.55);
    --radius: 20px;
    --radius2: 14px;
    --screen-overlay: rgba(255,255,255,0.03);
    --input-bg: rgba(199, 210, 255, 0.04);
    --input-focus-bg: rgba(214, 192, 138, 0.06);
    --option-bg: #0b0d12;

    /* Scrollbar */
    --sb-track: rgba(255,255,255,.06);
    --sb-thumb: rgba(214,192,138,.55); /* gold */
    --sb-thumb-hover: rgba(214,192,138,.75);
}

html[data-theme="light"] {
    --bg: #dfe5ee;
    --bg2: #e8edf4;
    --card: #f2f5f9;
    --surface-pane: #edf1f6;
    --text: #101318;
    --muted: #101318;
    --faint: #101318;
    --line: rgba(16,19,24,.22);
    --line2: rgba(16,19,24,.14);
    --section-line-strong: rgba(16,19,24,.22);
    --accent: #0f172a;
    --accent2: #2c3e66;
    --shadow: 0 18px 50px rgba(15, 23, 42, 0.10);
    --screen-overlay: rgba(0,0,0,0.05);
    --input-bg: rgba(16, 19, 24, 0.05);
    --input-focus-bg: rgba(214, 192, 138, 0.18);
    --option-bg: #edf1f6;
    --sb-track: rgba(16,19,24,.16);
    --sb-thumb: rgba(16,19,24,.40);
    --sb-thumb-hover: rgba(16,19,24,.62);
}

/* Light theme: all text must be black, including pills and highlighted counters. */
html[data-theme="light"] body,
html[data-theme="light"] body * {
    color: #101318 !important;
}

html[data-theme="light"] input::placeholder,
html[data-theme="light"] textarea::placeholder {
    color: rgba(16, 19, 24, 0.62) !important;
}

/* Scrollbar (global) */
html {
    scrollbar-color: var(--sb-thumb) var(--sb-track); /* Firefox */
    scrollbar-width: thin;
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: var(--sb-track);
}

*::-webkit-scrollbar-thumb {
    background: var(--sb-thumb);
    border-radius: 10px;
    border: 2px solid rgba(0,0,0,.35);
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--sb-thumb-hover);
}

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

html, body {
    height: 100%;
}

/* Hide admin-only blocks until role is known to prevent flash */
html.k-hide-until-role [data-admin-only]{display:none !important;}
/* Owner-only blocks must never show for non-owner admins (even if JS fails) */
html:not([data-is-owner="1"]) [data-owner-only]{display:none !important;}

body {
    font-family: Montserrat, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background: linear-gradient(180deg, var(--bg), var(--bg2));
    color: var(--text);
    overflow-x: hidden;
}

/* Align client view background to admin (solid subtle tone) */
#client-view-screen::before{
    content:"";
    position:fixed;
    inset:0;
    pointer-events:none;
    z-index:0;
    background: var(--screen-overlay);
}
#client-view-screen .app-header,
#client-view-screen .app-main{position:relative; z-index:1;}

/* Admin background: solid fill (single tone) */
#admin-screen{position:relative;}
#admin-screen::before{
    content:"";
    position:fixed;
    inset:0;
    pointer-events:none;
    z-index:0;
    background: var(--screen-overlay);
}
#admin-screen .app-header,
#admin-screen .app-main{position:relative; z-index:1;}


.app-wrapper {
    height: 100vh;
    overflow: hidden;
}

.screen {
    display: none;
    height: 100vh;
    overflow-y: auto;
    animation: fadeIn 0.3s;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Admin accordions */
.k-acc .k-acc-body{padding-top:12px;}
.k-acc.k-acc-collapsed .k-acc-body{display:none;}
.k-acc .k-acc-caret{display:none;}

/* Make accordion header clickable even though h2 has border-bottom */
.k-acc > .section-header{position:relative; z-index:1;}
.k-acc > .section-header::after{content:''; position:absolute; inset:-10px -6px -10px -6px;}

/* LOGIN SCREEN */
#login-screen.active {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

/* REGISTER SCREEN (same centering as login) */
.screen.active:has(#register-form) {
    align-items: center;
    justify-content: center;
}

.login-container {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 40px;
    max-width: 400px;
    width: 100%;
}

/* Registration: spacing like admin login (use only gap, no label margins) */
#register-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
}

#register-form input {
    width: 100%;
}

.login-container h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 4px;
    text-align: center;
}

.login-subtitle {
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    margin-bottom: 30px;
    letter-spacing: 0.05em;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Make register form spacing match login form */
#register-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* keep zero margins; spacing comes from form gap */

/* Register: lock row alignment like login (prevent form jumping) */
#invite-info,
#reg-result {
    min-height: 18px;
}

/* Force identical input sizing in register/login */
#register-form input,
#login-form input {
    height: 42px;
    box-sizing: border-box;
}

/* HEADER */
.app-header {
    position: sticky;
    top: 0;
    z-index: 40;
    /* No background / no contour lines for header (per request) */
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: transparent;
    border-bottom: none;
    padding: 20px;
}

.header-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.app-header h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
}

.btn-logout {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
    padding: 8px 14px;
    border-radius: var(--radius2);
    cursor: pointer;
    font-size: 12px;
    font-family: Montserrat, sans-serif;
    transition: all 0.2s;
}

.btn-logout:hover {
    border-color: var(--accent2);
    color: var(--accent);
}

.btn-back {
    background: transparent;
    color: var(--muted);
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-family: Montserrat, sans-serif;
    padding: 0;
}

.btn-back:hover {
    color: var(--accent);
}

/* MAIN CONTENT */
.app-main {
    flex: 1;
    overflow-y: auto;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
    padding: 30px 20px;
}

/* SECTIONS */
.section {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius2);
    padding: 24px;
    margin-bottom: 24px;
}

/* Simple between-sections row (no card/container) */
.between-sections{
    display:flex;
    justify-content:flex-end;
    gap:10px;
    margin: -10px 0 18px 0; /* sit between cards */
}

/* Admin home: make blocks slightly lighter than the right-side fill */
#admin-screen .section{
    /* solid fill (no transparency) */
    background: var(--surface-pane);
    border-color: var(--section-line-strong);
}

#client-view-screen .section{
    background: var(--surface-pane);
    border-color: var(--section-line-strong);
}

.section-header {
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

/* FORMS */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.form-full {
    grid-column: 1 / -1;
}

label {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.label-text {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

input, select, textarea {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius2);
    font-size: 13px;
    font-family: Montserrat, sans-serif;
    background: var(--input-bg);
    color: var(--text);
    transition: all 0.2s;
}

/* Optimize native dropdown colors (where browser allows) */
select {
    background-color: var(--input-bg);
    color: var(--text);
}

select option {
    background-color: var(--option-bg);
    color: var(--text);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--gold);
    background: var(--input-focus-bg);
    box-shadow: 0 0 0 3px rgba(214, 192, 138, 0.10);
}

textarea {
    resize: vertical;
    min-height: 60px;
}

/* BUTTONS */
.btn-primary {
    background: rgba(214, 192, 138, 0.12);
    color: var(--gold);
    padding: 10px 16px;
    border: 1px solid var(--gold);
    border-radius: var(--radius2);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
    font-family: Montserrat, sans-serif;
}

.btn-primary:hover {
    background: rgba(214, 192, 138, 0.24);
    box-shadow: 0 0 0 3px rgba(214, 192, 138, 0.12);
}

.btn-secondary {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
    padding: 8px 14px;
    border-radius: var(--radius2);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
    font-family: Montserrat, sans-serif;
    text-decoration: none;
}

.btn-secondary:hover {
    border-color: var(--accent2);
    background: rgba(199, 210, 255, 0.08);
    color: var(--accent);
}

.btn-large {
    padding: 12px 24px;
    font-size: 13px;
    width: 100%;
}

.btn-copy {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
    padding: 6px 10px;
    border-radius: var(--radius2);
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s;
}

.btn-copy:hover {
    border-color: var(--accent2);
    color: var(--accent);
}

/* ADD STAGE FORM */
.add-stage-form {
    background: rgba(199, 210, 255, 0.04);
    border: 1px solid var(--line);
    border-radius: var(--radius2);
    padding: 16px;
    margin-top: 16px;
}

.add-stage-form.hidden {
    display: none;
}

.add-stage-form h3 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

/* STAGES LIST */
.stages-preview {
    background: rgba(199, 210, 255, 0.02);
    border: 1px solid var(--line);
    border-radius: var(--radius2);
    padding: 16px;
    margin-top: 16px;
}

.stages-preview.hidden {
    display: none;
}

.stages-preview h3 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
}

.stages-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stages-list li {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(199, 210, 255, 0.04);
    border-radius: var(--radius2);
    font-size: 12px;
}

/* PROJECTS LIST */
.projects-list {
    display: grid;
    gap: 16px;
}

.project-card {
    background: rgba(199, 210, 255, 0.02);
    border: 1px solid var(--line);
    border-radius: var(--radius2);
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
}

.project-card:hover {
    background: rgba(199, 210, 255, 0.06);
    border-color: var(--accent2);
}

.project-card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.project-card-meta {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 12px;
}

.project-card-progress {
    background: rgba(199, 210, 255, 0.04);
    border-radius: var(--radius2);
    height: 4px;
    overflow: hidden;
    margin-top: 12px;
}

.project-card-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold), var(--accent2));
}

/* PROJECT INFO  rows like client totals blocks */
.project-info {
    display: flex;
    flex-direction: column;
    gap: 12px; /* same spacing as client totals/stages */
}

.info-row {
    background: rgba(199, 210, 255, 0.03);
    border: 1px solid var(--line2);
    border-radius: 14px;
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

/* remove legacy dividers */
.info-row{border-bottom:none;}

.info-row .label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
}

.info-row input {
    flex: 1;
    margin: 0 12px;
}

.project-actions-row {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    width: 100%;
    flex-wrap: wrap;
}

.project-action-btn {
    min-width: 200px;
    text-align: center;
}

/* STAGES EDITOR */
.stages-editor {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Each stage is its own container (not a single nested block) */
.stage-section {
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: var(--radius2);
    padding: 16px;
    background: transparent;
}

/* Clear separation between stages */
#stages-editor {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stage-section + .stage-section {
    margin-top: 0;
}

/* Collapsed stage card */
.stage-section.is-collapsed {
    padding: 12px 14px;
}

/* Make collapsed header truly one-line/compact */
.stage-section.is-collapsed .section-header {
    padding-bottom: 0;
}
.stage-section.is-collapsed .section-header h2 {
    font-size: 13px;
}
.stage-section.is-collapsed .health-pill {
    padding: 4px 8px;
    font-size: 10px;
}
.stage-section.is-collapsed .stage-status-select {
    height: 30px;
    padding-top: 4px;
    padding-bottom: 4px;
}

.stage-section .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.stage-section .section-header h2 {
    margin: 0;
    font-size: 14px;
}

.stage-plan-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

/* Desktop: six fixed-equal columns for stage plan row */
@media (min-width: 769px) {
    .stage-plan-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
    }
}

.stage-plan-grid > label {
    min-width: 0;
}

/* Stage plan inputs: uniform control height */
.stage-plan-grid input,
.stage-plan-grid select {
    height: 44px;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}
.stage-plan-grid input {
    padding-top: 0;
    padding-bottom: 0;
}

.stage-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin: 12px 0 14px;
}

.kpi {
    background: rgba(199, 210, 255, 0.03);
    border: 1px solid var(--line2);
    border-radius: 14px;
    padding: 12px;
}

.kpi-label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
}

.kpi-value {
    margin-top: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.health-pill {
    font-size: 11px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--muted);
    background: rgba(199, 210, 255, 0.03);
    white-space: nowrap;
    flex: 0 0 auto;
}

.health-pill.green {
    border-color: rgba(120, 255, 170, 0.35);
    color: rgba(170, 255, 210, 0.95);
    background: rgba(120, 255, 170, 0.06);
}

.health-pill.yellow {
    border-color: rgba(255, 205, 92, 0.45);
    color: rgba(255, 230, 170, 0.98);
    background: rgba(255, 205, 92, 0.10);
}

.health-pill.orange {
    border-color: rgba(255, 185, 90, 0.35);
    color: rgba(255, 210, 160, 0.95);
    background: rgba(255, 185, 90, 0.06);
}

.health-pill.red {
    border-color: rgba(255, 90, 90, 0.35);
    color: rgba(255, 180, 180, 0.95);
    background: rgba(255, 90, 90, 0.06);
}

.worklog-box {
    background: rgba(199, 210, 255, 0.02);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 12px;
    margin: 12px 0;
}

.worklog-add {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    align-items: end;
}

.worklog-note {
    grid-column: 1 / -1;
}

.worklog-title {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin: 10px 0 6px;
}

.worklog-empty {
    margin-top: 10px;
    font-size: 11px;
    color: var(--muted);
}

.worklog-list {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.worklog-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line2);
    border-radius: 14px;
    background: rgba(199, 210, 255, 0.02);
}

/* Owner admin list highlight */
.worklog-row.is-blocked{
    border-color: rgba(214,192,138,0.30);
    background: rgba(214,192,138,0.06);
}

.wl-actions-inline {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-left: auto;
    width: auto;
    flex: 0 0 auto;
}

.fact-pay-row {
    display: block;
}

.fact-pay-row .fact-pay-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    width: 100%;
}

.fact-pay-row .fact-pay-line .wl-date {
    justify-self: start;
    white-space: nowrap;
}

.fact-pay-row .fact-pay-line .wl-val {
    justify-self: center;
    margin-top: 0;
    white-space: nowrap;
}

.fact-pay-row .fact-pay-line .btn-delete {
    justify-self: end;
}

.wl-date {
    font-size: 11px;
    color: var(--muted);
}

.wl-val {
    font-size: 12px;
    font-weight: 600;
    margin-top: 2px;
}

.wl-note {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}

.stage-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line2);
}

/* keep traffic-light pill from shrinking/collapsing */
.stage-editor-header > div { flex: 0 0 auto; }
.stage-editor-header h2, .stage-editor-header h3 { flex: 1 1 auto; min-width: 0; }

/* Pin right controls (health + status + delete) to the right edge, keep them stable */
.stage-editor-header > div {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-left: auto;
    flex-wrap: nowrap;
}

.stage-editor-header h2 {
    min-width: 0;
}

.stage-editor-header h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.stage-status-select {
    width: 150px;
}

/* Admin stage plan grid: responsive for narrow screens */
@media (max-width: 520px) {
  .stage-plan-grid { grid-template-columns: 1fr !important; }
  .stage-plan-grid label { min-width: 0; }
  .stage-plan-grid input, .stage-plan-grid select { width: 100%; }
}

.stage-progress {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
}

.stage-progress input {
    width: 60px;
}

.stage-progress-track {
    width: 60px;
    height: 8px;
    border-radius: 999px;
    background: rgba(199, 210, 255, 0.16);
    border: 1px solid rgba(199, 210, 255, 0.22);
    overflow: hidden;
}

.stage-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold), var(--accent2));
}

.stage-date-start,
.stage-date-finish {
    color: #18c37e;
}

.stage-date-finish-red {
    color: #ff5d5d;
}

.stage-date-sep {
    color: var(--muted);
}

.upload-photos {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.upload-photos input[type="file"] {
    display: none;
}

.btn-upload {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
    padding: 8px 12px;
    border-radius: var(--radius2);
    cursor: pointer;
    font-size: 12px;
    font-family: Montserrat, sans-serif;
}

.btn-upload:hover {
    border-color: var(--accent2);
    color: var(--accent);
}

.photo-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.photo-thumb {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    background: rgba(199, 210, 255, 0.04);
    cursor: pointer;
}

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.photo-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.72);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 24px;
}

.photo-modal.active {
    display: flex;
}

.photo-modal-content {
    width: min(980px, 96vw);
    max-height: 90vh;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.photo-modal.is-fullscreen {
    padding: 0;
}
.photo-modal.is-fullscreen .photo-modal-content {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
}
.photo-modal.is-fullscreen .photo-modal-body img {
    max-height: calc(100vh - 56px);
    border-radius: 0;
}

.photo-nav {
    display:flex;
    gap:10px;
    align-items:center;
}
.photo-nav button {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--muted);
    border-radius: 12px;
    padding: 6px 10px;
    cursor: pointer;
}
.photo-nav button:hover {
    border-color: var(--accent2);
    color: var(--accent);
}

.photo-stage {
    position: relative;
}

.photo-edge {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 64px;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.10);
    background: rgba(0,0,0,0.35);
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    display:flex;
    align-items:center;
    justify-content:center;
    font-size: 28px;
    line-height: 1;
    user-select: none;
}
.photo-edge:hover {
    border-color: var(--accent2);
    background: rgba(0,0,0,0.45);
    color: var(--accent);
}
.photo-edge-left { left: 12px; }
.photo-edge-right { right: 12px; }

.photo-modal.is-fullscreen .photo-edge-left { left: 18px; }
.photo-modal.is-fullscreen .photo-edge-right { right: 18px; }

.photo-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line2);
}

.photo-modal-header .title {
    font-size: 12px;
    color: var(--muted);
}

.photo-modal-close {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--muted);
    border-radius: 12px;
    padding: 6px 10px;
    cursor: pointer;
}

.photo-modal-close:hover {
    border-color: var(--accent2);
    color: var(--accent);
}

.photo-modal-body {
    padding: 14px;
    display: grid;
    gap: 12px;
}

.photo-modal-body img {
    width: 100%;
    height: auto;
    max-height: 70vh;
    object-fit: contain;
    background: #0b0d12;
    border-radius: 14px;
}

.btn-danger {
    background: rgba(255, 77, 77, 0.10);
    border: 1px solid rgba(255, 77, 77, 0.55);
    color: #ffb3b3;
    padding: 8px 12px;
    border-radius: var(--radius2);
    cursor: pointer;
    font-size: 12px;
    font-family: Montserrat, sans-serif;
    flex: 0 0 auto;
    white-space: nowrap;
}

.btn-danger:hover {
    background: rgba(255, 77, 77, 0.18);
}

.btn-delete {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: 1px solid rgba(255, 77, 77, 0.55);
    background: rgba(255, 77, 77, 0.08);
    color: #ffb3b3;
    font-family: Montserrat, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    font-size: 18px;
    line-height: 1;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: 0 0 auto;
}

.btn-delete:hover {
    background: rgba(255, 77, 77, 0.18);
    border-color: rgba(255, 77, 77, 0.75);
    color: #ffd0d0;
}

/* CLIENT VIEW */
/* Header in client view: no background/contour (match admin) */
.client-view .app-header {
    background: transparent;
    border-bottom: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.progress-summary {
    background: rgba(199, 210, 255, 0.04);
    border-radius: var(--radius2);
    padding: 24px;
}

.progress-summary h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
}

.progress-bar-container {
    margin-bottom: 24px;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 8px;
}

.progress-bar {
    height: 8px;
    background: rgba(199, 210, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold), var(--accent2));
    transition: width 0.3s;
}

.timeline-info {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.timeline-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.timeline-item .label {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
}

.timeline-item .value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

/* CLIENT PROGRESS (client.html uses progress-wrap/progress-head) */
.progress-wrap{margin-top:4px;}
.progress-head{
    display:flex;
    align-items:baseline;
    justify-content:space-between; /* "" + "%"    */
    gap:10px;
    margin-bottom:10px; /*    */
}
.progress-title{font-size:12px; color:var(--muted); text-transform:uppercase; letter-spacing:.06em;}
.progress-val{font-size:16px; font-weight:600; color:var(--text);}

/* CLIENT TOTALS (   : , gap=12px) */
.totals-grid{
    margin-top: 12px;
    display:flex;
    flex-direction:column;
    gap: 12px;
}

.totals-item {
    background: rgba(199, 210, 255, 0.03);
    border: 1px solid var(--line2);
    border-radius: 14px;
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.totals-item .k {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
}

.totals-item .v {
    font-size: 12px;
    font-weight: 600;
}

/* Client: payments vs fact indicator */
.k-payfact { font-weight: 700; }
.k-payfact.is-green { color: #2ee88b; }
.k-payfact.is-orange { color: #ffb020; }
.k-payfact.is-red { color: #ff5d5d; }
@keyframes k-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
.k-payfact.is-blink {
  animation-name: k-blink;
  animation-iteration-count: infinite;
  animation-timing-function: ease-in-out;
}

/* Analytics accordion */
#analytics-projects-wrap.is-collapsed #analytics-projects { display:none; }
#analytics-projects [data-ana-acc-body].is-collapsed { display: none; }

/* CLIENT STAGES */
.client-stages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.client-stage {
    background: rgba(199, 210, 255, 0.02);
    border: 1px solid var(--line);
    border-radius: var(--radius2);
    padding: 16px;
    min-width: 0;
}

.stage-title { min-width: 0; }
.stage-title span { display:block; word-break: break-word; overflow-wrap:anywhere; }
.health-pill { max-width: 100%; white-space: normal; }

.client-stage-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
    cursor: pointer;
    user-select: none;
    flex-wrap: wrap;
}

/* Telegram Mini App / narrow screens: keep status badge from forcing horizontal scroll */
@media (max-width: 520px) {
  .client-stage-head { gap: 8px; }
  .client-stage-head > * { min-width: 0; }
  .client-stage-head .stage-title,
  .client-stage-head h3,
  .client-stage-head .wl-main { min-width: 0; }
  .client-stage-head .stage-title { flex: 1 1 100%; }
  .client-stage-head .stage-badge,
  .client-stage-head .badge,
  .client-stage-head [class*="badge"] {
    flex: 0 0 auto;
    max-width: 100%;
    white-space: normal;
  }
}

.client-stage .client-acc-caret {
    opacity: .7;
    font-size: 14px;
    margin-left: 6px;
}

.client-stage.is-collapsed .client-stage-body {
    display: none;
}

.client-stage-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 10px;
    margin: 12px 0;
}

.meta-item {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line2);
    border-radius: 14px;
    background: rgba(199, 210, 255, 0.02);
}

.meta-item .k {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
}

.meta-item .v {
    font-size: 12px;
    font-weight: 600;
}

.client-stage-progress {
    margin-top: 10px;
}

.client-stage-photos {
    margin-top: 14px;
}

.photos-title {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 10px;
}

.client-photos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 10px;
}

.stage-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.stage-status-badge {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--faint);
}

.stage-status-badge.done {
    background: var(--gold);
}

.stage-status-badge.active {
    background: var(--accent2);
    animation: pulse 1.5s ease-in-out infinite;
}

.stage-status-badge.paused {
    background: #f2b705;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.stage-dates {
    font-size: 11px;
    color: var(--muted);
    margin: 4px 0;
}

/* GALLERY */
.client-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.gallery-item {
    border-radius: var(--radius2);
    overflow: hidden;
    background: rgba(199, 210, 255, 0.04);
}

.gallery-item img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    display: block;
}

.gallery-item-info {
    padding: 8px;
    font-size: 10px;
    color: var(--muted);
}

/* CLIENT FOOTER */
.client-footer {
    color: var(--muted);
    font-size: 11px;
}

/* Master/Mini App: keep input rows stable on narrow screens */
@media (max-width: 520px) {
  .worklog-row { flex-wrap: wrap; }
  .worklog-row .wl-main { min-width: 0; flex: 1 1 100%; }
  .worklog-row .wl-actions { width: 100%; justify-content: flex-start; }

  /* Keep delete controls on the right for specific admin lists */
  .approved-fact-row,
  .stage-pay-row {
    flex-wrap: nowrap !important;
    align-items: center;
  }
  .approved-fact-row .wl-main,
  .stage-pay-row .wl-main {
    flex: 1 1 auto !important;
    min-width: 0;
  }
  .stage-pay-row .wl-main {
    text-align: center;
  }
  .approved-fact-row .wl-actions-inline,
  .stage-pay-row .wl-actions-inline {
    width: auto !important;
    margin-left: auto;
    justify-content: flex-end !important;
  }
  .fact-pay-row {
    display: block !important;
  }
  .fact-pay-row .fact-pay-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
  }
  .fact-pay-row .wl-date { justify-self: start; white-space: nowrap; }
  .fact-pay-row .wl-val { justify-self: center; white-space: nowrap; margin-top: 0; }
  .fact-pay-row .btn-delete { justify-self: end; }

  /* Master form row with photo buttons */
  .worklog-actions > div { flex-wrap: wrap !important; }
  .worklog-actions button { min-width: 0 !important; width: 100% !important; }
  .worklog-actions .upload-hint { white-space: normal !important; }
  #master-stages .worklog-add { grid-template-columns: 1fr; }

  /* Master: " " table -> vertical cards */
  .mwl-pending-head { margin-bottom: 10px; display:flex; flex-direction:column; align-items:flex-start; gap:8px; }
  .mwl-pending-title { font-size: 14px; font-weight:700; white-space:nowrap; }
  #mwl-toggle-pending { width:100%; white-space:nowrap; }

  /* Access/Invites mobile: headings */
  #access-section .mini-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  #access-section .mini-title { font-size: 13px; font-weight: 700; line-height: 1.2; }
  #access-section #btn-refresh-pending { width: 100%; }

  /* Access/Invites mobile: stack buttons + prevent overflow */
  #access-section .worklog-row { flex-wrap: wrap; }
  #access-section .wl-main { min-width:0; flex: 1 1 100%; }
  #access-section .wl-date { white-space: normal; overflow-wrap:anywhere; word-break: break-word; }
  #access-section .worklog-row > div:last-child { width:100%; }
  #access-section .worklog-row button { width:100%; }

  #master-my-pending table { display:block; width:100%; }
  #master-my-pending thead { display:none; }
  #master-my-pending tbody, #master-my-pending tr, #master-my-pending td { display:block; width:100%; }
  #master-my-pending tr { border-top:1px solid rgba(255,255,255,0.06); padding:10px 8px; }
  #master-my-pending td { padding:4px 0 !important; white-space: normal !important; }
  #master-my-pending td:nth-child(1)::before { content:": "; color:var(--muted); }
  #master-my-pending td:nth-child(2)::before { content:": "; color:var(--muted); }
  #master-my-pending td:nth-child(3)::before { content:".: "; color:var(--muted); }
  #master-my-pending td:nth-child(4)::before { content:": "; color:var(--muted); }
  #master-my-pending td:nth-child(5)::before { content:": "; color:var(--muted); }
  #master-my-pending td:nth-child(6)::before { content:": "; color:var(--muted); }

  .worklog-row input, .worklog-row textarea, .worklog-row select { width: 100%; }
  .btn-primary, .btn-secondary { width: 100%; }
  .app-header .btn-secondary,
  .app-header .btn-logout {
    width: auto !important;
  }
}

.client-footer-inner {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.client-footer a {
    color: var(--accent2);
    text-decoration: none;
}

/* Admin Mini App: hide non-essential sections (CSS, does not affect desktop) */
html.is-miniapp #pricing-section,
html.is-miniapp #manual-section,
html.is-miniapp #owner-admins {
  display: none !important;
}

/* hide inactive projects section by hiding its parent section when possible */
html.is-miniapp #projects-inactive-list { display:none !important; }

/* RESPONSIVE */
@media (max-width: 768px) {
    .app-main {
        padding: 20px 15px;
    }

    /* Admin Mini App: make long titles and pills wrap instead of forcing horizontal scroll */
    .health-pill { white-space: normal; max-width: 100%; }
    .stage-title span { overflow-wrap:anywhere; word-break: break-word; }
    .stages-grid, .project-stages, .stage-row { min-width: 0; }
    .stage-actions { flex-wrap: wrap; }
    .stage-actions .btn-primary, .stage-actions .btn-secondary { width: 100%; }

    /* Project editor header controls */
    .stage-editor-header { flex-wrap: wrap; align-items:flex-start; gap:10px; }
    .stage-editor-header h3 { min-width:0; width:100%; }
    .stage-status-select { width: 100%; max-width: 260px; }
    .add-stage-form .form-actions { flex-direction: column; }
    .add-stage-form .form-actions .btn-primary,
    .add-stage-form .form-actions .btn-secondary { width: 100%; }

    .form-grid, .form-grid-2 {
        grid-template-columns: 1fr;
    }

    .timeline-info {
        grid-template-columns: 1fr;
    }

    .btn-large {
        width: 100%;
    }

    .login-container {
        margin: 20px;
    }

    .header-inner {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* Unified typography across all pages and controls */
body,
button,
input,
select,
textarea {
    font-family: Montserrat, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* Keep media/blocks inside viewport */
img,
video,
canvas,
svg {
    max-width: 100%;
    height: auto;
}

.section,
.project-card,
.stage-section,
.client-stage,
.worklog-row,
.info-row,
.totals-item,
.meta-item,
.kpi,
.stages-preview,
.add-stage-form,
.progress-summary,
.photo-modal-content {
    min-width: 0;
    max-width: 100%;
}

/* Reusable header groups */
.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.analytics-filters {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

@media (max-width: 900px) {
    html,
    body {
        font-size: 14px;
    }

    .app-wrapper,
    .screen,
    .app-main {
        width: 100%;
        min-width: 0;
    }

    .app-header {
        padding: 14px 12px;
    }

    .app-main {
        padding: 16px 12px !important;
    }

    .section {
        padding: 16px;
        margin-bottom: 14px;
    }

    .section-header {
        margin-bottom: 14px;
    }

    .section-header h2 {
        font-size: 15px;
        padding-bottom: 10px;
    }

    .header-inner {
        width: 100%;
        gap: 12px;
        align-items: flex-start;
    }

    .header-brand,
    .header-row {
        width: 100%;
    }

    .header-row {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .header-row h1 {
        width: 100%;
        min-width: 0;
    }

    .header-controls {
        width: 100%;
        flex-wrap: wrap;
    }

    .header-controls .btn-secondary,
    .header-controls .btn-logout {
        flex: 1 1 calc(50% - 4px);
        min-width: 140px;
        text-align: center;
    }

    .app-header [data-theme-toggle],
    .app-header .btn-logout,
    #client-logout,
    #master-logout {
        text-transform: uppercase;
    }

    .project-actions-row {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 10px;
    }

    .project-action-btn {
        width: min(280px, 100%);
        min-width: 0;
        text-align: center;
    }

    .project-card .card-actions {
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .project-card .card-actions .btn-secondary {
        width: min(240px, 100%) !important;
        min-width: 0 !important;
    }

    .form-grid,
    .form-grid-2,
    .client-stage-meta,
    .timeline-info,
    .worklog-add,
    .stage-plan-grid,
    .stage-kpis,
    .analytics-filters {
        grid-template-columns: 1fr !important;
    }

    .project-card-meta,
    .info-row,
    .totals-item,
    .meta-item,
    .worklog-row {
        flex-wrap: wrap;
        gap: 8px;
    }

    .info-row .label,
    .totals-item .k,
    .meta-item .k {
        width: 100%;
    }

    .stage-section .section-header,
    .stage-editor-header {
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 10px;
    }

    .stage-editor-header > div {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .stage-editor-header .stage-editor-controls {
        width: 100%;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 10px;
    }

    .stage-editor-header .health-pill {
        text-align: center;
        margin: 0 auto;
    }

    .stage-status-select {
        width: 100% !important;
        max-width: 100% !important;
    }

    .stage-editor-header .stage-status-select {
        max-width: 360px !important;
    }

    .btn-stage-delete {
        width: 100% !important;
        max-width: 360px;
        margin: 0 auto;
        text-align: center;
        background: rgba(214, 192, 138, 0.12);
        border-color: var(--gold);
        color: var(--gold);
    }

    .btn-stage-delete:hover {
        background: rgba(214, 192, 138, 0.24);
        border-color: var(--gold);
        color: var(--gold);
    }

    .approved-fact-row,
    .stage-pay-row {
        flex-wrap: nowrap !important;
        align-items: center;
    }

    .approved-fact-row .wl-main,
    .stage-pay-row .wl-main {
        flex: 1 1 auto !important;
        min-width: 0;
    }

    .stage-pay-row .wl-main {
        text-align: center;
    }

    .approved-fact-row .wl-actions-inline,
    .stage-pay-row .wl-actions-inline {
        width: auto !important;
        margin-left: auto;
        justify-content: flex-end !important;
    }

    .fact-pay-row {
        display: block !important;
    }

    .fact-pay-row .fact-pay-line {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        align-items: center;
        gap: 8px;
    }

    .fact-pay-row .wl-date {
        justify-self: start;
        white-space: nowrap;
    }

    .fact-pay-row .wl-val {
        justify-self: center;
        white-space: nowrap;
        margin-top: 0;
    }

    .fact-pay-row .btn-delete {
        justify-self: end;
    }

    .stage-pay-row .btn-danger {
        min-width: 104px;
        width: auto !important;
    }

    .race-pie-wrap {
        display: none;
    }

    .health-pill {
        max-width: 100%;
        white-space: normal;
    }

    .btn-primary,
    .btn-secondary,
    .btn-danger,
    .btn-upload {
        line-height: 1.25;
    }

    .client-footer-inner {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        text-align: center;
    }

    .client-footer-inner > * {
        width: 100%;
        text-align: center;
    }

    #analytics-screen {
        height: calc(100vh - 96px) !important;
    }
}



