:root {
  --brand: #0f5c4d;
  --brand-dark: #0a3f35;
  --brand-soft: #e6f2ef;
  --accent: #d99a2b;
  --surface: #ffffff;
  --bg: #f4f6f5;
  --border: #e2e7e5;
  --text: #1d2a27;
  --muted: #6b7a76;
  --sidebar-w: 248px;
}

body.app { background: var(--bg); color: var(--text); font-size: .935rem; }

.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
/* !important: Bootstrap's .offcanvas-lg forces a transparent background on large screens. */
.sidebar { width: var(--sidebar-w); background-color: var(--brand-dark) !important; color: #cfe3de; flex-shrink: 0; }
@media (min-width: 992px) {
  .sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; visibility: visible !important; transform: none !important; }
}
.sidebar-brand { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { background: var(--accent); color: #fff; font-weight: 700; font-size: .8rem; border-radius: 8px; padding: .35rem .45rem; letter-spacing: .5px; }
.brand-name { color: #fff; font-weight: 600; line-height: 1.2; }
.sidebar-nav { padding: .75rem .6rem; display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav .nav-link { display: flex; align-items: center; gap: .7rem; color: #cfe3de; padding: .55rem .75rem; border-radius: 8px; text-decoration: none; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-nav .nav-link.active { background: var(--brand); color: #fff; }
.sidebar-nav .nav-link.disabled { opacity: .5; cursor: default; }
.sidebar-nav .nav-link i { font-size: 1.05rem; }
.sidebar-nav .soon { margin-left: auto; font-size: .65rem; background: rgba(255,255,255,.12); padding: 1px 6px; border-radius: 10px; }
.nav-section { text-transform: uppercase; font-size: .7rem; letter-spacing: 1px; color: #8fb3aa; padding: 1rem .75rem .35rem; }

/* Main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.content { padding: 1.5rem 1.25rem 3rem; max-width: 1400px; width: 100%; }
@media (max-width: 575px) { .content { padding: 1rem 1rem 2rem; } }

.user-chip { display: flex; align-items: center; gap: .5rem; border: 1px solid var(--border); background: var(--surface); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 600; }
.role-badge { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.role-badge.is-admin { background: #fbefd9; color: #8a5b07; }

/* Page elements */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1.25rem; }
.page-head h1 { font-size: 1.45rem; font-weight: 700; margin: 0; }
.page-head .sub { color: var(--muted); margin: 0; width: 100%; }
.card { border: 1px solid var(--border); border-radius: 12px; box-shadow: none; }
.card-header { background: transparent; border-bottom: 1px solid var(--border); font-weight: 600; }
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-brand:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.form-label { font-weight: 500; }
.text-muted-2 { color: var(--muted); }

.stat-card { padding: 1rem 1.1rem; display: flex; align-items: center; gap: .9rem; }
.stat-icon { width: 44px; height: 44px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); display: flex; align-items: center; justify-content: center; font-size: 1.25rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; }

/* Permission matrix */
.perm-table th, .perm-table td { vertical-align: middle; }
.perm-table td.check { text-align: center; width: 84px; }
.perm-table .form-check-input { width: 1.25em; height: 1.25em; cursor: pointer; }
.perm-table .module-desc { color: var(--muted); font-size: .8rem; }
.perm-admin-only { background: #fbf6ec; }

.table > :not(caption) > * > * { padding: .7rem .75rem; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; background: #fafbfa; }

/* Dashboard */
a.card, a.metric, a.pipe-row { text-decoration: none; color: inherit; }
a[href].card:hover, a[href].metric:hover { border-color: var(--brand); }
.kpi-card { padding: 1rem 1.1rem; border-top: 4px solid var(--brand); }
.kpi-blue { border-top-color: #2f6fb5; }
.kpi-amber { border-top-color: var(--accent); }
.kpi-green { border-top-color: #2e9e5b; }
.kpi-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 2rem; font-weight: 700; line-height: 1.15; }
.kpi-hint { font-size: .8rem; color: var(--muted); }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.metric { padding: .9rem 1rem; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); border-radius: 0; border-left: 0; border-top: 0; }
a[href].metric:hover { background: var(--brand-soft); }
.metric-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.metric-label { font-size: .85rem; font-weight: 500; }
.metric-hint { font-size: .75rem; color: var(--muted); }
.metric-alert .metric-value { color: #b42318; }
.chart-box { position: relative; height: 240px; }
.pipe-row { display: grid; grid-template-columns: minmax(120px, 42%) 1fr 36px; align-items: center; gap: .6rem; padding: .3rem 0; }
.pipe-label { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pipe-bar { height: 8px; background: #edf1ef; border-radius: 4px; overflow: hidden; }
.pipe-bar span { display: block; height: 100%; background: var(--brand); border-radius: 4px; min-width: 4px; }
.pipe-count { text-align: right; font-weight: 600; font-size: .85rem; }
a[href].pipe-row:hover .pipe-label { color: var(--brand); text-decoration: underline; }

.admin-card { border-color: #f0dcb4; }
.admin-card > .card-header { background: #fbf6ec; color: #8a5b07; }
.money { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pos-owe { color: #1c7a43; font-weight: 600; }
.pos-extra { color: #b42318; font-weight: 600; }
.grade-A { background: #e3f4ea; color: #1c7a43; }
.grade-B { background: #e7f0fb; color: #1d5fa8; }
.grade-C { background: #fdf0dc; color: #8a5b07; }

/* Workers */
.filter-card .form-label { margin-bottom: .2rem; color: var(--muted); }
.chip-row { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .7rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; font-size: .82rem; }
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip-count { background: rgba(0,0,0,.07); border-radius: 999px; padding: 0 .45rem; font-weight: 600; font-size: .75rem; }
.chip.active .chip-count { background: rgba(255,255,255,.22); }

.status-badge { display: inline-block; padding: .2rem .55rem; border-radius: 6px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.tone-process { background: #e7f0fb; color: #1d5fa8; }
.tone-done { background: #e3f4ea; color: #1c7a43; }
.tone-alert { background: #fde8e8; color: #b42318; }
.tone-closed { background: #eef0ef; color: #5b6763; }

.worker-table .row-link { cursor: pointer; }
.thumb { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.thumb-empty { display: inline-flex; align-items: center; justify-content: center; background: var(--brand-soft); color: var(--brand); }
.mini-steps { display: flex; gap: 3px; }
.mini-step { width: 14px; height: 6px; border-radius: 3px; background: #e2e7e5; }
.mini-step.done { background: var(--brand); }
.mini-step.current { background: var(--accent); }
.mini-step.off { background: #f3c4c0; }

.steps { display: flex; justify-content: space-between; position: relative; gap: .25rem; }
.steps::before { content: ""; position: absolute; top: 16px; left: 4%; right: 4%; height: 3px; background: var(--border); }
.step { position: relative; display: flex; flex-direction: column; align-items: center; gap: .35rem; flex: 1; min-width: 0; }
.step-dot { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600;
  background: var(--surface); border: 3px solid var(--border); color: var(--muted); z-index: 1; }
.step.done .step-dot { background: var(--brand); border-color: var(--brand); color: #fff; }
.step.current .step-dot { border-color: var(--accent); color: var(--accent); }
.step.off .step-dot { border-color: #f3c4c0; }
.step-label { font-size: .78rem; color: var(--muted); text-align: center; }
.step.done .step-label, .step.current .step-label { color: var(--text); font-weight: 600; }
@media (max-width: 575px) { .step-label { font-size: .65rem; } .step-dot { width: 28px; height: 28px; } .steps::before { top: 13px; } }

.photo-current { height: 120px; border: 1px solid var(--border); border-radius: 8px; background: #f4f6f5; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.photo-current img { max-width: 100%; max-height: 100%; object-fit: contain; }
.worker-pics { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
.worker-pics a { display: block; height: 130px; border: 1px solid var(--border); border-radius: 8px; background: #f4f6f5; overflow: hidden; }
.worker-pics img { width: 100%; height: 100%; object-fit: contain; }
.worker-pics .missing { height: 130px; border: 1px dashed var(--border); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .8rem; text-align: center; padding: .5rem; }
.profile-photo {width: 120px; height: 120px; border-radius: 50%; object-fit: cover; }
.profile-photo-empty { display: inline-flex; align-items: center; justify-content: center; background: var(--brand-soft); color: var(--brand); font-size: 3rem; }
.kv { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: .35rem .75rem; }
.kv dt { font-weight: 500; color: var(--muted); }
.kv dd { margin: 0; }
.audit { padding: .25rem .25rem 0; }

/* CV builder */
.builder { display: grid; grid-template-columns: 230px minmax(0, 1fr) 290px; gap: 1rem; align-items: start; }
@media (max-width: 1199px) { .builder { grid-template-columns: 200px minmax(0, 1fr); } .builder-props { grid-column: 1 / -1; } }
@media (max-width: 767px) { .builder { grid-template-columns: 1fr; } }
.builder-palette, .builder-props { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .8rem; }
@media (min-width: 768px) {
  .builder-palette, .builder-props { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow-y: auto; }
}
@media (max-width: 767px) { .builder-palette { max-height: 260px; overflow-y: auto; } }
.palette-title, .props-title { font-weight: 600; font-size: .85rem; margin-bottom: .5rem; }
.props-sub { font-size: .8rem; color: var(--muted); margin-bottom: .5rem; }
.palette-list { display: flex; flex-direction: column; gap: 4px; }
.palette-item, .palette-field { border: 1px solid var(--border); border-radius: 8px; padding: .4rem .55rem; background: #fafbfa; cursor: grab; font-size: .82rem; user-select: none; }
.palette-item:hover, .palette-field:hover { border-color: var(--brand); background: var(--brand-soft); }
.palette-item i { color: var(--brand); margin-right: .25rem; }
.palette-field i { color: var(--muted); }
.palette-group { font-size: .7rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: .6rem 0 .25rem; }
.builder-canvas-wrap { overflow-x: auto; background: #e4e8e6; border-radius: 12px; padding: 16px; min-height: 70vh; }
.builder-page { box-shadow: 0 2px 12px rgba(0,0,0,.12); }
.blk { position: relative; outline: 1px dashed transparent; outline-offset: 2px; border-radius: 2px; cursor: pointer; }
.blk:hover { outline-color: #9db5ad; }
.blk.is-selected { outline: 2px solid var(--brand); }
.blk.has-selection:not(.is-selected) { outline: 1px dashed var(--brand); }
.blk-bar { position: absolute; top: -11px; right: 4px; display: none; gap: 2px; z-index: 3; background: var(--brand); border-radius: 6px; padding: 1px 4px; align-items: center; }
.blk:hover .blk-bar, .blk.is-selected .blk-bar { display: flex; }
.blk-bar .blk-name { color: #fff; font-size: 10px; padding: 0 4px; font-family: system-ui, sans-serif; }
.blk-bar button, .blk-handle { background: none; border: 0; color: #fff; font-size: 11px; padding: 0 3px; line-height: 18px; }
.blk-handle { cursor: grab; }
.cv-rows { min-height: 28px; border: 1px solid #c9ced6; border-top: 0; }
.cv-row { display: grid; grid-template-columns: 14px 34% 1fr 34% 18px; align-items: center; border-top: 1px solid #c9ced6; min-height: 22px; }
.cv-row > span { padding: 2px 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cv-row .row-en, .cv-row .row-ar { background: #f1f4f8; font-weight: 600; }
.cv-row .row-val { text-align: center; font-weight: 600; border-left: 1px solid #c9ced6; border-right: 1px solid #c9ced6; }
.cv-row .row-handle { cursor: grab; color: #9aa; padding: 0; text-align: center; }
.cv-row .row-del { border: 0; background: none; color: #c33; opacity: 0; padding: 0; }
.cv-row:hover .row-del { opacity: 1; }
.cv-row.is-selected { box-shadow: inset 0 0 0 2px var(--accent); }
.cv-rows .palette-field { margin: 2px; }
.cv-drop-hint { color: #8a9a95; text-align: center; padding: 6px; font-style: italic; border-top: 1px solid #c9ced6; }
.cv-drop-hint.big { grid-column: 1 / -1; border: 2px dashed #c5d2cd; padding: 60px 10px; font-size: 14px; }
.spacer-box { background: repeating-linear-gradient(45deg, #f3f5f4, #f3f5f4 6px, #fff 6px, #fff 12px); }
.sortable-ghost { opacity: .4; }
.logo-thumb { max-height: 36px; max-width: 120px; object-fit: contain; border: 1px solid var(--border); border-radius: 4px; }
.add-item { display: grid; gap: 4px; margin-top: .5rem; }
.template-card .cv-mini { height: 6px; border-radius: 3px; }
.layout-hint { font-size: 10px; color: #6b7a76; font-style: italic; padding: 2px 4px; font-family: system-ui, sans-serif; }
.page-break-line { border-top: 2px dashed #9db5ad; margin: 10px 0; text-align: center; height: 0; }
.page-break-line span { position: relative; top: -10px; background: #e4e8e6; color: #44615a; font-size: 10px; padding: 1px 8px; border-radius: 8px; font-family: system-ui, sans-serif; }
.image-library { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.image-item { display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 6px; padding: 3px 4px; min-width: 0; }
.image-item img { width: 46px; height: 26px; object-fit: contain; background: #f4f6f5; border-radius: 3px; flex-shrink: 0; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand)); }
.login-card { width: 100%; max-width: 400px; border-radius: 16px; border: 0; }
.login-card .brand-mark { font-size: 1rem; padding: .5rem .65rem; }
