/* ==========================================================================
   MKH - Roles and the permission editor
   Visual language from the Claude Design project.
   Requires tokens.css, base.css, components.css and layout.css.
   Shared by roles.html (the list) and role-edit.html (the editor).
   ========================================================================== */

/* --------------------------------------------------------------------------
   Roles toolbar
   -------------------------------------------------------------------------- */

.roles-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
}
.roles-bar .toolbar { padding: 0; border-bottom: 0; flex: 1; }

/* --------------------------------------------------------------------------
   Role cards
   -------------------------------------------------------------------------- */

.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 288px), 1fr));
  gap: clamp(12px, 1.4vw, 18px);
}

.role-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  transition: transform var(--dur-base) var(--ease),
              box-shadow var(--dur-base) var(--ease),
              border-color var(--dur-base) var(--ease);
}
.role-card:hover { transform: translateY(-3px); box-shadow: var(--sh-md); border-color: var(--line-strong); }
.role-card[hidden] { display: none; }

/* A 2px accent across the top, tinted per role type. */
.role-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: var(--grad-arrow);
}
.role-card[data-type="system"]::before { background: var(--grad-badge); }

.role-card__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }

.role-card__icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary-soft-fg);
}
.role-card__icon svg { width: 20px; height: 20px; }
.role-card__icon--system { background: var(--accent-soft); color: var(--accent-soft-fg); }

.role-card__head { display: flex; flex-direction: column; gap: 6px; }
.role-card__name {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  letter-spacing: -0.015em;
}
.role-card__desc { font-size: var(--fs-sm); line-height: 1.55; color: var(--txt-2); }

/* ---- Permission meter ----------------------------------------------------
   A count alone ("45 / 82") is hard to compare across cards at a glance; the
   bar makes the spread between a read-only role and an admin one obvious.
   -------------------------------------------------------------------------- */

.role-meter { display: flex; flex-direction: column; gap: 7px; margin-top: auto; }
.role-meter__head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.role-meter__label {
  font-size: 10.5px;
  font-weight: var(--fw-bold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--txt-3);
}
.role-meter__value { font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--txt-2); }

.role-meter__track {
  height: 5px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
}
.role-meter__fill { height: 100%; border-radius: var(--r-full); background: var(--accent-fill); }
.role-card[data-type="system"] .role-meter__fill { background: var(--primary-fill); }

.role-card__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}
.role-card__users { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--txt-3); }
.role-card__users svg { width: 14px; height: 14px; }

/* "New role" tile - a dashed affordance rather than a filled card. */
.role-card--new {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  min-height: 200px;
  padding: 22px 18px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  color: var(--txt-3);
  transition: border-color var(--dur-base) var(--ease),
              transform var(--dur-base) var(--ease),
              background-color var(--dur-base) var(--ease);
}
.role-card--new::before { content: none; }
.role-card--new:hover {
  border-color: var(--primary);
  transform: translateY(-3px);
  background: var(--surface);
  text-decoration: none;
}
.role-card--new .role-card__name { font-size: var(--fs-lg); color: var(--txt); }
.role-card--new .role-card__desc { max-width: 30ch; color: var(--txt-3); }
.role-card__icon--new { background: var(--primary-soft); color: var(--primary); }

.role-empty { padding: 40px 20px; text-align: center; color: var(--txt-3); font-size: var(--fs-base); }
.role-empty[hidden] { display: none; }

/* --------------------------------------------------------------------------
   Role editor - details
   -------------------------------------------------------------------------- */

.role-details__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.role-details__grid .field { margin-bottom: 0; }

/* --------------------------------------------------------------------------
   Permission editor

   Grouped list, not a module x action grid. Modules do not share one action
   vocabulary - "Reconcile GSTR-2B" exists only under GST filing - so a grid
   would be mostly empty cells and would grow a column every time one module
   gained an action. Rows also leave room for the description each permission
   needs: "Approve" on its own tells nobody what they are granting.
   -------------------------------------------------------------------------- */

.perm__summary { margin-top: 4px; font-size: var(--fs-sm); color: var(--txt-3); }
.perm__summary strong { font-family: var(--font-mono); font-size: var(--fs-md); color: var(--accent-soft-fg); }

.perm__master { white-space: nowrap; font-size: var(--fs-sm); font-weight: var(--fw-semibold); }

.perm-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 13px 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-soft);
}
.perm-toolbar .toolbar__search { min-width: 200px; }
.perm-toolbar .input { background: var(--surface); }

.perm-layout { display: grid; grid-template-columns: 216px minmax(0, 1fr); align-items: start; }

/* ---- Module index -------------------------------------------------------- */

.modindex {
  position: sticky;
  top: 78px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 14px 12px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  border-right: 1px solid var(--line-soft);
}
.modindex__label {
  padding: 4px 10px 8px;
  font-size: 9.5px;
  font-weight: var(--fw-bold);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--txt-3);
}
.modindex__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--r-xs);
  font-size: var(--fs-sm);
  color: var(--txt-2);
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.modindex__item:hover { background: var(--surface-2); color: var(--txt); text-decoration: none; }
.modindex__item[hidden] { display: none; }
.modindex__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modindex__count { flex: none; font-family: var(--font-mono); font-size: 11px; color: var(--txt-3); }
.modindex__count strong { color: var(--txt-2); }
.modindex__item.is-full .modindex__count strong { color: var(--accent-soft-fg); }
.modindex__item.is-empty .modindex__count strong { color: var(--txt-3); }

/* ---- Module section ------------------------------------------------------ */

.permsets { min-width: 0; display: flex; flex-direction: column; }

.permset { border-bottom: 1px solid var(--line-soft); scroll-margin-top: 80px; }
.permset[hidden] { display: none; }

.permset__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  background: var(--surface-2);
}

.permset__title { margin: 0; flex: 1; min-width: 0; font-size: inherit; font-weight: inherit; letter-spacing: normal; }

/* Vertical padding lives on the children, not the header: the disclosure
   button is only as tall as its text, and pushing the padding into it makes
   the whole strip a real target without changing how the row looks. */
.permset__toggle,
.permset__all,
.permset__count { padding-block: 12px; }

.permset__toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: var(--fw-bold);
  letter-spacing: -0.01em;
  color: var(--txt);
  text-align: left;
}
.permset__chevron {
  width: 15px;
  height: 15px;
  flex: none;
  color: var(--txt-3);
  transition: transform 0.18s var(--ease);
}
.permset.is-collapsed .permset__chevron { transform: rotate(-90deg); }
.permset__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.permset__count { flex: none; font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--txt-3); white-space: nowrap; }
.permset__count strong { color: var(--txt-2); }

.permset__all {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--txt-2);
  cursor: pointer;
  user-select: none;
}

/* Permissions flow into columns when there is room - a 14-module list one
   row at a time is a very long page. */
.permset__body { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.permset__body[hidden] { display: none; }

/* ---- Permission row ------------------------------------------------------ */

.perm-row {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 18px;
  border-top: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}
.perm-row:hover { background: var(--surface-2); }
.perm-row[hidden] { display: none; }
.perm-row .check { width: 16px; height: 16px; margin-top: 2px; }

.perm-row__text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.perm-row__name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--txt);
}
.perm-row__desc { font-size: var(--fs-sm); line-height: 1.5; color: var(--txt-3); }

/* Marks permissions that destroy data, move money or change who has access.
   Amber, not red: a prompt to look twice, not an error. */
.perm-row__flag {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 7px;
  border: 1px solid var(--amber-300);
  border-radius: var(--r-full);
  background: var(--warn-bg);
  color: var(--warn-fg);
  font-size: 9.5px;
  font-weight: var(--fw-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.perm__none { padding: 40px 20px; text-align: center; color: var(--txt-3); font-size: var(--fs-base); }
.perm__none[hidden] { display: none; }

.perm__foot { justify-content: space-between; flex-wrap: wrap; }
.perm__hint { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: var(--fs-sm); color: var(--txt-3); }

/* --------------------------------------------------------------------------
   Unsaved-changes bar
   -------------------------------------------------------------------------- */

.savebar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-savebar);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  max-width: calc(100vw - 32px);
  padding: 11px 12px 11px 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-full);
  background: var(--surface);
  box-shadow: var(--sh-lg);
  animation: mkh-rise 0.22s var(--ease);
}
.savebar[hidden] { display: none; }
.savebar__text { display: inline-flex; align-items: center; gap: 9px; font-size: var(--fs-md); color: var(--txt-2); }
.savebar__dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: var(--r-full);
  background: var(--warn);
  box-shadow: 0 0 0 3px var(--warn-bg);
}
.savebar__actions { display: flex; align-items: center; gap: var(--sp-2); }
.savebar .btn { border-radius: var(--r-full); }

/* --------------------------------------------------------------------------
   Narrowing
   -------------------------------------------------------------------------- */

/* The index is a convenience, not content - it is the first thing to go. */
@container content (max-width: 840px) {
  .perm-layout { grid-template-columns: minmax(0, 1fr); }
  .modindex { display: none; }
}

@container content (max-width: 560px) {
  .role-grid { grid-template-columns: minmax(0, 1fr); }
  .permset__head { flex-wrap: wrap; padding: 0 14px; }
  .permset__title { flex: 1 0 100%; }
  .permset__toggle { padding-bottom: 4px; }
  .permset__count { padding-top: 0; }
  .permset__all { padding-top: 0; margin-left: auto; }
  .perm-row { padding: 12px 14px; }
  .savebar { position: sticky; bottom: 12px; left: auto; transform: none; margin-top: var(--sp-4); }
}

@supports not (container-type: inline-size) {
  @media (max-width: 1100px) {
    .perm-layout { grid-template-columns: minmax(0, 1fr); }
    .modindex { display: none; }
  }
  @media (max-width: 820px) { .role-grid { grid-template-columns: minmax(0, 1fr); } }
}
