/* ==========================================================================
   PIT — layout and components.

   Every colour, font and spacing value comes from tokens.css. Nothing is
   hard-coded here.

   Design intent: a dense, sober analyst's tool. Numbers are right aligned with
   tabular figures, hierarchy is carried by type and rules rather than colour,
   gold appears sparingly as an accent.
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--p-white);
  color: var(--p-black);
  font-family: var(--p-font-sans);
  font-size: var(--p-size-body);
  line-height: var(--p-line-body);
}

h1,
h2,
h3,
h4 {
  font-family: var(--p-font-serif);
  font-weight: normal;
  color: var(--p-black);
  margin: 0;
}

h1 { font-size: var(--p-size-h1); }
h2 { font-size: var(--p-size-h2); }
h3 { font-size: var(--p-size-h3); }

a {
  color: var(--p-gold);
  text-decoration: none;
}

a:hover,
a:focus-visible {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--p-gold);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Text helpers
   -------------------------------------------------------------------------- */

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.mono {
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--p-gray);
}

.small {
  font-size: var(--p-size-small);
}

.tiny {
  font-size: var(--p-size-tiny);
}

.up {
  color: var(--p-gold);
  font-weight: bold;
}

.dn {
  color: var(--p-gray);
}

/* --------------------------------------------------------------------------
   Application layout
   -------------------------------------------------------------------------- */

.app {
  display: flex;
  min-height: 100vh;
}

.side {
  width: var(--p-sidebar-width);
  flex: 0 0 var(--p-sidebar-width);
  border-right: var(--p-border);
  background: var(--p-white);
  padding-bottom: var(--p-space-6);
}

/* Logo on white ground with its protection zone. */
.brand {
  padding: var(--p-logo-guard) var(--p-space-4) var(--p-space-3);
  border-bottom: var(--p-border);
  text-align: center;
}

.brand img {
  width: var(--p-logo-width);
  height: auto;
  display: block;
  margin: 0 auto;
}

.brand .appname {
  font-family: var(--p-font-serif);
  font-size: var(--p-size-h3);
  letter-spacing: 0.12em;
  margin-top: 9px;
}

.brand .appsub {
  font-size: 9.5px;
  line-height: 1.3;
  color: var(--p-gray);
}

.navlabel {
  font-size: var(--p-size-tiny);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--p-gray);
  padding: var(--p-space-4) var(--p-space-4) 6px;
}

.nav {
  padding-top: var(--p-space-3);
}

.nav a {
  display: block;
  padding: var(--p-space-2) var(--p-space-4);
  color: var(--p-black);
  font-size: var(--p-size-body);
  border-left: 3px solid transparent;
}

.nav a:hover {
  background: var(--p-gold-tint);
  text-decoration: none;
}

.nav a.active {
  border-left-color: var(--p-gold);
  color: var(--p-gold);
  font-weight: bold;
  background: var(--p-gold-tint);
}

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

.topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--p-space-3);
  padding: var(--p-space-2) var(--p-space-5);
  border-bottom: var(--p-border);
  font-size: var(--p-size-small);
  color: var(--p-gray);
}

.topbar .who {
  color: var(--p-black);
}

.content {
  flex: 1;
  padding: 20px var(--p-space-5) var(--p-space-6);
}

.sitefoot {
  display: flex;
  justify-content: space-between;
  gap: var(--p-space-4);
  flex-wrap: wrap;
  padding: var(--p-space-3) var(--p-space-5);
  border-top: var(--p-border);
  font-size: var(--p-size-tiny);
  color: var(--p-gray);
}

.pagehead {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: var(--p-border);
  padding-bottom: var(--p-space-3);
  margin-bottom: var(--p-space-5);
  gap: var(--p-space-4);
  flex-wrap: wrap;
}

.pagehead .sub {
  color: var(--p-gray);
  font-size: var(--p-size-small);
  margin-top: var(--p-space-1);
}

.pagehead .actions {
  display: flex;
  gap: var(--p-space-2);
  align-items: center;
  flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   Grid
   -------------------------------------------------------------------------- */

.grid {
  display: grid;
  gap: var(--p-space-3);
}

.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g5 { grid-template-columns: repeat(5, 1fr); }

/* --------------------------------------------------------------------------
   Card
   -------------------------------------------------------------------------- */

.card {
  border: var(--p-border);
  border-radius: var(--p-radius-card);
  background: var(--p-white);
  padding: var(--p-space-3) var(--p-space-4);
}

.card > h3 {
  margin-bottom: var(--p-space-3);
}

.card.flush {
  padding: 0;
}

/* --------------------------------------------------------------------------
   Key figure tile
   -------------------------------------------------------------------------- */

.kpi .l {
  font-size: var(--p-size-small);
  color: var(--p-gray);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.kpi .v {
  font-family: var(--p-font-serif);
  font-size: 30px;
  line-height: 1.1;
  margin-top: var(--p-space-1);
  font-variant-numeric: tabular-nums;
}

.kpi .d {
  font-size: var(--p-size-small);
  margin-top: 5px;
}

.kpi .v.empty {
  color: var(--p-gray);
  font-size: var(--p-size-h2);
}

/* --------------------------------------------------------------------------
   Table
   -------------------------------------------------------------------------- */

table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--p-size-table);
}

th {
  background: var(--p-gold);
  color: var(--p-white);
  font-weight: bold;
  text-align: left;
  padding: 7px 9px;
  font-size: var(--p-size-small);
  white-space: nowrap;
}

th.num {
  text-align: right;
}

td {
  padding: 6px 9px;
  border-bottom: var(--p-border);
}

tbody tr:nth-child(even) {
  background: var(--p-gray-light);
}

tbody tr:hover {
  background: var(--p-gold-tint-strong);
}

/* Horizontal scroll container. Wide tables scroll inside their own box; the
   page body must never scroll sideways. */
.tw {
  overflow-x: auto;
}

/* Definition list, label left, value right aligned with tabular figures. */
.dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px var(--p-space-3);
  font-size: var(--p-size-table);
  margin: 0;
}

.dl dt {
  color: var(--p-gray);
}

.dl dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Button
   -------------------------------------------------------------------------- */

.btn {
  display: inline-block;
  background: var(--p-gold);
  color: var(--p-white);
  border: 1px solid var(--p-gold);
  padding: 6px 13px;
  font-size: var(--p-size-table);
  font-family: var(--p-font-sans);
  border-radius: var(--p-radius);
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
}

.btn:hover,
.btn:focus-visible {
  text-decoration: none;
  filter: brightness(0.94);
}

.btn.ghost {
  background: var(--p-white);
  color: var(--p-gold);
}

.btn.plain {
  background: var(--p-white);
  color: var(--p-black);
  border-color: var(--p-gray-light);
}

.btn[disabled],
.btn.disabled {
  opacity: 0.5;
  cursor: default;
}

.btn.block {
  width: 100%;
  text-align: center;
}

/* --------------------------------------------------------------------------
   Status marker
   -------------------------------------------------------------------------- */

.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 2px;
  font-size: var(--p-size-tiny);
  font-weight: bold;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.tag.solid {
  background: var(--p-gold);
  color: var(--p-white);
}

.tag.light {
  background: var(--p-gold-light);
  color: var(--p-black);
}

.tag.neutral {
  background: var(--p-gray-light);
  color: var(--p-black);
}

.tag.outline {
  background: var(--p-white);
  color: var(--p-gold);
  border: 1px solid var(--p-gold);
}

.tag.quiet {
  background: var(--p-white);
  color: var(--p-gray);
  border: 1px solid var(--p-gray);
}

/* Machine-generated values are marked as such until an analyst confirms them.
   Deliberately visually distinct from every analyst marker. */
.tag.ki {
  background: var(--p-white);
  color: var(--p-blue-gray);
  border: 1px solid var(--p-blue-gray);
}

/* --------------------------------------------------------------------------
   Note box
   -------------------------------------------------------------------------- */

.note {
  background: var(--p-gold-tint);
  border-left: 3px solid var(--p-gold-light);
  padding: 9px var(--p-space-3);
  font-size: 11.5px;
  margin: var(--p-space-3) 0;
}

.note.plain {
  border-left-color: var(--p-gray-light);
  background: var(--p-white);
  border: var(--p-border);
}

/* --------------------------------------------------------------------------
   Empty state — shown where data does not exist yet. Never a fabricated number.
   -------------------------------------------------------------------------- */

.empty {
  color: var(--p-gray);
  font-size: var(--p-size-table);
}

/* --------------------------------------------------------------------------
   Progress bar
   -------------------------------------------------------------------------- */

.bar {
  height: 7px;
  background: var(--p-gray-light);
  border-radius: var(--p-radius);
  overflow: hidden;
  min-width: 56px;
}

.bar i {
  display: block;
  height: 100%;
  background: var(--p-gold);
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

label {
  display: block;
  font-size: var(--p-size-small);
  color: var(--p-gray);
  margin-bottom: var(--p-space-1);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="month"],
input[type="file"],
select,
textarea {
  font-family: var(--p-font-sans);
  font-size: var(--p-size-table);
  padding: 6px var(--p-space-2);
  border: var(--p-border);
  border-radius: var(--p-radius);
  background: var(--p-white);
  color: var(--p-black);
  width: 100%;
}

textarea {
  line-height: var(--p-line-body);
}

.field {
  margin-bottom: var(--p-space-3);
}

.field .help {
  font-size: var(--p-size-small);
  color: var(--p-gray);
  margin-top: var(--p-space-1);
}

.field .errors {
  font-size: var(--p-size-small);
  color: var(--p-gold);
  margin-top: var(--p-space-1);
  list-style: none;
  padding: 0;
}

.formactions {
  display: flex;
  gap: var(--p-space-2);
  align-items: center;
  margin-top: var(--p-space-4);
}

/* --------------------------------------------------------------------------
   Messages
   -------------------------------------------------------------------------- */

.messages {
  list-style: none;
  margin: 0 0 var(--p-space-4);
  padding: 0;
}

.messages li {
  border: var(--p-border);
  border-left: 3px solid var(--p-gold);
  padding: 9px var(--p-space-3);
  font-size: 11.5px;
  margin-bottom: var(--p-space-2);
}

.messages li.error {
  border-left-color: var(--p-black);
}

/* --------------------------------------------------------------------------
   Login page — white ground, centred card, logo above
   -------------------------------------------------------------------------- */

.loginpage {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--p-space-5);
  background: var(--p-white);
}

.loginbox {
  width: 340px;
  max-width: 100%;
}

.loginbox .brandblock {
  text-align: center;
  margin-bottom: var(--p-space-5);
  padding: var(--p-logo-guard) 0;
}

.loginbox .brandblock img {
  width: 180px;
  height: auto;
}

.loginbox .brandblock .appname {
  font-family: var(--p-font-serif);
  font-size: var(--p-size-h2);
  letter-spacing: 0.12em;
  margin-top: var(--p-space-3);
}

.loginbox .brandblock .appsub {
  font-size: var(--p-size-small);
  color: var(--p-gray);
}

.loginfoot {
  margin-top: var(--p-space-4);
  text-align: center;
  font-size: var(--p-size-tiny);
  color: var(--p-gray);
  line-height: 1.5;
}

/* --------------------------------------------------------------------------
   Timeline
   -------------------------------------------------------------------------- */

.timeline {
  border-left: 2px solid var(--p-gray-light);
  padding-left: var(--p-space-3);
  margin-left: var(--p-space-1);
}

.timeline .ev {
  margin-bottom: var(--p-space-3);
  position: relative;
}

.timeline .ev::before {
  content: "";
  position: absolute;
  left: -19px;
  top: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--p-gold);
}

/* --------------------------------------------------------------------------
   Responsive — desktop first, usable on a tablet
   -------------------------------------------------------------------------- */

@media (max-width: 1400px) {
  .g5 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1100px) {
  .g5,
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g3,
  .g2 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app { flex-direction: column; }

  .side {
    width: 100%;
    flex: 0 0 auto;
    border-right: none;
    border-bottom: var(--p-border);
  }

  .nav a { padding-left: var(--p-space-4); }
}
