/* ============================================================
   PGSS app styles — theme tokens live in tailwind.config (layout_top.php)
   Sidebar widths are the only numbers you should need to touch.
   ============================================================ */
:root {
  --sb-w: 4.5rem;        /* collapsed: icons only */
  --sb-w-open: 16rem;    /* expanded: icons + names */
  --tb-h: 3.75rem;
}
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: var(--sb-w);
  background: linear-gradient(180deg, #14213D 0%, #0D162B 100%);
  color: #fff; display: flex; flex-direction: column;
  transition: width .22s ease, transform .22s ease;
  overflow: hidden;
}
.sidebar.is-open { width: var(--sb-w-open); }
.main { margin-left: var(--sb-w); min-height: 100vh; transition: margin-left .22s ease; display: flex; flex-direction: column; }
body.sb-open .main { margin-left: var(--sb-w-open); }

/* crest = toggle button */
.crest { display: flex; align-items: center; gap: .75rem; padding: .875rem; height: var(--tb-h); width: 100%; text-align: left; position: relative; }
.crest:hover .crest-shield { transform: translateY(-1px); box-shadow: 0 0 0 3px rgba(201,162,39,.35); }
.crest-shield {
  flex: 0 0 2.75rem; width: 2.75rem; height: 2.75rem; border-radius: .75rem;
  background: #C9A227; color: #14213D; display: grid; place-items: center; overflow: hidden;
  transition: transform .15s, box-shadow .15s; font-family: Sora, sans-serif; font-weight: 700; letter-spacing: -.02em;
}
.crest-shield img { width: 100%; height: 100%; object-fit: cover; }
.crest-shield img + .crest-mono { display: none; }
.crest-text { display: flex; flex-direction: column; line-height: 1.1; white-space: nowrap; opacity: 0; transform: translateX(-6px); transition: opacity .15s, transform .2s; }
.crest-name { font-family: Sora, sans-serif; font-weight: 600; font-size: .9rem; }
.crest-sub { font-size: .7rem; color: rgba(255,255,255,.6); letter-spacing: .06em; text-transform: uppercase; }
.crest-chev { margin-left: auto; font-size: .7rem; color: rgba(255,255,255,.45); opacity: 0; transition: opacity .15s, transform .22s; }
.sidebar.is-open .crest-text, .sidebar.is-open .crest-chev { opacity: 1; transform: none; }
.sidebar:not(.is-open) .crest-chev { transform: rotate(180deg); }

.sb-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: .5rem .625rem; scrollbar-width: none; }
.sb-nav::-webkit-scrollbar { display: none; }
.sb-foot { padding: .625rem; border-top: 1px solid rgba(255,255,255,.08); }

.sb-item {
  display: flex; align-items: center; gap: .875rem; height: 2.75rem; padding: 0 .75rem;
  border-radius: .625rem; color: rgba(255,255,255,.72); white-space: nowrap; position: relative;
  transition: background .12s, color .12s;
}
.sb-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.sb-item.is-active { background: rgba(255,255,255,.10); color: #fff; }
.sb-item.is-active::before { content: ''; position: absolute; left: -.625rem; top: .5rem; bottom: .5rem; width: 3px; border-radius: 0 3px 3px 0; background: #C9A227; }
.sb-item.is-soon { opacity: .45; cursor: default; }
.sb-ico { width: 1.25rem; text-align: center; font-size: 1rem; flex: 0 0 auto; }
.sb-label { font-size: .9rem; font-weight: 500; opacity: 0; transition: opacity .15s; }
.sb-caret, .sb-badge { margin-left: auto; opacity: 0; transition: opacity .15s, transform .2s; }
.sb-caret { font-size: .65rem; }
.sb-badge { font-size: .6rem; letter-spacing: .08em; text-transform: uppercase; background: rgba(255,255,255,.12); padding: .15rem .4rem; border-radius: 999px; }
.sidebar.is-open .sb-label, .sidebar.is-open .sb-caret, .sidebar.is-open .sb-badge { opacity: 1; }
.sb-children { padding: .125rem 0 .375rem 2.6rem; display: flex; flex-direction: column; gap: .125rem; }
.sb-child { font-size: .84rem; color: rgba(255,255,255,.6); padding: .35rem .5rem; border-radius: .4rem; white-space: nowrap; }
.sb-child:hover { color: #fff; background: rgba(255,255,255,.06); }
.sb-child.is-current { color: #C9A227; }

/* tooltip when collapsed (desktop only) */
@media (min-width: 768px) {
  .sidebar:not(.is-open) .sb-item::after {
    content: attr(data-label); position: absolute; left: calc(100% + .75rem); top: 50%; transform: translateY(-50%) translateX(-4px);
    background: #0D162B; color: #fff; font-size: .78rem; padding: .35rem .6rem; border-radius: .4rem; white-space: nowrap;
    opacity: 0; pointer-events: none; transition: opacity .12s, transform .12s; box-shadow: 0 4px 12px rgba(0,0,0,.25);
  }
  .sidebar:not(.is-open) .sb-item:hover::after { opacity: 1; transform: translateY(-50%); }
  .sidebar:not(.is-open) .sb-item.is-soon::after { content: attr(data-label) ' — coming soon'; }
}

/* ---------- Mobile: sidebar becomes a drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(13,22,43,.55); z-index: 39; backdrop-filter: blur(2px); }
@media (max-width: 767px) {
  .sidebar { width: var(--sb-w-open); transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .sidebar.is-drawer { transform: none; }
  .sidebar .crest-text, .sidebar .sb-label, .sidebar .sb-caret, .sidebar .sb-badge { opacity: 1; transform: none; }
  .sidebar .crest-chev { display: none; }
  .main, body.sb-open .main { margin-left: 0; }
  .content { padding-bottom: 5.5rem; }
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--tb-h);
  display: flex; align-items: center; gap: .75rem; padding: 0 1rem;
  background: rgba(246,247,249,.85); backdrop-filter: blur(10px); border-bottom: 1px solid #E3E6EB;
}
@media (min-width: 640px) { .topbar { padding: 0 1.5rem; } }
.tb-burger { display: none; width: 2.5rem; height: 2.5rem; border-radius: .625rem; color: #14213D; }
.tb-burger:hover { background: #E3E6EB; }
@media (max-width: 767px) { .tb-burger { display: inline-grid; place-items: center; } }
.tb-eyebrow { font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: #9A7B1A; font-weight: 600; }
.tb-title { font-family: Sora, sans-serif; font-weight: 600; font-size: 1.05rem; line-height: 1.2; color: #14213D; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 2.25rem; height: 2.25rem; border-radius: 999px; background: #14213D; color: #C9A227; display: grid; place-items: center; font-family: Sora, sans-serif; font-weight: 600; font-size: .8rem; }

.content { padding: 1rem; flex: 1; }
@media (min-width: 640px) { .content { padding: 1.5rem; } }

/* ---------- Bottom nav (mobile) ---------- */
.bottomnav { display: none; }
@media (max-width: 767px) {
  .bottomnav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 35; height: calc(3.75rem + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    display: grid; grid-template-columns: repeat(4, 1fr); background: #fff; border-top: 1px solid #E3E6EB;
  }
  .bottomnav a, .bottomnav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .2rem; font-size: .68rem; color: #6B7280; }
  .bottomnav i { font-size: 1.15rem; }
  .bottomnav .is-active { color: #14213D; }
  .bottomnav .is-active i { color: #C9A227; }
}

/* ---------- Components ---------- */
.card { background: #fff; border: 1px solid #E3E6EB; border-radius: 1rem; box-shadow: 0 1px 2px rgba(20,33,61,.06), 0 4px 16px -8px rgba(20,33,61,.12); }
.card-h { display: flex; align-items: center; gap: .75rem; padding: .875rem 1.125rem; border-bottom: 1px solid #E3E6EB; }
.card-h h2 { font-family: Sora, sans-serif; font-weight: 600; font-size: .95rem; color: #14213D; }
.card-b { padding: 1.125rem; }

.chip { display: inline-flex; align-items: center; gap: .4rem; font-size: .75rem; font-weight: 600; padding: .3rem .7rem; border-radius: 999px; white-space: nowrap; }
.chip-brass { background: #FBF4DC; color: #9A7B1A; }
.chip-leaf  { background: #E4F3EC; color: #1E7F5C; }
.chip-rose  { background: #FBE9E7; color: #B3261E; }
.chip-sky   { background: #E6EEF8; color: #2C6BB3; }
.chip-gray  { background: #EEF0F3; color: #4B5563; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; font-weight: 600; font-size: .875rem; padding: .6rem 1rem; border-radius: .7rem; transition: background .12s, transform .08s, box-shadow .12s; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: #14213D; color: #fff; } .btn-primary:hover { background: #1E2F55; }
.btn-brass { background: #C9A227; color: #14213D; } .btn-brass:hover { background: #d9b23a; }
.btn-ghost { background: transparent; color: #14213D; border: 1px solid #E3E6EB; } .btn-ghost:hover { background: #fff; border-color: #c9ced6; }
.btn-danger { background: #FBE9E7; color: #B3261E; } .btn-danger:hover { background: #f5d4d0; }
.btn-sm { padding: .4rem .7rem; font-size: .8rem; border-radius: .55rem; }
.btn-icon { width: 2.25rem; height: 2.25rem; padding: 0; }

.label { display: block; font-size: .78rem; font-weight: 600; color: #4B5563; margin-bottom: .3rem; }
.input, .select, .textarea {
  width: 100%; background: #fff; border: 1px solid #D5DAE1; border-radius: .7rem; padding: .6rem .8rem; font-size: .9rem; color: #1F2933;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: #14213D; box-shadow: 0 0 0 3px rgba(20,33,61,.12); }
.input.mono { font-family: "JetBrains Mono", monospace; }
.help { font-size: .75rem; color: #6B7280; margin-top: .3rem; }
.field-err { font-size: .75rem; color: #B3261E; margin-top: .3rem; }

.table { width: 100%; font-size: .875rem; }
.table th { text-align: left; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: #6B7280; font-weight: 600; padding: .6rem .875rem; background: #F6F7F9; border-bottom: 1px solid #E3E6EB; }
.table td { padding: .7rem .875rem; border-bottom: 1px solid #EEF0F3; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #FBFBFC; }
.table .num { font-family: "JetBrains Mono", monospace; font-variant-numeric: tabular-nums; text-align: right; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.kpi { padding: 1.125rem; }
.kpi-label { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: #6B7280; font-weight: 600; }
.kpi-value { font-family: "JetBrains Mono", monospace; font-weight: 600; font-size: 1.6rem; color: #14213D; margin-top: .25rem; line-height: 1.1; }
.kpi-sub { font-size: .78rem; color: #6B7280; margin-top: .35rem; }
.kpi-ico { width: 2.5rem; height: 2.5rem; border-radius: .75rem; display: grid; place-items: center; font-size: 1.05rem; }

.flash { display: flex; align-items: center; gap: .6rem; padding: .7rem .9rem; border-radius: .7rem; font-size: .875rem; }
.flash-success { background: #E4F3EC; color: #1E7F5C; }
.flash-error   { background: #FBE9E7; color: #B3261E; }
.flash-info    { background: #E6EEF8; color: #2C6BB3; }

.empty { text-align: center; padding: 2.5rem 1rem; color: #6B7280; }
.empty i { font-size: 1.75rem; color: #C9A227; margin-bottom: .6rem; }
.empty h3 { font-family: Sora, sans-serif; color: #14213D; font-weight: 600; }

.gr { font-family: "JetBrains Mono", monospace; font-weight: 600; color: #9A7B1A; font-size: .85rem; }
[x-cloak] { display: none !important; }
