:root {
  --bs-primary: #d9480f;
  --bs-primary-rgb: 217, 72, 15;
  --bs-link-color: #c2410c;
  --bs-link-hover-color: #9a3412;
  --bs-body-bg: #f4f5f7;
  --bs-body-font-size: .92rem;
  --bs-border-radius: .5rem;
  --sidebar-w: 256px;
  --ink: #1c2430;
  --ink-soft: #2a3444;
}
body { background: var(--bs-body-bg); color: #222b38; }
.btn-primary { --bs-btn-bg: #d9480f; --bs-btn-border-color: #d9480f; --bs-btn-hover-bg: #b93c0a; --bs-btn-hover-border-color: #b93c0a; --bs-btn-active-bg: #a03409; --bs-btn-active-border-color: #a03409; --bs-btn-disabled-bg: #d9480f; --bs-btn-disabled-border-color: #d9480f; }
.btn-outline-primary { --bs-btn-color: #d9480f; --bs-btn-border-color: #d9480f; --bs-btn-hover-bg: #d9480f; --bs-btn-hover-border-color: #d9480f; --bs-btn-active-bg: #d9480f; --bs-btn-active-border-color: #d9480f; }
.text-bg-primary { background-color: #d9480f !important; }
.bg-primary { background-color: #d9480f !important; }
.text-primary { color: #d9480f !important; }
.progress-bar.bg-primary { background-color: #d9480f !important; }
.form-control:focus, .form-select:focus { border-color: #f08c5a; box-shadow: 0 0 0 .2rem rgba(217, 72, 15, .15); }
.form-check-input:checked { background-color: #d9480f; border-color: #d9480f; }

/* Sidebar */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: var(--ink); color: #c9d1dc; z-index: 1040; display: flex; flex-direction: column; transition: transform .2s ease; }
.sidebar-brand { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.1rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-mark { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, #f76707, #d9480f); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 1.25rem; flex: 0 0 auto; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text small { color: #8b97a8; font-size: .72rem; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: .5rem .6rem 1rem; }
.nav-heading { text-transform: uppercase; letter-spacing: .08em; font-size: .68rem; color: #6f7c8e; padding: 1rem .6rem .35rem; }
.nav-link-item { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: .5rem; color: #c9d1dc; text-decoration: none; font-size: .9rem; margin-bottom: 2px; }
.nav-link-item i { font-size: 1.05rem; width: 1.2rem; text-align: center; opacity: .85; }
.nav-link-item:hover { background: var(--ink-soft); color: #fff; }
.nav-link-item.active { background: rgba(247, 103, 7, .16); color: #ffb37a; box-shadow: inset 3px 0 0 #f76707; }
.sidebar-foot { padding: .7rem 1.1rem; font-size: .72rem; color: #6f7c8e; border-top: 1px solid rgba(255,255,255,.07); }
.sidebar-backdrop { display: none; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 1030; background: #fff; border-bottom: 1px solid #e5e8ee; padding: .55rem 1.25rem; display: flex; align-items: center; min-height: 58px; }
.topbar-title { font-weight: 600; font-size: 1.02rem; }
.content { padding: 1.4rem 1.4rem 3rem; flex: 1; max-width: 1500px; width: 100%; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: .8rem; }
.notif-menu { width: 340px; max-width: 92vw; }
.notif-item.unread { background: #fff6f0; }
.notif-item { white-space: normal; border-bottom: 1px solid #f0f1f4; }

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1035; }
  .main { margin-left: 0; }
  .content { padding: 1rem .85rem 3rem; }
}

/* Cards / tiles */
.card { border: 1px solid #e6e9ef; border-radius: .7rem; box-shadow: 0 1px 2px rgba(20, 30, 50, .04); }
.card-header { background: #fff; border-bottom: 1px solid #eef0f4; font-weight: 600; padding: .8rem 1.1rem; }
.stat-tile { padding: 1rem 1.1rem; height: 100%; }
.stat-tile .label { color: #6b7686; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.stat-tile .value { font-size: 1.3rem; font-weight: 700; line-height: 1.2; margin-top: .15rem; }
.stat-tile .sub { color: #6b7686; font-size: .78rem; }
.stat-icon { width: 42px; height: 42px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.25rem; background: #fff1e8; color: #d9480f; }
.page-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: 1.1rem; }
.page-head h1 { font-size: 1.35rem; margin: 0; font-weight: 700; }
.page-head .sub { color: #6b7686; font-size: .85rem; }

/* Tables */
.table > :not(caption) > * > * { padding: .65rem .8rem; }
.table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: #6b7686; background: #f8f9fb; border-bottom: 1px solid #e6e9ef; white-space: nowrap; }
.table-hover tbody tr:hover { background: #fffaf6; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-actions a, .table-actions button { padding: .15rem .45rem; }
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filter-bar .form-control, .filter-bar .form-select { max-width: 220px; }
.chip { display: inline-block; padding: .28rem .7rem; border-radius: 999px; background: #fff; border: 1px solid #dfe3ea; color: #3b4658; text-decoration: none; font-size: .8rem; margin: 0 .25rem .35rem 0; }
.chip:hover { border-color: #d9480f; color: #d9480f; }
.chip.active { background: #d9480f; border-color: #d9480f; color: #fff; }
.chip .n { opacity: .75; margin-left: .25rem; }

/* Detail pages */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: .35rem .9rem; font-size: .88rem; }
.kv dt { color: #6b7686; font-weight: 500; }
.kv dd { margin: 0; }
@media (max-width: 575.98px) { .kv { grid-template-columns: 1fr; } .kv dt { margin-top: .5rem; } }
.nav-tabs .nav-link { color: #4a5568; }
.nav-tabs .nav-link.active { color: #d9480f; font-weight: 600; border-bottom-color: #fff; }
.tab-wrap { overflow-x: auto; white-space: nowrap; }
.tab-wrap .nav { flex-wrap: nowrap; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: #6b7686; font-weight: 600; margin-bottom: .6rem; }

/* Editors */
.editor-table input, .editor-table select { min-width: 70px; }
.editor-table td { vertical-align: middle; padding: .3rem .35rem !important; }
.editor-table .desc { min-width: 220px; }
.editor-table .section-row td { background: #f3f4f7; font-weight: 600; }
.totals-box { background: #fff8f3; border: 1px solid #ffd9c2; border-radius: .6rem; padding: 1rem 1.1rem; }
.totals-box .line { display: flex; justify-content: space-between; padding: .18rem 0; }
.totals-box .line.total { border-top: 2px solid #d9480f; margin-top: .4rem; padding-top: .55rem; font-weight: 700; font-size: 1.1rem; }

/* BOQ */
.boq-section > .card-header { background: #f3f4f7; }
.boq-sub { margin-left: 1.25rem; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; }
.gallery a { display: block; aspect-ratio: 1; border-radius: .5rem; overflow: hidden; background: #e9ecf1; }
.gallery img { width: 100%; height: 100%; object-fit: cover; }

/* Auth */
.auth-bg { min-height: 100vh; background: linear-gradient(135deg, #1c2430 0%, #2d3a4f 55%, #d9480f 160%); }
.auth-card { max-width: 430px; margin: 8vh auto 0; }
.auth-side { color: #fff; }

.perm-grid { columns: 1; }
@media (min-width: 992px) { .perm-grid { columns: 2; column-gap: 1.5rem; } }
.perm-group { break-inside: avoid; }

@media print {
  .sidebar, .topbar, .no-print, .sidebar-backdrop { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  body { background: #fff; }
  .card { border: 0; box-shadow: none; }
}

@media (max-width: 575.98px) { .stat-tile .value { font-size: .98rem; white-space: nowrap; } .stat-tile { padding: .8rem .8rem; } .stat-tile .stat-icon { display: none; } .stat-tile .sub { overflow-wrap: anywhere; } }

/* Gantt */
.gantt-wrap { overflow: hidden; }
.gantt-scroll { overflow: auto; max-height: 72vh; }
.gantt-inner { position: relative; }
.g-row { display: flex; border-bottom: 1px solid #eef0f4; }
.g-row.g-late { background: #fff8f6; }
.g-head { position: sticky; top: 0; z-index: 6; background: #f8f9fb; border-bottom: 1px solid #dfe3ea; }
.g-left { position: sticky; left: 0; z-index: 5; width: var(--leftw); flex: 0 0 var(--leftw); display: flex; align-items: center; gap: .35rem; padding: 0 .5rem; background: #fff; border-right: 1px solid #dfe3ea; font-size: .82rem; overflow: hidden; }
.g-row.g-late .g-left { background: #fff8f6; }
.g-head .g-left { background: #f8f9fb; z-index: 7; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: #6b7686; font-weight: 600; }
.g-left .c-wbs { width: 38px; flex: 0 0 38px; font-size: .75rem; }
.g-left .c-name { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-left .c-date { width: 50px; flex: 0 0 50px; font-size: .75rem; text-align: right; }
.g-left .c-pct { width: 32px; flex: 0 0 32px; text-align: right; font-variant-numeric: tabular-nums; }
.g-name { color: #222b38; text-decoration: none; }
.g-name:hover { color: #d9480f; }
.g-time { position: relative; flex: 0 0 auto; }
.g-band { position: absolute; left: 0; right: 0; }
.g-cell { position: absolute; top: 0; bottom: 0; border-left: 1px solid #dfe3ea; font-size: .7rem; color: #495057; padding: 3px 0 0 4px; overflow: hidden; white-space: nowrap; }
.g-cell.g-sub { color: #868e96; font-size: .66rem; text-align: center; padding-left: 0; }
.g-cell.wk { background: #f1f3f5; }
.g-bar { position: absolute; top: 9px; height: 20px; border-radius: 4px; background: #a5d8ff; border: 1px solid #339af0; overflow: hidden; z-index: 2; }
.g-bar .g-fill { position: absolute; inset: 0 auto 0 0; background: #339af0; }
.g-bar .g-lbl { position: absolute; left: 6px; top: 1px; font-size: .68rem; font-weight: 600; color: #fff; text-shadow: 0 0 2px rgba(0,0,0,.4); }
.g-bar.g-crit { background: #ffc9c9; border-color: #e03131; } .g-bar.g-crit .g-fill { background: #e03131; }
.g-bar.g-done { background: #b2f2bb; border-color: #2f9e44; } .g-bar.g-done .g-fill { background: #2f9e44; }
.g-bar.g-parent { top: 13px; height: 12px; background: #868e96; border-color: #343a40; border-radius: 2px; } .g-bar.g-parent .g-fill { background: #343a40; } .g-bar.g-parent .g-lbl { display: none; }
.g-bar.late { box-shadow: 0 0 0 2px rgba(224,49,49,.25); }
.g-mile { position: absolute; top: 11px; width: 16px; height: 16px; background: #f59f00; transform: rotate(45deg) scale(.78); z-index: 2; border: 1px solid #b06f00; }
.g-mile.g-done { background: #2f9e44; border-color: #1b7a30; }
.g-base { position: absolute; bottom: 3px; height: 4px; background: #adb5bd; border-radius: 2px; z-index: 1; }
.g-svg { position: absolute; top: 0; left: var(--leftw); pointer-events: none; z-index: 3; }
.g-key { display: inline-block; width: 14px; height: 9px; border-radius: 2px; vertical-align: middle; margin-right: 3px; }
@media (max-width: 767.98px) {
  .gantt-wrap { --leftw: 170px !important; }
  .g-left .c-wbs, .g-left .c-date { display: none; }
  .g-left { padding: 0 .4rem; font-size: .78rem; }
}
@media print {
  .gantt-scroll { max-height: none; overflow: visible; }
  .gantt-wrap { overflow: visible; }
}

/* Message threads (portal and staff inbox) */
.msg { max-width: 82%; padding: .65rem .85rem; border-radius: .8rem; margin-bottom: .7rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine { margin-left: auto; background: #fff0e6; border: 1px solid #ffd8bf; }
.msg.theirs { background: #fff; border: 1px solid #e3e6ec; }
.msg .meta { font-size: .72rem; color: #6b7686; margin-bottom: .15rem; }
@media (max-width: 575.98px) { .msg { max-width: 94%; } }
