/*
 * AppHub — the platform menu, restyled from the Agrotop design proposal (repo ux-hub):
 * SAP Fiori-style grouping into tiles, in the Agrotop brand palette.
 *
 * Light mode is fixed on purpose: this is a corporate launchpad with a printed brand
 * manual behind it, not an app with a user theme preference.
 *
 * Assets are real files — this page's own under assets/, the shared palette and typeface
 * under brand/ — and every reference is RELATIVE: the page is served at the gateway root,
 * and a leading slash would break it behind any path prefix.
 */

/*
 * Palette, typeface and the light-theme vocabulary all come from the shared brand layer
 * (brand/README.md), which the parent pom copies into this module's static resources at build
 * time. theme-light.css imports tokens.css itself, so this one line brings both.
 *
 * It must be the FIRST rule in the file: @import is only valid before any other statement.
 */
@import url("brand/theme-light.css");

/* ============ TOKENS ============ */
/*
 * Only what is specific to THIS page. Every colour, radius and shadow now comes from the
 * shared light theme — the hub was where that vocabulary was designed (repo ux-hub), so it is
 * the reference implementation rather than a special case.
 */
:root {
  /* Layout, not theme: the hub's content column. Nothing brand-wide about 1180px. */
  --maxw: 1180px;
}

/* ============ BASE ============ */
* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--agrotop-font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-weight: 800; letter-spacing: -0.01em; text-wrap: balance; margin: 0; }
p { margin: 0; }
a { color: inherit; }
button { font-family: inherit; }
:focus-visible { outline: 2.5px solid var(--ring); outline-offset: 2px; border-radius: 6px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ============ TOP CONTROLS ============ */
/* The platform top bar now comes from the shared overlay (shell/app-bar.js), the same bar every
   app shows. What remains here are the hub-only controls that moved down into .page-head: the
   sidebar toggle and the tile search. */
.menu-toggle {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.menu-toggle svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}
/* Tile search + version line, relocated from the old shell into .page-head. The search filters
   the tile grid (distinct from the shared bar's dropdown search, which filters that menu). */
.page-search { flex: 1; max-width: 380px; position: relative; }
.page-search input {
  width: 100%;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 11px 16px 11px 40px;
  min-height: 44px;
  font-size: 14.5px;
  color: var(--ink);
  font-family: inherit;
}
.page-search input::placeholder { color: var(--ink-muted); }
.page-search svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  stroke: var(--ink-muted);
  pointer-events: none;
}

/* ============ PAGE / SIDEBAR ============ */
.page { max-width: var(--maxw); margin: 0 auto; padding: 30px 28px 64px; }
.page-head {
  margin-bottom: 22px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.page-head-main { flex: 1; min-width: 0; }
.page-head h1 { font-size: 30px; }
.page-head .sub { color: var(--ink-muted); font-size: 14px; margin-top: 6px; }
@media (max-width: 560px) {
  .page-head { flex-wrap: wrap; }
  /* Leave room beside the menu button for the title instead of letting the search steal it. */
  .page-head-main { flex: 1 1 calc(100% - 60px); }
  .page-head h1 { font-size: 24px; }
  .page-search { max-width: none; width: 100%; order: 3; }
}

.layout { display: flex; gap: 32px; align-items: flex-start; }
.sidebar {
  width: 228px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  /* Clears the shared top bar (shell/app-bar.js) so the filters do not slide under it. */
  top: calc(var(--aab-height, 64px) + 16px);
}
.main { flex: 1; min-width: 0; }

.filters-primary {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.filters { display: flex; flex-direction: column; gap: 4px; }
.chip {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-muted);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.chip[aria-pressed="true"] {
  background: var(--accent-text);
  color: var(--accent-ink);
  border-color: var(--accent-text);
}
.chip:hover:not([aria-pressed="true"]) {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-text);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 39;
}

@media (max-width: 860px) {
  .menu-toggle { display: flex; }
  .layout { flex-direction: column; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    max-width: 85vw;
    height: 100%;
    z-index: 40;
    background: var(--page);
    padding: 20px;
    overflow-y: auto;
    box-shadow: 0 10px 40px var(--shadow-lift);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; }
  .chip { border-color: var(--border); }
}

/* ============ SECTIONS ============ */
.section { margin-top: 34px; }
.section:first-child { margin-top: 0; }
.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.section-head .icon {
  width: 18px;
  height: 18px;
  stroke: var(--ink-muted);
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.section-head h2 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  font-weight: 700;
}
.section-head .count {
  font-size: 12px;
  color: var(--ink-muted);
  font-weight: 700;
  background: var(--surface-sunken);
  border-radius: 999px;
  padding: 1px 9px;
}
/* The personal shortcut sections read as "yours": the heading glyph takes the brand red. */
.section-favorites .section-head .icon { stroke: var(--accent-text); fill: var(--accent-text); }
.section-frequent .section-head .icon { stroke: var(--accent-text); }
.section-head .line { flex: 1; height: 1px; background: var(--border); }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 860px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .grid { grid-template-columns: 1fr; } }

/* ============ TILES ============ */
/* The cell positions the favourite star over the tile's corner; the tile is the real link. */
.tile-cell { position: relative; display: flex; }
.tile-cell .tile { flex: 1; min-width: 0; }
.tile {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
  text-decoration: none;
  box-shadow: 0 1px 2px var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  min-height: 168px;
}
.tile:hover, .tile:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px var(--shadow-lift);
  border-color: color-mix(in srgb, var(--accent-text) 40%, var(--card-border));
}
/* Right padding keeps the status badge / external marker clear of the favourite star. */
.tile-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding-right: 38px;
}

/* ============ FAVOURITE STAR ============ */
.fav-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.fav-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.fav-btn:hover { background: var(--accent-soft); color: var(--accent-text); }
/* Pinned: filled in the AA-safe brand red (the amber a star usually gets fails contrast). */
.fav-btn[aria-pressed="true"] { color: var(--accent-text); }
.fav-btn[aria-pressed="true"] svg { fill: currentColor; }
.tile-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: var(--accent-soft);
  color: var(--accent-text);
}
.tile:hover .tile-icon, .tile:focus-visible .tile-icon {
  background: var(--accent-text);
  color: var(--accent-ink);
}
.tile-icon { transition: background 0.15s, color 0.15s; }
.tile-icon svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.status.prod { background: var(--success); color: #fff; }
.status.proto { background: var(--warning); color: var(--ink); }
.status.retiring { background: var(--surface-sunken); color: var(--ink-muted); }

/* External corporate systems carry no platform status — they are not ours to promote. */
.tile-external {
  width: 15px;
  height: 15px;
  stroke: var(--ink-muted);
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.tile h3 { font-size: 15.5px; font-weight: 700; color: var(--ink); }
.tile p {
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tile-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent-text);
}
.tile-foot svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.15s;
}
.tile:hover .tile-foot svg, .tile:focus-visible .tile-foot svg { transform: translateX(3px); }

@media (prefers-reduced-motion: reduce) {
  .tile, .tile-icon, .fav-btn, .tile-foot svg, .sidebar { transition: none; }
  .tile:hover, .tile:focus-visible { transform: none; }
  .tile:hover .tile-foot svg, .tile:focus-visible .tile-foot svg { transform: none; }
}

/* ============ LOADING / EMPTY / ERROR ============ */
.state { padding: 40px 0; text-align: center; color: var(--ink-muted); font-size: 14px; }
.state.error { color: var(--danger); font-weight: 600; }
