:root {
    --bg: #f5f6f8; --card: #fff; --ink: #1c2230; --muted: #6b7385; --line: #e3e6ec; --brand: #ff5b2e; --brand-d: #d9431a;
    --green: #16a34a; --red: #dc2626; --yellow: #ca8a04; --blue: #2563eb; --radius: 12px;
}
@media (prefers-color-scheme: dark) {
    :root { --bg: #12151c; --card: #1a1f29; --ink: #e8ebf2; --muted: #98a1b5; --line: #2a303d; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--ink); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
a { color: var(--brand-d); text-decoration: none; }
.muted { color: var(--muted); } .c { text-align: center; } .r { text-align: right; } .small { font-size: .85rem; }
.hide { display: none !important; }

/* shell */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--ink); }
.logo { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; }
.top .sp { flex: 1; }
.who { font-size: .85rem; color: var(--muted); text-align: right; line-height: 1.2; }
.layout { display: flex; min-height: calc(100vh - 56px); }
.side { width: 210px; flex: none; padding: .75rem; border-right: 1px solid var(--line); background: var(--card); }
.side a { display: flex; gap: .6rem; align-items: center; padding: .55rem .7rem; border-radius: 9px; color: var(--ink); font-weight: 500; }
.side a.on { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand-d); font-weight: 600; }
.side a:hover { background: var(--bg); }
main { flex: 1; min-width: 0; padding: 1rem; max-width: 1400px; }
.bottom { display: none; }
@media (max-width: 860px) {
    .hide-sm { display: none !important; }
    .side { display: none; }
    main { padding: .75rem .75rem 5rem; }
    .bottom { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--line); overflow-x: auto; }
    .bottom a { flex: 1 0 auto; min-width: 64px; padding: .45rem .5rem; text-align: center; font-size: .72rem; color: var(--muted); }
    .bottom a b { display: block; font-size: 1.15rem; font-weight: 400; }
    .bottom a.on { color: var(--brand-d); font-weight: 600; }
}

/* components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card > h2:first-child, .card > h3:first-child { margin-bottom: .75rem; }
.grid { display: grid; gap: .75rem; } .g2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); } .g3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); } .g4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.kpi small { color: var(--muted); display: block; } .kpi b { font-size: 1.25rem; } .kpi.red b { color: var(--red); } .kpi.green b { color: var(--green); }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; } .row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
.btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: .5rem .9rem; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; } .btn.primary:hover { background: var(--brand-d); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; } .btn:disabled { opacity: .5; cursor: default; }
.icon { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: .2rem .4rem; } .icon:hover { color: var(--red); }
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .2rem; font-weight: 600; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); border-color: var(--brand); }
input[readonly] { background: var(--bg); } textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: .7rem; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .75rem; font-weight: 600; background: #e5e7eb; color: #374151; white-space: nowrap; }
.badge.green { background: #dcfce7; color: #166534; } .badge.red { background: #fee2e2; color: #991b1b; } .badge.blue { background: #dbeafe; color: #1e40af; }
.badge.orange { background: #ffedd5; color: #9a3412; } .badge.yellow { background: #fef9c3; color: #854d0e; } .badge.gray { background: #e5e7eb; color: #374151; }
.tbl-wrap { overflow-x: auto; margin-bottom: .75rem; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
.tbl th { font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--bg); position: sticky; top: 0; }
.tbl td.wrap { white-space: normal; min-width: 180px; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: color-mix(in srgb, var(--brand) 6%, transparent); }
.tbl.edit td { padding: .2rem .25rem; } .tbl.edit input, .tbl.edit select { padding: .3rem .4rem; min-width: 70px; }
.tbl tfoot td { font-weight: 700; background: var(--bg); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: .55rem .9rem; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand-d); border-bottom-color: var(--brand); }
.totals { position: sticky; top: 64px; } .totals .l { display: flex; justify-content: space-between; padding: .2rem 0; } .totals .big { font-size: 1.3rem; font-weight: 800; color: var(--brand-d); }
.totals hr { border: 0; border-top: 1px dashed var(--line); margin: .5rem 0; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; } @media (max-width: 1000px) { .cols { grid-template-columns: 1fr; } .totals { position: static; } }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; } .bar i { display: block; height: 100%; background: var(--green); }
.bar.warn i { background: var(--yellow); } .bar.bad i { background: var(--red); }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(10, 14, 22, .55); z-index: 50; display: grid; place-items: center; padding: 1rem; overflow-y: auto; }
.modal-box { background: var(--card); border-radius: var(--radius); padding: 1.2rem; width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto; } .modal-box.wide { max-width: 760px; }
#toast { position: fixed; left: 50%; bottom: 5rem; transform: translate(-50%, 20px); background: #111827; color: #fff; padding: .6rem 1rem; border-radius: 9px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); } #toast.bad { background: var(--red); }

/* auth */
.auth { max-width: 380px; margin: 8vh auto; padding: 0 1rem; } .auth .card { padding: 1.5rem; }

/* kanban */
.kanban { display: flex; gap: .75rem; overflow-x: auto; padding-bottom: 1rem; align-items: flex-start; -webkit-overflow-scrolling: touch; }
.col { flex: 0 0 240px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem; min-height: 160px; }
.col.over { outline: 2px dashed var(--brand); }
.col h3 { display: flex; justify-content: space-between; font-size: .85rem; padding: .25rem .3rem .5rem; text-transform: uppercase; letter-spacing: .03em; }
.kcard { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 9px; padding: .6rem; margin-bottom: .5rem; cursor: grab; }
.kcard.late { border-left-color: var(--red); } .kcard small { color: var(--muted); display: block; } .kcard b { display: block; }
.kcard select { margin-top: .4rem; font-size: .8rem; padding: .2rem; }

/* gantt */
.gantt { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); max-height: 75vh; }
.g-head, .g-row { display: flex; } .g-label { flex: none; width: 170px; position: sticky; left: 0; z-index: 3; background: var(--card); border-right: 1px solid var(--line); padding: .35rem .6rem; font-size: .82rem; display: flex; flex-direction: column; justify-content: center; }
.g-track { position: relative; flex: none; height: 38px; border-bottom: 1px solid var(--line); background-image: linear-gradient(to right, var(--line) 1px, transparent 1px); }
.g-bar { position: absolute; top: 9px; height: 20px; border-radius: 5px; opacity: .92; font-size: .68rem; color: #fff; padding: 0 4px; overflow: hidden; white-space: nowrap; line-height: 20px; cursor: pointer; }
.g-bar.done { opacity: .45; } .g-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--red); z-index: 2; } .g-deliv { position: absolute; top: 12px; width: 14px; height: 14px; transform: rotate(45deg); background: var(--ink); z-index: 1; }
.g-months, .g-weeks { display: flex; } .g-months > div { border-left: 1px solid var(--line); font-size: .75rem; font-weight: 700; padding: .2rem .3rem; overflow: hidden; white-space: nowrap; }
.g-weeks > div { font-size: .62rem; color: var(--muted); text-align: center; border-left: 1px solid var(--line); padding: .15rem 0; }
.g-load { display: flex; } .g-load > div { text-align: center; font-size: .7rem; font-weight: 700; padding: .3rem 0; border-left: 1px solid var(--line); }
.g-head { position: sticky; top: 0; z-index: 4; background: var(--card); flex-direction: column; }
.legend { display: flex; flex-wrap: wrap; gap: .75rem; font-size: .8rem; margin: .5rem 0; } .legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* stepper (customer portal) */
.steps { display: flex; gap: 4px; margin: .6rem 0; } .step { flex: 1; text-align: center; font-size: .72rem; } .step i { display: block; height: 8px; border-radius: 99px; background: var(--line); margin-bottom: 4px; }
.step.done i { background: var(--green); } .step.doing i { background: var(--brand); } .step.doing b { color: var(--brand-d); } .step small { display: block; color: var(--muted); }

/* print (budget PDF) */
.print-sheet { background: #fff; color: #111; max-width: 800px; margin: 0 auto; padding: 2rem; border: 1px solid var(--line); border-radius: var(--radius); }
.print-sheet h1 { font-size: 1.5rem; } .print-sheet table { width: 100%; border-collapse: collapse; margin: 1rem 0; } .print-sheet td, .print-sheet th { padding: .5rem; border-bottom: 1px solid #ddd; text-align: left; }
.print-sheet .total { font-size: 1.4rem; font-weight: 800; }
@media print {
    body { background: #fff; } .top, .side, .bottom, .noprint, #toast { display: none !important; } .layout { display: block; } main { padding: 0; max-width: none; }
    .print-sheet { border: 0; padding: 0; max-width: none; } @page { margin: 16mm; }
}

/* phone: list tables become stacked cards */
@media (max-width: 640px) {
    .tbl.stack thead { display: none; }
    .tbl.stack, .tbl.stack tbody { display: block; }
    .tbl.stack tr { display: block; padding: .55rem .8rem; border-bottom: 1px solid var(--line); }
    .tbl.stack td { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; border: 0; padding: .12rem 0; white-space: normal; text-align: right; }
    .tbl.stack td[data-l]::before { content: attr(data-l); color: var(--muted); font-size: .76rem; text-align: left; flex: none; }
    .tbl.stack td.wrap { min-width: 0; }
    .tbl.stack td.acts { justify-content: flex-end; padding-top: .4rem; }
}
