/* ============================================================
   FAMA PM — V1.2 "Fluent" theme (Microsoft Teams-inspired)
   Tokens → shell (sidebar + command bar) → components → dark mode
   ============================================================ */

/* ---------- Tokens: light (default) ---------- */
:root {
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;

  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-2: #faf9f8;
  --surface-3: #f0f0f1;
  --hairline: #e1e1e3;
  --hairline-strong: #c8c8ca;
  --text: #1b1b1f;
  --text-2: #5f5f66;
  --text-3: #8a8a90;

  --red: #d10429;
  --red-hover: #b00322;
  --red-tint: rgba(209, 4, 41, .09);
  --red-tint-strong: rgba(209, 4, 41, .16);

  --elev-1: 0 1px 2px rgba(0,0,0,.05), 0 1px 3px rgba(0,0,0,.04);
  --elev-2: 0 2px 6px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --elev-3: 0 8px 24px rgba(0,0,0,.14);

  --radius: 8px;
  --radius-sm: 4px;

  --side-w: 236px;
  --side-w-collapsed: 56px;
  --cmdbar-h: 52px;

  --sb-bg: #fbfbfc;
  --sb-text: #424246;
  --sb-text-2: #8a8a90;
  --sb-hover: rgba(0,0,0,.05);
  --sb-active-bg: var(--red-tint);
  --sb-border: var(--hairline);

  --tint-success-bg: #e7f4e9;  --tint-success-fg: #107c41;
  --tint-warning-bg: #fff4e2;  --tint-warning-fg: #8a6116;
  --tint-danger-bg:  #fdeaea;  --tint-danger-fg:  #b00322;
  --tint-info-bg:    #e8f1f8;  --tint-info-fg:    #0f5480;
  --tint-neutral-bg: #ececed;  --tint-neutral-fg: #4a4a4f;
}

/* ---------- Tokens: dark theme ---------- */
[data-theme="dark"] {
  --bg: #1b1b1f;
  --surface: #242429;
  --surface-2: #2b2b31;
  --surface-3: #313136;
  --hairline: #3d3d43;
  --hairline-strong: #54545a;
  --text: #f3f3f4;
  --text-2: #b3b3b8;
  --text-3: #87878d;

  --red-tint: rgba(233, 61, 96, .16);
  --red-tint-strong: rgba(233, 61, 96, .26);

  --elev-1: 0 1px 3px rgba(0,0,0,.4);
  --elev-2: 0 2px 8px rgba(0,0,0,.45);
  --elev-3: 0 10px 30px rgba(0,0,0,.6);

  --tint-success-bg: #1d3a26;  --tint-success-fg: #6ccb87;
  --tint-warning-bg: #3d2f14;  --tint-warning-fg: #f2c66d;
  --tint-danger-bg:  #452028;  --tint-danger-fg:  #ff8ba0;
  --tint-info-bg:    #17303f;  --tint-info-fg:    #7fc3e8;
  --tint-neutral-bg: #333338;  --tint-neutral-fg: #c5c5ca;
}

/* ---------- Tokens: dark sidebar variant ---------- */
[data-side="dark"] {
  --sb-bg: #141416;
  --sb-text: #cfd0d4;
  --sb-text-2: #8a8a90;
  --sb-hover: rgba(255,255,255,.06);
  --sb-active-bg: var(--red-tint-strong);
  --sb-border: #26262a;
}

/* ---------- Base ---------- */
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: .925rem;
  transition: background .18s ease, color .18s ease;
}
h1, h2, h3, h4, h5, h6 { font-weight: 600; }
a { color: var(--red); }
a:hover { color: var(--red-hover); }

::selection { background: var(--red-tint-strong); }

/* Focus rings (Fluent) */
.form-control:focus, .form-select:focus, .form-check-input:focus,
.btn:focus-visible, .side-link:focus-visible, .form-check-input:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 1px;
  box-shadow: none;
}

/* ---------- Brand ---------- */
.brand-red { color:#fff; background: var(--red); padding: 2px 10px; border-radius: var(--radius-sm); letter-spacing:.5px; }
.btn-fama { background: var(--red); border: 1px solid var(--red); color:#fff; font-weight:600; }
.btn-fama:hover { background: var(--red-hover); border-color: var(--red-hover); color:#fff; }
.btn-fama:active { transform: translateY(1px); }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar-toggle-checkbox { display: none; }

.app-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 1045;
  background: var(--sb-bg);
  border-right: 1px solid var(--sb-border);
  color: var(--sb-text);
  display: flex; flex-direction: column;
  transition: width .18s ease, transform .22s ease, background .18s ease;
}

.side-brand {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 10px 12px 14px; min-height: 60px;
  border-bottom: 1px solid var(--sb-border);
  white-space: nowrap;
}
.brand-logo {
  font-weight: 700; letter-spacing: 1px; font-size: 1rem; color: #fff; display: inline-block;
  background: var(--red); padding: 3px 12px; border-radius: var(--radius-sm);
  flex: 0 0 auto;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 8px;
  object-fit: cover; background: #000;
  flex: 0 0 auto; display: inline-block;
}
.brand-tag { font-size: .58rem; letter-spacing: 2.2px; color: var(--sb-text-2); line-height: 1.3; flex: 1 1 auto; min-width: 0; overflow: hidden; }
.collapse-btn {
  flex: 0 0 auto;
  margin-left: auto; background: none; border: 0; color: var(--sb-text-2);
  cursor: pointer; font-size: .95rem; padding: 4px; border-radius: 4px;
}

.side-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 10px 8px; }
.side-nav::-webkit-scrollbar { width: 4px; }
.side-nav::-webkit-scrollbar-thumb { background: var(--hairline-strong); border-radius: 2px; }

.side-label {
  font-size: .62rem; text-transform: uppercase; letter-spacing: 1.6px;
  color: var(--sb-text-2); padding: 14px 12px 5px; white-space: nowrap;
}

.side-link {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  color: var(--sb-text); text-decoration: none; font-size: .9rem;
  padding: 8px 12px; border-radius: 6px; margin-bottom: 2px;
  white-space: nowrap;
  transition: background .12s ease, color .12s ease;
}
.side-link i { font-size: 1.05rem; width: 20px; text-align: center; flex: 0 0 auto; color: var(--sb-text-2); transition: color .12s; }
.side-link span { overflow: hidden; text-overflow: ellipsis; }
.side-link:hover { background: var(--sb-hover); color: var(--text); }
.side-link:hover i { color: var(--text); }

/* Teams-style active: red bar on the left + tinted bg */
.side-link.active { background: var(--sb-active-bg); color: var(--text); font-weight: 600; }
.side-link.active i { color: var(--red); }
.side-link.active::before {
  content: ''; position: absolute; left: 0; top: 6px; bottom: 6px;
  width: 3px; border-radius: 2px; background: var(--red);
}

.side-badge {
  background: var(--red); color: #fff; border-radius: 20px;
  font-size: .66rem; padding: 1px 7px; margin-left: auto; font-weight: 700;
}

.side-foot { border-top: 1px solid var(--sb-border); padding: 8px; }

/* Collapsed (icons-only): brand becomes a compact column — nothing overflows */
body.side-collapsed .app-sidebar { width: var(--side-w-collapsed); }
body.side-collapsed .side-brand {
  flex-direction: column; gap: 8px;
  padding: 12px 4px 10px;
}
body.side-collapsed .brand-mark { width: 32px; height: 32px; }
body.side-collapsed .brand-tag,
body.side-collapsed .side-label,
body.side-collapsed .side-link span,
body.side-collapsed .side-badge { display: none; }
body.side-collapsed .side-link { justify-content: center; padding: 9px 6px; }
body.side-collapsed .side-link.active::before { top: 3px; bottom: 3px; }
body.side-collapsed .collapse-btn { margin: 0 auto; }
body.side-collapsed .collapse-btn i { transform: rotate(180deg); }
body.side-collapsed .app-main { margin-left: var(--side-w-collapsed); }
body.side-collapsed .collapse-btn i { transform: rotate(180deg); }

.collapse-btn:hover { background: var(--sb-hover); color: var(--text); }
.collapse-btn i { transition: transform .18s ease; display: inline-block; }

/* Backdrop (mobile) */
.sidebar-backdrop { display: none; position: fixed; inset: 0; z-index: 1040; background: rgba(0,0,0,.4); }

/* ============================================================
   MAIN SHELL + COMMAND BAR
   ============================================================ */
.app-main { margin-left: var(--side-w); min-height: 100vh; display: flex; flex-direction: column; transition: margin-left .18s ease; }
.app-main .content-area { flex: 1; }

.cmdbar {
  position: sticky; top: 0; z-index: 1020;
  display: flex; align-items: center; gap: 14px;
  min-height: var(--cmdbar-h);
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}
.cmdbar-crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cmdbar-module { font-weight: 600; color: var(--text); white-space: nowrap; }
.cmdbar-sep { color: var(--text-3); }
.cmdbar-action { color: var(--text-2); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pill-search { margin-left: auto; }
.pill-search .input-group {
  width: 260px; transition: width .2s ease;
}
.pill-search .input-group:focus-within { width: 340px; }
.pill-search .form-control {
  border-radius: 20px; border-color: var(--hairline);
  background: var(--surface-2); font-size: .85rem; padding-left: 34px;
}
.pill-search .form-control:focus { background: var(--surface); }
.pill-search .search-ico {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); z-index: 5; font-size: .9rem; pointer-events: none;
}

.cmdbar-icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  color: var(--text-2); text-decoration: none; font-size: 1.05rem;
  background: none; border: 0; cursor: pointer;
  transition: background .12s;
}
.cmdbar-icon-btn:hover { background: var(--surface-3); color: var(--text); }
.cmdbar-icon-btn .bell-badge {
  position: absolute; top: 2px; right: 2px; font-size: .58rem; padding: 1px 5px;
}

.avatar-chip {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--red); color: #fff; font-weight: 700; font-size: .8rem;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; border: 0; letter-spacing: .5px;
}
[data-theme="dark"] .avatar-chip { border: 1px solid var(--hairline-strong); }

.avatar-menu { min-width: 240px; padding: 0; overflow: hidden; border-radius: var(--radius); box-shadow: var(--elev-3); }
.avatar-menu .am-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--hairline); }
.avatar-menu .am-name { font-weight: 600; color: var(--text); }
.avatar-menu .am-mail { font-size: .78rem; color: var(--text-2); word-break: break-all; }
.avatar-menu .am-roles { padding: 6px 16px; }
.avatar-menu .am-role-pill {
  display: inline-block; font-size: .7rem; margin: 2px 4px 2px 0;
  background: var(--tint-neutral-bg); color: var(--tint-neutral-fg);
  border-radius: 20px; padding: 2px 9px;
}
.avatar-menu .am-section { border-top: 1px solid var(--hairline); padding: 8px 8px; }
.avatar-menu .menu-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 7px 10px; border: 0; background: none;
  color: var(--text); font-size: .86rem; border-radius: 6px; cursor: pointer; text-align: left;
}
.avatar-menu .menu-row:hover { background: var(--surface-3); }
.avatar-menu .menu-row i { width: 20px; color: var(--text-2); }

/* Mobile top bar */
.mobile-topbar { display: none; }
.burger { color: var(--text); font-size: 1.5rem; cursor: pointer; line-height: 1; background:none; border:0; }
.mobile-bell { color: var(--text); font-size: 1.15rem; position: relative; }
.bell-badge { position: absolute; top: -6px; right: -10px; font-size: .6rem; }

/* ---------- Content ---------- */
.content-area { padding-top: 20px; }
.page-h1 { font-size: 1.35rem; margin-bottom: .35rem; }
.page-sub { color: var(--text-2); font-size: .85rem; }

/* ---------- Cards & panels ---------- */
.card {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--elev-1);
  background: var(--surface);
  color: var(--text);
}
.card:hover { box-shadow: var(--elev-1); }
.card-header {
  background: var(--surface); border-bottom: 1px solid var(--hairline);
  font-weight: 600; border-radius: var(--radius) var(--radius) 0 0 !important;
}
.card-body { color: var(--text); }

.h6, h2.h6 { text-transform: none; letter-spacing: .2px; color: var(--text-2); font-weight: 600; font-size: .78rem; }

/* ---------- Buttons ---------- */
.btn {
  border-radius: var(--radius-sm); font-weight: 600; font-size: .875rem;
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease, transform .05s ease;
}
.btn:active { transform: translateY(1px); }

.btn-outline-dark, .btn-dark {
  --bs-btn-color: var(--text);
  background: var(--surface); border: 1px solid var(--hairline-strong); color: var(--text);
}
.btn-outline-dark:hover, .btn-dark:hover {
  background: var(--surface-3); border-color: var(--hairline-strong); color: var(--text);
}
.btn-outline-dark:focus-visible, .btn-dark:focus-visible { background: var(--surface); color: var(--text); }
.btn-dark { background: var(--surface-3); }
[data-theme="dark"] .btn-dark:hover { background: var(--surface-3); }

.btn-outline-secondary { border-color: var(--hairline-strong); color: var(--text-2); }
.btn-outline-secondary:hover { background: var(--surface-3); color: var(--text); border-color: var(--hairline-strong); }

.btn-outline-danger { border-color: var(--hairline-strong); color: var(--tint-danger-fg); }
.btn-outline-danger:hover { background: var(--tint-danger-bg); border-color: var(--tint-danger-fg); color: var(--tint-danger-fg); }
.btn-outline-success { border-color: var(--hairline-strong); color: var(--tint-success-fg); }
.btn-outline-success:hover { background: var(--tint-success-bg); border-color: var(--tint-success-fg); color: var(--tint-success-fg); }

/* ---------- Tables (Fluent data lists) ---------- */
.table { color: var(--text); --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .62rem .75rem; border-color: var(--hairline); }
.table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2);
  color: var(--text-2); font-size: .74rem; text-transform: uppercase; letter-spacing: .6px;
  font-weight: 600; border-bottom: 1px solid var(--hairline) !important; white-space: nowrap;
}
.table tbody tr { transition: background .1s ease; }
.table tbody tr:hover { background: var(--surface-2); }
.table-light { background: var(--surface-2); color: var(--text); }
.table-responsive { border-radius: var(--radius); }

/* ---------- Forms ---------- */
.form-control, .form-select {
  border-color: var(--hairline-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
.form-control::placeholder { color: var(--text-3); }
.form-control:focus, .form-select:focus {
  border-color: var(--red); box-shadow: 0 1px 0 var(--red);
  background: var(--surface); color: var(--text);
}
.form-label { font-weight: 600; font-size: .82rem; color: var(--text); margin-bottom: .3rem; }
.form-text { color: var(--text-3); }
.form-check-input:checked { background-color: var(--red); border-color: var(--red); }
.form-check-input:checked[type="radio"] { background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3ccircle r='2.5' fill='%23fff'/%3e%3c/svg%3e"); }
.form-switch .form-check-input:focus:not(:checked) { --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3ccircle r='3' fill='rgba%280,0,0,.25%29'/%3e%3c/svg%3e"); }
.input-group-text { background: var(--surface-2); border-color: var(--hairline-strong); color: var(--text-2); }

/* ---------- Badges → soft tinted pills ---------- */
.badge { border-radius: 20px; font-weight: 600; padding: .35em .7em; letter-spacing: .2px; }
.badge.bg-danger  { background: var(--tint-danger-bg)  !important; color: var(--tint-danger-fg)  !important; }
.badge.bg-success { background: var(--tint-success-bg) !important; color: var(--tint-success-fg) !important; }
.badge.bg-warning { background: var(--tint-warning-bg) !important; color: var(--tint-warning-fg) !important; }
.badge.bg-info    { background: var(--tint-info-bg)    !important; color: var(--tint-info-fg)    !important; }
.badge.bg-secondary { background: var(--tint-neutral-bg) !important; color: var(--tint-neutral-fg) !important; }
.badge.bg-dark    { background: var(--tint-neutral-bg) !important; color: var(--tint-neutral-fg) !important; }
.badge.bg-light, .badge.bg-light.text-dark { background: var(--surface-3) !important; color: var(--text-2) !important; border: 1px solid var(--hairline); }

/* ---------- Tabs (underline) ---------- */
.nav-tabs { border-bottom: 1px solid var(--hairline); gap: 2px; }
.nav-tabs .nav-link {
  border: 0; border-bottom: 2px solid transparent;
  color: var(--text-2); font-weight: 600; font-size: .86rem;
  padding: .55rem .9rem; border-radius: 6px 6px 0 0; margin-bottom: -1px;
  transition: color .12s, background .12s;
}
.nav-tabs .nav-link:hover { color: var(--text); background: var(--surface-3); }
.nav-tabs .nav-link.active {
  background: none; color: var(--red); border-bottom: 2px solid var(--red);
  border-top: 0; border-left: 0; border-right: 0; font-weight: 600;
}

/* ---------- Alerts ---------- */
.alert { border: 1px solid transparent; border-radius: var(--radius); font-size: .875rem; }
.alert-success { background: var(--tint-success-bg); color: var(--tint-success-fg); border-color: transparent; }
.alert-danger  { background: var(--tint-danger-bg);  color: var(--tint-danger-fg);  border-color: transparent; }
.alert-warning { background: var(--tint-warning-bg); color: var(--tint-warning-fg); border-color: transparent; }
.alert-info    { background: var(--tint-info-bg);    color: var(--tint-info-fg);    border-color: transparent; }
.alert .btn-close { filter: none; }
[data-theme="dark"] .alert .btn-close { filter: invert(1) grayscale(1); }

/* ---------- Dropdowns ---------- */
.dropdown-menu {
  border: 1px solid var(--hairline); border-radius: var(--radius);
  box-shadow: var(--elev-2); background: var(--surface); color: var(--text);
  padding: 6px;
}
.dropdown-item { border-radius: 6px; color: var(--text); font-size: .875rem; padding: .45rem .75rem; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--surface-3); color: var(--text); }
.dropdown-item-text { color: var(--text-2); }
.dropdown-divider { border-color: var(--hairline); }

/* ---------- Pagination ---------- */
.page-link { border-color: var(--hairline); color: var(--text); background: var(--surface); border-radius: var(--radius-sm) !important; margin: 0 2px; }
.page-item.active .page-link { background: var(--red); border-color: var(--red); color: #fff; }
.page-link:hover { background: var(--surface-3); color: var(--text); }

/* ---------- Modal ---------- */
.modal-content { border: 1px solid var(--hairline); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--elev-3); }
.modal-header, .modal-footer { border-color: var(--hairline); }

/* ---------- Progress ---------- */
.progress { background: var(--surface-3); border-radius: 20px; }
.progress-bar { background: var(--red); }

/* ---------- Kanban (responsive grid — wraps to the user's screen) ---------- */
.kanban-scroll {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(252px, 1fr));
  gap: 14px;
  align-items: start;
}
.kanban-col { min-width: 0; }
.kanban-col .card-header {
  background: var(--surface-2); color: var(--text-2);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .8px; font-weight: 600;
  border-bottom: 1px solid var(--hairline);
}
.kanban-card { cursor: pointer; transition: transform .06s ease, box-shadow .12s ease; border: 1px solid var(--hairline) !important; }
.kanban-card:hover { transform: translateY(-2px); box-shadow: var(--elev-2); }

/* ---------- Timeline ---------- */
.timeline { list-style: none; padding-left: 0; }
.timeline li { position: relative; padding-left: 26px; margin-bottom: 14px; }
.timeline li::before { content:''; position:absolute; left:7px; top:4px; width:10px; height:10px; border-radius:50%; background: var(--red); box-shadow: 0 0 0 3px var(--red-tint); }
.timeline li::after { content:''; position:absolute; left:11px; top:18px; bottom:-14px; width:2px; background: var(--hairline); }
.timeline li:last-child::after { display:none; }

/* ---------- Login ---------- */
body:not(.app-authed) { background: linear-gradient(160deg, var(--bg) 60%, var(--red-tint) 100%); }

/* ---------- Tables inside cards: rounded clipping ---------- */
.card .table-responsive { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }

/* ---------- Misc ---------- */
.table-sm td, .table-sm th { vertical-align: middle; }
.border-top, .border-bottom { border-color: var(--hairline) !important; }
.text-muted { color: var(--text-2) !important; }
footer { color: var(--text-3); border-top: 1px solid var(--hairline); background: var(--surface); }
.gantt .bar-done .bar { fill: #198754 !important; }
.gantt .bar-blocked .bar { fill: var(--red) !important; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); width: var(--side-w) !important; box-shadow: var(--elev-3); }
  .sidebar-toggle-checkbox:checked ~ .app-sidebar { transform: translateX(0); }
  .sidebar-toggle-checkbox:checked ~ .sidebar-backdrop { display: block; }
  body.side-collapsed .app-main { margin-left: 0; }
  .app-main { margin-left: 0 !important; }

  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    position: sticky; top: 0; z-index: 1030;
    background: var(--surface); border-bottom: 1px solid var(--hairline);
    padding: 9px 14px; color: var(--text);
  }
  .mobile-brand .brand-logo { font-size: .9rem; }
  .mobile-actions { display: flex; align-items: center; gap: 6px; }

  .pill-search .input-group { width: 100%; }
  .cmdbar { padding: 0 14px; }
  .cmdbar-action { display: none; }
}

@media (min-width: 992px) {
  .mobile-topbar { display: none !important; }
}
