:root {
    --ink: #17211d;
    --muted: #66736e;
    --line: #dfe6e2;
    --surface: #ffffff;
    --background: #f4f7f5;
    --brand: #1d5b46;
    --brand-dark: #123d2f;
    --accent: #d3a858;
    --danger: #a63d46;
    --shadow: 0 16px 45px rgba(20, 54, 42, .08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--background); }
body { min-height: 100vh; margin: 0; background: radial-gradient(circle at 15% 0%, rgba(211,168,88,.10), transparent 24rem), var(--background); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .45rem; font-size: clamp(1.8rem, 3vw, 2.7rem); letter-spacing: -.04em; line-height: 1.08; }
h2 { margin-bottom: .4rem; font-size: 1.25rem; letter-spacing: -.02em; }
h3 { margin-bottom: .35rem; font-size: 1.05rem; }

.topbar { position: sticky; z-index: 20; top: 0; min-height: 72px; padding: 0 clamp(1rem, 4vw, 3rem); display: flex; align-items: center; gap: 2rem; color: #fff; background: rgba(18,35,29,.96); backdrop-filter: blur(14px); box-shadow: 0 8px 30px rgba(12,28,22,.16); }
.brand { display: flex; align-items: center; gap: .7rem; font-weight: 760; letter-spacing: -.01em; white-space: nowrap; }
.brand small { display: block; color: #a9beb5; font-size: .65rem; font-weight: 550; text-transform: uppercase; letter-spacing: .13em; }
.brand-mark { width: 34px; height: 34px; display: inline-grid; place-items: center; color: #132c22; background: linear-gradient(135deg, #e5c77c, var(--accent)); border-radius: 10px; font-family: Georgia, serif; font-size: 1.25rem; font-weight: 800; box-shadow: inset 0 1px 0 rgba(255,255,255,.45); }
.brand-mark-large { width: 50px; height: 50px; border-radius: 14px; font-size: 1.8rem; }
.main-nav { display: flex; align-self: stretch; align-items: center; gap: .15rem; }
.main-nav a { padding: .7rem .85rem; color: #c2d1cb; border-radius: 9px; font-size: .9rem; font-weight: 650; }
.main-nav a:hover { color: #fff; background: rgba(255,255,255,.07); }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: 1rem; font-size: .84rem; color: #c9d8d2; }
.user-menu form { margin: 0; }
.menu-button { display: none; margin-left: auto; color: #fff; background: none; border: 0; font-size: 1.35rem; }

.page-shell { width: min(1440px, 100%); margin: 0 auto; padding: clamp(1.5rem, 4vw, 3.5rem); }
.auth-shell { min-height: 100vh; display: grid; place-items: center; }
.page-heading { margin-bottom: 2rem; display: flex; align-items: flex-end; justify-content: space-between; gap: 1.5rem; }
.page-heading p { margin-bottom: 0; }
.heading-line, .heading-actions, .section-heading, .task-title-line, .row-actions { display: flex; align-items: center; gap: .75rem; }
.heading-actions { flex-wrap: wrap; justify-content: flex-end; }
.eyebrow { margin-bottom: .45rem !important; color: var(--brand); font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .14em; }
.muted { color: var(--muted); }
.pre-line { white-space: pre-line; }

.button { min-height: 40px; padding: .65rem 1rem; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid transparent; border-radius: 10px; font-weight: 720; font-size: .88rem; transition: transform .15s, box-shadow .15s, background .15s; }
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: .65; }
.button-primary { color: #fff; background: var(--brand); box-shadow: 0 8px 20px rgba(29,91,70,.18); }
.button-primary:hover { background: var(--brand-dark); }
.button-secondary { color: var(--brand-dark); background: #e7f0ec; border-color: #cfdfd8; }
.button-ghost { color: inherit; background: transparent; border-color: var(--line); }
.topbar .button-ghost { color: #fff; border-color: rgba(255,255,255,.18); }
.button-small { min-height: 34px; padding: .42rem .7rem; font-size: .78rem; }
.button-block { width: 100%; }
.text-link { color: var(--brand); font-weight: 750; }
.text-danger { padding: 0; color: var(--danger); background: none; border: 0; font-weight: 700; }
.icon-link { width: 32px; height: 32px; display: grid; place-items: center; color: var(--muted); border: 1px solid var(--line); border-radius: 9px; }

.alert { margin-bottom: 1.25rem; padding: .9rem 1rem; border-radius: 11px; font-size: .9rem; font-weight: 650; }
.alert-success { color: #165239; background: #ddf3e7; border: 1px solid #bce1cd; }
.alert-error { color: #7f2530; background: #f9e5e7; border: 1px solid #edc3c8; }
.validation { color: var(--danger); font-size: .8rem; }
.validation:empty { display: none; }
.validation ul { margin: .4rem 0; padding-left: 1.2rem; }

.auth-card { width: min(450px, 100%); padding: clamp(1.5rem, 5vw, 2.5rem); display: grid; gap: 2rem; background: rgba(255,255,255,.96); border: 1px solid rgba(255,255,255,.8); border-radius: 24px; box-shadow: 0 30px 80px rgba(20,54,42,.14); }
.auth-card-wide { width: min(620px, 100%); }
.auth-brand { display: flex; align-items: center; gap: .9rem; }
.auth-brand strong { display: block; font-size: 1.15rem; }
.auth-brand span { display: block; color: var(--muted); font-size: .8rem; }

.form-card { max-width: 920px; padding: clamp(1.25rem, 4vw, 2.25rem); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.form-stack { display: grid; gap: 1rem; }
.form-grid { display: grid; gap: 1rem; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid > div { min-width: 0; }
label { margin-bottom: .4rem; display: block; font-size: .82rem; font-weight: 750; }
input:not([type="checkbox"]):not([type="file"]), select, textarea { width: 100%; min-height: 44px; padding: .7rem .8rem; color: var(--ink); background: #fbfdfc; border: 1px solid #cad5d0; border-radius: 10px; outline: none; transition: border .15s, box-shadow .15s; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(29,91,70,.12); }
input[type="file"] { max-width: 100%; }
.check-row { margin: 0; display: flex; align-items: center; gap: .6rem; }
.check-row input { width: 17px; height: 17px; accent-color: var(--brand); }
.check-card { margin: 0; padding: .85rem; display: flex; align-items: center; gap: .7rem; border: 1px solid var(--line); border-radius: 11px; }
.check-card input { width: 18px; height: 18px; accent-color: var(--brand); }
.check-card span, .check-card small { display: block; }
.check-card small { margin-top: .15rem; color: var(--muted); font-weight: 500; }
.check-card.is-disabled { opacity: .55; }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 2.3rem !important; }
.input-suffix span { position: absolute; top: 50%; right: .8rem; color: var(--muted); transform: translateY(-50%); }
.form-actions { padding-top: .5rem; display: flex; justify-content: flex-end; }
.form-help { margin: 0; color: var(--muted); font-size: .8rem; }

.metric-grid { margin-bottom: 2rem; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1rem; }
.metric-card { min-height: 126px; padding: 1.2rem; display: flex; flex-direction: column; justify-content: space-between; background: var(--surface); border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 8px 25px rgba(20,54,42,.05); }
.metric-card span { color: var(--muted); font-size: .8rem; font-weight: 650; }
.metric-card strong { font-size: clamp(1.25rem, 2vw, 1.75rem); letter-spacing: -.04em; }
.metric-card-accent { color: #fff; background: linear-gradient(145deg, var(--brand), var(--brand-dark)); border-color: transparent; }
.metric-card-accent span { color: #c9ded5; }

.section-card, .calendar-card { padding: clamp(1.1rem, 3vw, 1.7rem); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.section-heading { margin-bottom: 1.25rem; justify-content: space-between; }
.section-heading p { margin: 0; color: var(--muted); font-size: .88rem; }
.count-pill { min-width: 30px; padding: .25rem .55rem; text-align: center; color: var(--brand); background: #e5f0eb; border-radius: 99px; font-size: .8rem; font-weight: 800; }
.empty-inline, .empty-state { display: grid; place-items: center; text-align: center; }
.empty-inline { padding: 2rem; color: var(--muted); }
.empty-state { min-height: 340px; padding: 3rem 1rem; background: var(--surface); border: 1px dashed #bdcbc5; border-radius: var(--radius); }
.empty-state p { max-width: 500px; color: var(--muted); }
.empty-icon { width: 54px; height: 54px; margin-bottom: 1rem; display: grid; place-items: center; color: var(--brand); background: #e6f0ec; border-radius: 50%; font-size: 1.5rem; font-weight: 700; }

.table-wrap { max-width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .9rem .8rem; text-align: left; border-bottom: 1px solid #e8eeeb; vertical-align: middle; font-size: .88rem; }
th { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; }
td strong, td small { display: block; }
td small { margin-top: .2rem; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
.row-actions { justify-content: flex-end; }

.status, .paid-pill { width: max-content; padding: .28rem .52rem; display: inline-flex; border-radius: 99px; font-size: .7rem; font-weight: 800; white-space: nowrap; }
.status-1, .task-status-1 { color: #6f5320; background: #f5ead4; }
.status-2, .task-status-2 { color: #1f5576; background: #deedf6; }
.status-3, .task-status-3, .status-active { color: #226044; background: #dff0e7; }
.status-4, .status-inactive { color: #6c7471; background: #e9edeb; }
.paid-pill { color: #fff; background: var(--brand); }

.project-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; }
.project-card { min-height: 350px; padding: 1.35rem; display: flex; flex-direction: column; gap: 1.15rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.project-card-head, .money-row { display: flex; align-items: center; justify-content: space-between; }
.project-card h2 { margin-bottom: .3rem; }
.project-card h2 a:hover { color: var(--brand); }
.project-card p { margin: 0; color: var(--muted); font-size: .88rem; }
.money-row { margin-top: auto; font-size: .85rem; }
.money-row span { color: var(--muted); }
.progress { height: 6px; overflow: hidden; background: #e8eeeb; border-radius: 99px; }
.progress span { height: 100%; display: block; background: linear-gradient(90deg, var(--brand), #5da083); border-radius: inherit; }
.project-totals { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.project-totals span, .project-totals strong { display: block; }
.project-totals span { margin-bottom: .2rem; color: var(--muted); font-size: .72rem; }

.finance-grid { margin-bottom: 1.5rem; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .8rem; }
.finance-grid article { padding: 1.05rem; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.finance-grid span, .finance-grid strong, .finance-grid small { display: block; }
.finance-grid span { color: var(--muted); font-size: .75rem; font-weight: 700; }
.finance-grid strong { margin: .5rem 0; font-size: 1.3rem; letter-spacing: -.03em; }
.finance-grid small { color: var(--muted); font-size: .68rem; line-height: 1.35; }
.finance-grid .finance-received { color: #fff; background: var(--brand); border-color: var(--brand); }
.finance-grid .finance-received span, .finance-grid .finance-received small { color: #c9ded5; }
.project-overview { margin-bottom: 1.5rem; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2rem; }
.project-overview p { margin-bottom: 0; color: var(--muted); line-height: 1.6; }
.date-list { margin: 0; display: flex; gap: 1.5rem; }
.date-list dt { color: var(--muted); font-size: .72rem; font-weight: 700; }
.date-list dd { margin: .25rem 0 0; font-weight: 750; }

.task-list { display: grid; gap: .8rem; }
.task-item { padding: 1.1rem; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1rem; background: #fbfdfc; border: 1px solid var(--line); border-radius: 13px; }
.task-main p { margin-bottom: .8rem; color: var(--muted); font-size: .86rem; line-height: 1.55; }
.task-main h3 { margin-top: .6rem; }
.task-meta { display: flex; flex-wrap: wrap; gap: 1rem; color: var(--muted); font-size: .78rem; }
.invoice-link { color: var(--brand); font-weight: 750; }
.task-actions { display: flex; align-items: flex-start; gap: .45rem; flex-wrap: wrap; justify-content: flex-end; }
.invoice-menu { position: relative; }
.invoice-menu summary { list-style: none; }
.invoice-menu summary::-webkit-details-marker { display: none; }
.invoice-panel { position: absolute; z-index: 10; top: calc(100% + .5rem); right: 0; width: 290px; padding: 1rem; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 18px 50px rgba(20,54,42,.18); }
.invoice-panel form { display: grid; gap: .7rem; }
.invoice-panel form + form { margin-top: .8rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.invoice-panel label { color: var(--muted); font-size: .72rem; }

.segmented { width: max-content; margin-bottom: 1rem; padding: .25rem; display: flex; background: #e4ebe7; border-radius: 10px; }
.segmented a { padding: .5rem .8rem; border-radius: 8px; color: var(--muted); font-size: .8rem; font-weight: 750; }
.segmented a.active { color: var(--ink); background: #fff; box-shadow: 0 3px 10px rgba(20,54,42,.08); }

.calendar-card { padding: 0; overflow: hidden; }
.calendar-toolbar { min-height: 74px; padding: 1rem 1.25rem; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 1rem; border-bottom: 1px solid var(--line); }
.calendar-toolbar h2 { margin: 0; text-align: center; font-size: 1.05rem; text-transform: capitalize; }
.calendar-toolbar select { width: min(240px, 100%); justify-self: end; }
.calendar-nav { display: flex; gap: .35rem; }
.calendar-loading, .calendar-error { min-height: 400px; display: grid; place-items: center; color: var(--muted); }
.calendar-desktop { overflow-x: auto; }
.calendar-grid { min-width: 980px; display: grid; grid-template-columns: 64px repeat(7, minmax(128px, 1fr)); }
.calendar-corner, .calendar-day-head { height: 62px; border-bottom: 1px solid var(--line); }
.calendar-corner { border-right: 1px solid var(--line); }
.calendar-day-head { display: grid; place-items: center; align-content: center; border-right: 1px solid var(--line); text-transform: capitalize; }
.calendar-day-head span { color: var(--muted); font-size: .68rem; font-weight: 700; }
.calendar-day-head strong { margin-top: .15rem; font-size: 1.05rem; }
.calendar-day-head.is-today { color: var(--brand); background: #eef6f2; }
.calendar-times { height: 960px; position: relative; border-right: 1px solid var(--line); }
.calendar-times span { height: 40px; padding: .15rem .55rem 0 0; display: block; text-align: right; color: #8a9691; font-size: .62rem; transform: translateY(-.45rem); }
.calendar-day { height: 960px; position: relative; border-right: 1px solid var(--line); background: #fff; }
.calendar-day.is-today { background: #fbfefc; }
.calendar-hour-line { position: absolute; right: 0; left: 0; height: 1px; background: #edf1ef; }
.calendar-event { position: absolute; z-index: 2; right: 4px; left: 4px; min-height: 28px; padding: .3rem .4rem; overflow: hidden; display: block; border-left: 3px solid; border-radius: 5px; font-size: .65rem; line-height: 1.25; }
.calendar-event:hover { z-index: 3; filter: brightness(.97); box-shadow: 0 4px 12px rgba(20,54,42,.12); }
.calendar-event strong, .calendar-event span, .calendar-event small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calendar-event span, .calendar-event small { margin-top: .12rem; opacity: .82; font-size: .58rem; }
.calendar-mobile { display: none; }

@media (max-width: 1100px) {
    .metric-grid { grid-template-columns: repeat(3, 1fr); }
    .project-grid { grid-template-columns: repeat(2, 1fr); }
    .finance-grid { grid-template-columns: repeat(3, 1fr); }
    .topbar { gap: 1rem; }
    .main-nav a { padding-inline: .55rem; }
    .user-menu > span { display: none; }
}

@media (max-width: 760px) {
    .topbar { min-height: 64px; flex-wrap: wrap; padding: .75rem 1rem; }
    .menu-button { display: block; }
    .main-nav { width: 100%; order: 4; display: none; align-items: stretch; flex-direction: column; padding: .4rem 0; }
    .main-nav.is-open { display: flex; }
    .main-nav a { padding: .7rem; }
    .user-menu { margin-left: 0; }
    .page-shell { padding: 1.25rem 1rem 2.5rem; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .heading-actions { width: 100%; justify-content: flex-start; }
    .metric-grid, .project-grid, .finance-grid { grid-template-columns: 1fr 1fr; }
    .metric-card { min-height: 110px; }
    .project-overview { grid-template-columns: 1fr; }
    .date-list { flex-wrap: wrap; }
    .task-item { grid-template-columns: 1fr; }
    .task-actions { justify-content: flex-start; }
    .invoice-panel { right: auto; left: 0; max-width: calc(100vw - 3rem); }
    .calendar-toolbar { grid-template-columns: 1fr 1fr; }
    .calendar-toolbar h2 { grid-column: 1 / -1; grid-row: 1; }
    .calendar-toolbar select { width: 100%; }
    .calendar-desktop { display: none; }
    .calendar-mobile { padding: 1rem; display: grid; gap: 1rem; }
    .calendar-mobile section { padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
    .calendar-mobile section:last-child { border-bottom: 0; }
    .calendar-mobile h3 { text-transform: capitalize; }
    .calendar-empty-day { margin: 0; color: var(--muted); font-size: .82rem; }
    .calendar-mobile-event { margin-top: .55rem; padding: .7rem .8rem; display: block; background: #f8fbf9; border: 1px solid var(--line); border-left: 4px solid; border-radius: 9px; }
    .calendar-mobile-event strong, .calendar-mobile-event span, .calendar-mobile-event small { display: block; }
    .calendar-mobile-event span, .calendar-mobile-event small { margin-top: .2rem; color: var(--muted); font-size: .72rem; }
}

@media (max-width: 520px) {
    .form-grid.two, .metric-grid, .finance-grid { grid-template-columns: 1fr; }
    .heading-actions .button { flex: 1; }
    .project-totals { grid-template-columns: 1fr; }
    .section-card { padding: 1rem; }
    th, td { padding: .75rem .6rem; }
    .calendar-toolbar { grid-template-columns: 1fr; }
    .calendar-toolbar h2, .calendar-nav, .calendar-toolbar select { grid-column: 1; justify-self: stretch; }
    .calendar-nav .button { flex: 1; }
}
