/* =====================================================================
   App shell — user dashboard and admin panel.
   ===================================================================== */

.shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
.scrim { display: none; }

/* ---------- sidebar ---------- */
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line); z-index: 40; transition: transform .3s var(--ease), background-color .25s; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 14px; }
.sidebar-head .brand { font-size: 1.1rem; }
.sidebar-head .brand-mark { width: 34px; height: 34px; }
.sidebar-close { display: none; }
.area-switch { margin: 4px 14px 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-3); border-radius: 11px; }
.area-switch a { text-align: center; font-size: .76rem; font-weight: 600; padding: 7px 6px; border-radius: 8px; color: var(--muted); font-family: var(--font-d); transition: .2s; }
.area-switch a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.area-switch a:not(.on):hover { color: var(--ink); }
.nav-scroll { flex: 1; overflow-y: auto; padding: 6px 12px 16px; }
.nav-label { font-family: var(--font-m); font-size: .62rem; letter-spacing: .16em; text-transform: uppercase; color: var(--faint); padding: 16px 10px 8px; }
.nav-item { position: relative; display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 10px; color: var(--muted); font-size: .88rem; font-weight: 500; transition: background-color .15s, color .15s; }
.nav-item:hover { background: var(--surface-3); color: var(--ink); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item.active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }
.nav-item .count { margin-left: auto; font-family: var(--font-m); font-size: .66rem; padding: 1px 7px; border-radius: 999px; background: var(--surface-3); color: var(--muted); }
.nav-item.active .count { background: var(--surface); color: var(--brand); }
.sidebar-foot { padding: 14px; border-top: 1px solid var(--line); }
.upgrade-card { padding: 16px; border-radius: 14px; background: linear-gradient(135deg, var(--brand), var(--brand-deep)); color: #fff; position: relative; overflow: hidden; margin-bottom: 12px; }
.upgrade-card::after { content: ""; position: absolute; right: -30px; bottom: -40px; width: 120px; height: 120px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 50%, transparent); filter: blur(18px); }
.upgrade-card strong { font-family: var(--font-d); display: block; font-size: .92rem; position: relative; }
.upgrade-card p { font-size: .76rem; opacity: .85; margin: 3px 0 10px; position: relative; }
.upgrade-card a { position: relative; font-size: .76rem; font-weight: 600; font-family: var(--font-d); display: inline-flex; align-items: center; gap: 5px; background: rgba(255,255,255,.18); padding: 6px 10px; border-radius: 8px; }
.me { display: flex; align-items: center; gap: 11px; padding: 6px; border-radius: 12px; }
.me .who { min-width: 0; flex: 1; }
.me .who strong { display: block; font-size: .84rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .who span { display: block; font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- main ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px; padding: 12px 28px; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
.topbar .menu-btn { display: none; }
.top-search { flex: 1; max-width: 420px; }
.top-search .input { background: var(--surface-2); border-color: var(--line); padding-top: 9px; padding-bottom: 9px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.dropdown { position: relative; }
.dropdown-toggle { display: flex; align-items: center; gap: 10px; background: none; border: 1px solid transparent; padding: 4px 8px 4px 4px; border-radius: 12px; cursor: pointer; }
.dropdown-toggle:hover { background: var(--surface); border-color: var(--line); }
.dropdown-toggle .avatar { width: 32px; height: 32px; border-radius: 9px; }
.dropdown-toggle .nm { font-size: .84rem; font-weight: 600; color: var(--ink); }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px; padding: 8px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(-6px); pointer-events: none; transition: .18s var(--ease); z-index: 60; }
.dropdown.open .dropdown-menu { opacity: 1; transform: none; pointer-events: auto; }
.dropdown-menu .dm-head { padding: 10px 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.dropdown-menu .dm-head strong { display: block; font-size: .88rem; color: var(--ink); }
.dropdown-menu .dm-head span { font-size: .76rem; color: var(--muted); }
.dropdown-menu a, .dropdown-menu button { width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; font-size: .86rem; color: var(--text); background: none; border: 0; cursor: pointer; text-align: left; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-3); color: var(--ink); }
.dropdown-menu .danger { color: var(--danger); }
.dropdown-menu .icon { color: var(--faint); }

.content { padding: 28px; width: 100%; max-width: 1320px; margin: 0 auto; flex: 1; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.6rem; font-weight: 700; }
.page-head p { color: var(--muted); font-size: .92rem; margin-top: 4px; }
.page-head .crumb { font-family: var(--font-m); font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }
.page-head .crumb a:hover { color: var(--brand); }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { position: relative; padding: 18px 20px; overflow: hidden; }
.stat .s-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.stat .s-label { font-size: .8rem; color: var(--muted); font-weight: 500; }
.stat .s-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.stat.green .s-ico { background: var(--accent-soft); color: var(--accent); }
.stat.amber .s-ico { background: var(--warning-soft); color: var(--warning); }
.stat .s-value { font-family: var(--font-d); font-size: 1.9rem; font-weight: 700; color: var(--ink); line-height: 1; letter-spacing: -.02em; }
.stat .s-foot { margin-top: 10px; font-size: .76rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .s-foot b { color: var(--accent); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; margin-bottom: 18px; }
.grid-2.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 18px; }

/* bar chart */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 190px; padding-top: 10px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.bar .col { width: 100%; max-width: 30px; border-radius: 7px 7px 3px 3px; background: linear-gradient(180deg, var(--brand), color-mix(in srgb, var(--brand) 55%, var(--accent))); min-height: 4px; position: relative; transition: filter .2s; }
.bar .col.zero { background: var(--surface-3); }
.bar:hover .col { filter: brightness(1.12); }
.bar .col .tip { position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); font-family: var(--font-m); font-size: .66rem; background: var(--ink); color: var(--bg); padding: 3px 7px; border-radius: 6px; white-space: nowrap; opacity: 0; transition: .15s; pointer-events: none; }
.bar:hover .tip { opacity: 1; }
.bar .d { font-family: var(--font-m); font-size: .62rem; color: var(--faint); }

/* progress list */
.plist { display: flex; flex-direction: column; gap: 16px; }
.prow .pr-top { display: flex; justify-content: space-between; font-size: .84rem; margin-bottom: 7px; }
.prow .pr-top strong { color: var(--ink); font-weight: 600; }
.prow .pr-top span { font-family: var(--font-m); font-size: .74rem; color: var(--muted); }
.progress { height: 7px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand), var(--accent)); }

/* activity feed */
.feed { display: flex; flex-direction: column; }
.feed-item { display: flex; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.feed-item:last-child { border-bottom: 0; }
.feed-item .f-dot { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-3); color: var(--muted); flex: none; }
.feed-item .f-text { font-size: .84rem; color: var(--text); }
.feed-item .f-text strong { color: var(--ink); font-weight: 600; }
.feed-item .f-time { font-size: .72rem; color: var(--faint); margin-top: 2px; font-family: var(--font-m); }

/* toolbar / filters */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.toolbar .input-group { flex: 1; min-width: 200px; max-width: 340px; }
.toolbar .select { width: auto; min-width: 150px; }
.segmented { display: inline-flex; padding: 3px; gap: 3px; background: var(--surface-3); border-radius: 10px; }
.segmented a { padding: 6px 12px; font-size: .8rem; font-weight: 600; border-radius: 8px; color: var(--muted); }
.segmented a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* tool icon cell */
.t-ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.t-ico .icon { width: 19px; height: 19px; }
tr.is-hidden .t-ico { background: var(--surface-3); color: var(--faint); }
tr.is-hidden .t-title { color: var(--muted); }
.cat-row td { background: var(--surface-2); font-family: var(--font-m); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding-top: 10px; padding-bottom: 10px; }

/* icon picker */
.icon-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 8px; }
.icon-picker label { cursor: pointer; }
.icon-picker input { position: absolute; opacity: 0; }
.icon-picker span { height: 46px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 11px; color: var(--muted); background: var(--surface); transition: .15s; }
.icon-picker span:hover { border-color: var(--brand); color: var(--brand); }
.icon-picker input:checked + span { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.icon-picker input:focus-visible + span { box-shadow: 0 0 0 3px var(--brand-ring); }

/* radio cards (tool status) */
.radio-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.radio-cards label { cursor: pointer; }
.radio-cards input { position: absolute; opacity: 0; }
.radio-cards .rc { display: block; height: 100%; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); transition: .15s; }
.radio-cards .rc strong { display: block; font-size: .86rem; color: var(--ink); }
.radio-cards .rc span { font-size: .74rem; color: var(--muted); }
.radio-cards input:checked + .rc { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px var(--brand-ring); }

/* form layout: main + aside */
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.form-layout aside { position: sticky; top: 86px; display: flex; flex-direction: column; gap: 18px; }
.switch-list { display: flex; flex-direction: column; }
.switch-list .switch-row { border-radius: 0; border-width: 0 0 1px; background: transparent; padding: 14px 20px; }
.switch-list .switch-row:last-child { border-bottom: 0; }

/* settings */
.settings { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 22px; align-items: start; }
.settings-nav { position: sticky; top: 86px; padding: 8px; }
.settings-nav a { display: flex; gap: 12px; align-items: flex-start; padding: 11px 12px; border-radius: 11px; color: var(--muted); transition: .15s; }
.settings-nav a:hover { background: var(--surface-3); color: var(--ink); }
.settings-nav a.on { background: var(--brand-soft); color: var(--brand); }
.settings-nav a .icon { margin-top: 2px; }
.settings-nav strong { display: block; font-size: .87rem; color: inherit; font-weight: 600; }
.settings-nav span { display: block; font-size: .72rem; color: var(--faint); line-height: 1.35; margin-top: 1px; }
.settings-section { margin-bottom: 18px; }
.save-bar { position: sticky; bottom: 16px; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 14px 12px 20px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); }
.save-bar span { font-size: .84rem; color: var(--muted); }
.save-bar.dirty span { color: var(--warning); font-weight: 500; }

/* permission matrix */
.perm-group { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.perm-group + .perm-group { margin-top: 12px; }
.perm-group .pg-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.perm-group .pg-head strong { font-size: .88rem; color: var(--ink); }
.perm-group .pg-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px; padding: 10px; }
.perm-group .pg-body label { padding: 8px 10px; border-radius: 9px; }
.perm-group .pg-body label:hover { background: var(--surface-3); }
.perm-group code { font-family: var(--font-m); font-size: .78rem; color: var(--text); }

.role-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.role-card { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.role-card .rc-top { display: flex; align-items: center; justify-content: space-between; }
.role-card .rc-ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.role-card h3 { font-size: 1.05rem; text-transform: capitalize; }
.role-card .rc-meta { display: flex; gap: 18px; font-size: .8rem; color: var(--muted); }
.role-card .rc-meta b { color: var(--ink); font-family: var(--font-d); }
.role-card .rc-foot { display: flex; gap: 8px; margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }

/* user dashboard */
.welcome { position: relative; overflow: hidden; padding: 28px 30px; border-radius: var(--r-xl); background: linear-gradient(120deg, var(--brand), var(--brand-deep)); color: #fff; margin-bottom: 22px; box-shadow: var(--shadow-lg); }
.welcome::after { content: ""; position: absolute; right: -40px; top: -80px; width: 300px; height: 300px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 40%, transparent); filter: blur(40px); }
.welcome > * { position: relative; z-index: 1; }
.welcome h1 { color: #fff; font-size: 1.7rem; margin-bottom: 6px; }
.welcome p { opacity: .85; max-width: 52ch; }
.welcome .w-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.welcome .btn-ghost { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.25); }
.welcome .btn-ghost:hover { background: rgba(255,255,255,.22); border-color: rgba(255,255,255,.4); }

.app-tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.app-tool { position: relative; display: flex; flex-direction: column; gap: 10px; padding: 18px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm); transition: .2s var(--ease); }
.app-tool:hover { transform: translateY(-3px); border-color: var(--brand); box-shadow: var(--shadow); }
.app-tool.locked .t-ico { background: var(--surface-3); color: var(--muted); }
.app-tool .at-top { display: flex; justify-content: space-between; align-items: flex-start; }
.app-tool h4 { font-size: .95rem; font-weight: 600; }
.app-tool p { font-size: .8rem; color: var(--muted); line-height: 1.45; }
.cat-title { display: flex; align-items: center; gap: 12px; margin: 28px 0 14px; }
.cat-title h3 { font-size: 1.05rem; }
.cat-title .rule { flex: 1; height: 1px; background: var(--line); }
.cat-title .n { font-family: var(--font-m); font-size: .7rem; color: var(--faint); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); }
.auth-side { position: relative; overflow: hidden; padding: 40px 48px; display: flex; flex-direction: column; justify-content: space-between; color: #fff;
  background: radial-gradient(circle at 85% 10%, color-mix(in srgb, var(--accent) 45%, transparent), transparent 45%), linear-gradient(145deg, var(--brand), var(--brand-deep) 70%); }
.auth-side .brand { color: #fff; }
.auth-side .brand-mark { background: rgba(255,255,255,.16); box-shadow: none; border: 1px solid rgba(255,255,255,.25); }
.auth-side .brand-text small { color: rgba(255,255,255,.7); }
.auth-side h2 { color: #fff; font-size: clamp(1.8rem, 3vw, 2.5rem); font-weight: 800; max-width: 16ch; margin-bottom: 14px; }
.auth-side p { opacity: .85; max-width: 42ch; }
.auth-points { display: flex; flex-direction: column; gap: 12px; margin-top: 28px; }
.auth-points span { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.auth-points .icon { width: 22px; height: 22px; padding: 4px; border-radius: 7px; background: rgba(255,255,255,.18); stroke-width: 2.6; }
.auth-side .foot { font-size: .78rem; opacity: .7; }
.auth-grid-bg { position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 44px 44px; mask-image: radial-gradient(circle at 30% 60%, #000, transparent 70%); pointer-events: none; }
.auth-side > * { position: relative; }
.auth-main { display: flex; flex-direction: column; padding: 28px clamp(20px, 5vw, 56px); }
.auth-top { display: flex; justify-content: space-between; align-items: center; }
.auth-top .back { display: inline-flex; align-items: center; gap: 7px; font-size: .86rem; color: var(--muted); }
.auth-top .back:hover { color: var(--brand); }
.auth-card { width: 100%; max-width: 420px; margin: auto; padding: 36px 0; }
.auth-card h1 { font-size: 1.85rem; font-weight: 700; margin-bottom: 8px; }
.auth-card .sub { color: var(--muted); margin-bottom: 28px; }
.auth-card form { display: flex; flex-direction: column; gap: 16px; }
.auth-row { display: flex; justify-content: space-between; align-items: center; font-size: .84rem; }
.auth-alt { text-align: center; font-size: .88rem; color: var(--muted); margin-top: 22px; }
.auth-alt a { color: var(--brand); font-weight: 600; }
.demo-creds { margin-top: 22px; padding: 14px 16px; border-radius: 12px; border: 1px dashed var(--line-strong); background: var(--surface-2); font-size: .8rem; color: var(--muted); }
.demo-creds code { font-family: var(--font-m); color: var(--ink); font-size: .78rem; }
.demo-creds button { background: none; border: 0; color: var(--brand); font-weight: 600; cursor: pointer; font-size: .78rem; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-layout { grid-template-columns: 1fr; }
  .form-layout aside { position: static; }
}
@media (max-width: 1024px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 280px; transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .sidebar-close { display: grid; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(8, 15, 30, .45); backdrop-filter: blur(2px); z-index: 35; opacity: 0; pointer-events: none; transition: opacity .3s; }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .topbar .menu-btn { display: grid; }
  .grid-2, .grid-2.even { grid-template-columns: 1fr; }
  .settings { grid-template-columns: 1fr; }
  .settings-nav { position: static; display: flex; overflow-x: auto; gap: 4px; }
  .settings-nav a { flex: none; }
  .settings-nav span { display: none; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
}
@media (max-width: 640px) {
  .content { padding: 18px 16px; }
  .topbar { padding: 10px 16px; }
  .top-search { display: none; }
  .dropdown-toggle .nm { display: none; }
  .stats { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat { padding: 14px; }
  .stat .s-value { font-size: 1.5rem; }
  .radio-cards { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 1.35rem; }
  .welcome { padding: 22px; }
}
