/*
  MP Office Portal, office screens.

  The office already has a visual language on paper: a gold-ruled ceremonial
  letterhead, a green official letterhead, and a register where every item is a
  numbered docket, a token, a work number, a reference number. The screens
  follow that register: a ruled left gutter carries the number, hairline rules
  separate entries, and state is a chip rather than a colour wash. Gold is a
  rule and a marker, never a fill; green means issued or done; the accent is
  spent in one place per screen.
*/

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  font-variant-numeric: tabular-nums;
}

html[lang="gu"] body { font-family: var(--font-gu); }
html[lang="hi"] body { font-family: var(--font-hi); }

a { color: var(--navy-700); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--gold-300); outline-offset: 2px; border-radius: 3px; }

h1, h2, h3 { margin: 0 0 var(--s3); line-height: 1.22; text-wrap: balance; }
h1 { font-size: var(--text-xl); font-weight: 600; letter-spacing: -.2px; }
h2 {
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--gold-700);
  margin: var(--s6) 0 var(--s3);
  padding-bottom: var(--s2);
  border-bottom: 1px solid var(--line);
}
h3 { font-size: var(--text-base); font-weight: 600; }
p { margin: 0 0 var(--s3); }
.muted { color: var(--ink-3); font-size: var(--text-sm); }

/* ---------- Masthead ----------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: var(--header-h);
  padding: var(--s2) var(--s4);
  background: var(--navy-900);
  color: #fff;
  box-shadow: inset 0 -3px 0 var(--gold-500);
}
.app-header .emblem { height: 36px; width: auto; flex: none; }
.app-header .brand { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.app-header .brand .name {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 1.6px;
  color: var(--gold-200);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
html[lang="gu"] .app-header .brand .name { font-family: var(--font-gu); letter-spacing: .4px; font-size: 15px; }
.app-header .brand .role { font-size: 11.5px; color: #b9c0dd; letter-spacing: .2px; }
.app-header .spacer { flex: 1; }
.app-header .mp-photo {
  height: 36px; width: 36px; border-radius: 50%;
  object-fit: cover; object-position: 50% 20%;
  box-shadow: 0 0 0 1.5px var(--gold-500);
  flex: none;
}
.app-header .lang-toggle { font-size: 11.5px; white-space: nowrap; letter-spacing: .3px; }
.app-header .lang-toggle a { color: #b9c0dd; }
.app-header .lang-toggle a[aria-current="true"] { color: var(--gold-200); font-weight: 600; }

/* ---------- Navigation --------------------------------------------------- */

.nav-desktop { display: none; }

.nav-mobile {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  gap: 0;
  overflow-x: auto;
  background: var(--surface);
  border-top: 1px solid var(--line-strong);
  padding: 0 var(--s2) env(safe-area-inset-bottom, 0);
  scrollbar-width: none;
}
.nav-mobile::-webkit-scrollbar { display: none; }
.nav-mobile a, .nav-mobile button {
  flex: 0 0 auto;
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  padding: 0 var(--s4);
  font-size: var(--text-sm);
  color: var(--ink-2);
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.nav-mobile a[aria-current="page"] {
  color: var(--navy-700);
  font-weight: 600;
  border-bottom-color: var(--gold-500);
}
.nav-mobile .inline-form { display: inline-flex; margin: 0; }
body { padding-bottom: calc(var(--tabbar-h) + var(--s5)); }

@media (min-width: 900px) {
  .nav-desktop {
    display: flex;
    align-items: stretch;
    gap: var(--s4);
    padding: 0 var(--s5);
    background: var(--surface);
    border-bottom: 1px solid var(--line-strong);
    position: sticky; top: var(--header-h); z-index: 20;
  }
  .nav-desktop ul { list-style: none; display: flex; flex-wrap: wrap; margin: 0; padding: 0; flex: 1; }
  .nav-desktop a {
    display: inline-flex; align-items: center;
    padding: var(--s3) var(--s3);
    color: var(--ink-2);
    font-size: var(--text-sm);
    border-bottom: 3px solid transparent;
  }
  .nav-desktop a:hover { color: var(--navy-700); text-decoration: none; border-bottom-color: var(--line-strong); }
  .nav-desktop a[aria-current="page"] { color: var(--navy-700); font-weight: 600; border-bottom-color: var(--gold-500); }
  .nav-desktop .inline-form { align-self: center; margin: 0; }
  .nav-mobile { display: none; }
  body { padding-bottom: var(--s6); }
}

/* ---------- Layout ------------------------------------------------------- */

.container {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s5) var(--s4) var(--s7);
}

.page-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s3);
  margin-bottom: var(--s5);
}
.page-head h1 { margin: 0; }
.page-head .count, .page-head .muted { color: var(--ink-3); font-size: var(--text-sm); }

/* ---------- The attention strip ------------------------------------------
   Not six identical tiles. The three things that need a decision today are
   stated in words; the ambient counts sit quietly beneath them.             */

.attention { display: grid; gap: var(--s2); margin-bottom: var(--s5); }
.attention a {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: var(--s4);
  padding: var(--s4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold-500);
  border-radius: 3px;
}
.attention a:hover { text-decoration: none; border-color: var(--line-strong); border-left-color: var(--gold-700); }
.attention .n { font-size: 26px; font-weight: 600; color: var(--navy-700); line-height: 1; text-align: right; }
.attention .what { color: var(--ink); font-size: var(--text-base); }
.attention .go { color: var(--ink-3); font-size: 18px; }
.attention a.is-clear { border-left-color: var(--line-strong); }
.attention a.is-clear .n { color: var(--ink-3); font-weight: 400; }

.quiet-counts {
  display: flex; flex-wrap: wrap; gap: var(--s5);
  padding: var(--s3) var(--s4);
  background: var(--surface-2);
  border-radius: 3px;
  margin-bottom: var(--s5);
  font-size: var(--text-sm);
}
.quiet-counts a { color: var(--ink-2); }
.quiet-counts b { color: var(--navy-700); font-weight: 600; }

.quick-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s5); }

/* ---------- Lists --------------------------------------------------------
   Two shapes only. A plain list is one column of entries. A register list
   adds a ruled gutter carrying the docket number, and only lists whose
   entries actually have a number use it.                                    */

.card-list {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.card-list > article {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--line);
}
.card-list > article:last-child { border-bottom: 0; }
.card-list > article:hover { background: var(--surface-2); }
.card-list > p.muted { padding: var(--s5); margin: 0; }

.card-list article h3 { margin: 0; font-size: var(--text-base); }
.card-list article p { margin: 0; font-size: var(--text-sm); color: var(--ink-2); }
.card-list article .actions {
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s3);
  align-items: flex-end;
  margin-top: var(--s3);
  padding-top: var(--s3);
  border-top: 1px dashed var(--line);
}
.card-list article .actions .inline-form { margin: 0; }

/* The register: a numbered gutter, as in the office's own book. */
.card-list.register > article {
  display: grid;
  grid-template-columns: 56px 1fr;
  column-gap: var(--s4);
  row-gap: 3px;
  align-items: start;
}
.card-list.register > article > * { grid-column: 2; }
.card-list.register .docket {
  grid-column: 1;
  grid-row: 1 / span 20;
  align-self: stretch;
  margin: 0;
  padding: 2px var(--s4) 0 0;
  border-right: 1px solid var(--line);
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  color: var(--gold-700);
  text-align: right;
}
.card-list.register .docket a { color: inherit; }
.card-list.register .entry-title { font-size: var(--text-lg); }

/* A reference number is itself the title. */
.letter-card h3, .work-card h3 {
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: .4px;
  color: var(--navy-700);
}

.is-cancelled { opacity: .55; }
.is-cancelled h3 { text-decoration: line-through; }
.is-stale, .is-overdue { box-shadow: inset 3px 0 0 var(--warn-500); }
.is-unassigned { box-shadow: inset 3px 0 0 var(--ink-3); }
.is-greeted { opacity: .6; }
.overdue { color: var(--danger-500); font-weight: 600; }

/* One object for state, used on every screen. */
.chip-state {
  display: inline-flex; align-items: center;
  padding: 2px 9px;
  border-radius: 2px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .3px;
  text-transform: uppercase;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--line-strong);
}
.chip-state.ok { background: var(--ok-100); color: var(--ok-500); border-color: #bfe3cb; }
.chip-state.warn { background: var(--warn-100); color: var(--warn-500); border-color: #f0d9a8; }
.chip-state.danger { background: var(--danger-100); color: var(--danger-500); border-color: #f4c1bb; }
.chip-state.info { background: var(--info-100); color: var(--info-500); border-color: #c5daf3; }

/* ---------- Standalone panel --------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: var(--s4) var(--s5);
}

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

form label {
  display: block;
  margin-bottom: var(--s4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink-2);
}
form input, form select, form textarea {
  display: block;
  width: 100%;
  min-height: 46px;
  margin-top: 5px;
  padding: var(--s2) var(--s3);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  font: inherit;
  font-size: 16px; /* stops iOS zooming on focus */
  color: var(--ink);
}
form textarea { min-height: 96px; resize: vertical; }
form input:focus, form select:focus, form textarea:focus {
  border-color: var(--gold-500);
  outline: 3px solid var(--gold-200);
  outline-offset: 0;
}
form label input[type="checkbox"] { display: inline-block; width: auto; min-height: 0; margin-right: var(--s2); }

button, .button {
  min-height: 46px;
  padding: 0 var(--s5);
  background: var(--navy-700);
  color: #fff;
  border: 1px solid var(--navy-700);
  border-radius: 3px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover { background: var(--navy-500); }
button.secondary, .inline-form button {
  background: var(--surface);
  color: var(--navy-700);
  border-color: var(--line-strong);
  font-weight: 500;
  padding: 0 var(--s4);
}
button.secondary:hover, .inline-form button:hover { background: var(--surface-2); }
.link-button { background: none; border: none; color: var(--navy-700); text-decoration: underline; padding: 0; min-height: 0; }

/* A pill is an action, and only ever an action. */
.chip {
  display: inline-flex; align-items: center;
  min-height: 44px; padding: 0 var(--s5);
  border-radius: 3px;
  background: var(--surface);
  border: 1px solid var(--navy-700);
  color: var(--navy-700);
  font-weight: 600;
  font-size: var(--text-sm);
}
.chip:hover { background: var(--navy-700); color: #fff; text-decoration: none; }

.inline-form { display: inline-flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin-bottom: var(--s2); }
.inline-form input, .inline-form select { width: auto; min-width: 140px; margin-top: 0; }

.visitors-filters, .works-filters, .letters-filters, .contacts-filters {
  display: flex; flex-wrap: wrap; gap: var(--s4); align-items: flex-end;
  padding: var(--s4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 3px;
  margin-bottom: var(--s4);
}
.visitors-filters label, .works-filters label, .letters-filters label, .contacts-filters label { margin-bottom: 0; }
.visitors-filters input, .visitors-filters select,
.works-filters select, .letters-filters select,
.contacts-filters input, .contacts-filters select { width: auto; min-width: 150px; }

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

.flash, .flash-success, .flash-error, .flash-notice, .flash-info, .notice, .form-errors {
  padding: var(--s3) var(--s4);
  border-radius: 3px;
  margin-bottom: var(--s4);
  border: 1px solid;
  border-left-width: 3px;
  font-size: var(--text-sm);
}
.flash-success { background: var(--ok-100); color: var(--ok-500); border-color: #bfe3cb; }
.flash-error, .form-errors { background: var(--danger-100); color: var(--danger-500); border-color: #f4c1bb; list-style: none; }
.flash-info, .flash-notice, .notice { background: var(--info-100); color: var(--info-500); border-color: #c5daf3; }

[data-token-slip] {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  background: var(--gold-050);
  color: var(--gold-900);
  border-color: var(--gold-300);
}

/* ---------- Detail pages -------------------------------------------------- */

dl, dl.visit-facts, dl.work-facts {
  display: grid;
  grid-template-columns: minmax(110px, 30%) 1fr;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0;
  margin: 0 0 var(--s5);
  overflow: hidden;
}
dt {
  padding: var(--s3) var(--s4);
  color: var(--ink-3);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
dd {
  margin: 0;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
}
dl > dt:last-of-type, dl > dd:last-of-type { border-bottom: 0; }

section { margin-bottom: var(--s6); }
.status-history { list-style: none; padding: 0; margin: 0; font-size: var(--text-sm); }
.status-history li {
  padding: var(--s3) 0 var(--s3) var(--s4);
  border-left: 2px solid var(--line-strong);
  margin-left: 6px;
  color: var(--ink-2);
  position: relative;
}
.status-history li::before {
  content: "";
  position: absolute; left: -5px; top: 18px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--gold-500);
}

/* ---------- Tables -------------------------------------------------------- */

.table-scroll {
  overflow-x: auto;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
}
table { border-collapse: collapse; width: 100%; min-width: 560px; font-size: var(--text-sm); }
th, td { text-align: left; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
thead th {
  background: var(--surface-2);
  color: var(--ink-3);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .8px;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tr.is-cancelled td { text-decoration: line-through; color: var(--ink-3); }

/* ---------- Share and QR -------------------------------------------------- */

.qr-block { background: var(--surface); border: 1px solid var(--line); border-radius: 3px; padding: var(--s5); max-width: 320px; }
.qr-block svg { width: 100%; height: auto; display: block; }
.share-text {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold-500);
  padding: var(--s3) var(--s4);
  border-radius: 3px;
  font-size: var(--text-sm);
}

/* ---------- Login --------------------------------------------------------- */

.auth-page {
  max-width: 400px;
  margin: 7vh auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.auth-page .crest {
  background: var(--navy-900);
  box-shadow: inset 0 -3px 0 var(--gold-500);
  padding: var(--s5) var(--s5) var(--s4);
  text-align: center;
  color: #fff;
}
.auth-page .crest .emblem { height: 52px; }
.auth-page .crest .mp-photo {
  height: 84px; width: 84px; border-radius: 50%;
  object-fit: cover; object-position: 50% 18%;
  box-shadow: 0 0 0 2px var(--gold-500);
  display: block; margin: var(--s3) auto var(--s3);
}
.auth-page .crest h1 {
  font-family: var(--font-display);
  font-size: 15px; font-weight: 600; letter-spacing: 1.6px;
  color: var(--gold-200); text-transform: uppercase; margin: 0 0 3px;
}
html[lang="gu"] .auth-page .crest h1 { font-family: var(--font-gu); letter-spacing: .4px; font-size: 17px; }
.auth-page .crest h2 {
  font-size: 12px; color: #b9c0dd; font-weight: 400; letter-spacing: .2px;
  margin: 0; padding: 0; border: 0; text-transform: none;
}
.auth-page .body { padding: var(--s5); }
.auth-page form button[type="submit"] { width: 100%; }
.auth-page .lang-toggle { text-align: center; font-size: var(--text-sm); margin-bottom: var(--s4); }
.auth-page .foot { text-align: center; padding: 0 var(--s5) var(--s5); font-size: var(--text-sm); }

.error-page { text-align: center; padding-top: 12vh; }

@media (max-width: 560px) {
  .app-header .brand .role { display: none; }
  .app-header { gap: var(--s2); padding: var(--s2) var(--s3); }
  .card-list > article { grid-template-columns: 46px 1fr; gap: var(--s1) var(--s3); padding: var(--s3); }
  .visit-card .visit-token, .card-list article .docket { padding-right: var(--s3); font-size: 17px; }
  .attention a { grid-template-columns: 42px 1fr auto; gap: var(--s3); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Editable master tables ---------------------------------------
   A row of inputs with its own Save is a heavy pattern, so the button is
   quiet and the inputs sit flush in the cell.                               */

table input, table select {
  min-height: 38px;
  margin-top: 0;
  padding: 5px var(--s2);
  font-size: var(--text-sm);
}
table td .inline-form { margin: 0; }
table td button {
  min-height: 36px;
  padding: 0 var(--s3);
  background: var(--surface);
  color: var(--navy-700);
  border: 1px solid var(--line-strong);
  font-weight: 500;
  font-size: var(--text-sm);
}
table td button:hover { background: var(--navy-700); color: #fff; }
table td .row-actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
table td a { font-size: var(--text-sm); }

/* Stacked action forms inside a card sit on one line, wrapping as a unit. */
.action-row {
  display: flex; flex-wrap: wrap; gap: var(--s3);
  align-items: flex-end;
}
.action-row .field { display: flex; flex-direction: column; gap: 3px; font-size: var(--text-sm); color: var(--ink-2); }
.action-row input, .action-row select { margin-top: 0; min-width: 150px; }
