/* A&M CEMS — one stylesheet. Brand colors match am-engr.com and the A&M logo. */
:root {
  --brand: #0B1C24;        /* A&M midnight: header, dark bands */
  --brand-dark: #061217;
  --brand-mid: #133A40;    /* deep spruce */
  --brand-ink: #ffffff;
  --lime: #C0DC2C;         /* A&M logo lime: primary buttons, highlights */
  --lime-hover: #A9C421;
  --lime-soft: #F1F7D2;
  --accent: #1F6F70;       /* A&M deep teal: links and accent text on light backgrounds */
  --accent-soft: #E3F1F0;
  --a-teal: #4FA8A8;       /* A&M teal */
  --ink: #2A2629;          /* A&M warm charcoal */
  --muted: #5E5A60;
  --line: #E2DED5;
  --bg: #F6F4EE;           /* A&M ivory */
  --surface: #ffffff;
  --red: #b42318;   --red-soft: #fdecea;
  --amber: #9a6700; --amber-soft: #fff4d6;
  --blue: #1d5fa8;  --blue-soft: #e8f0fb;
  --teal: #0f766e;  --teal-soft: #e0f4f1;
  --green: #1f7a45; --green-soft: #e3f4ea;
  --grey: #555f6d;  --grey-soft: #eef0f3;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-head: "Sora", "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--accent); }
a:hover { color: var(--brand-mid); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1, h2 { font-family: var(--font-head); letter-spacing: -.01em; color: var(--brand); }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }
.hide { display: none !important; }

/* ---------- top bar ---------- */
.top {
  display: flex; align-items: center; gap: 1rem;
  background: var(--brand); color: var(--brand-ink);
  padding: .5rem 1.1rem; position: sticky; top: 0; z-index: 20;
  border-bottom: 3px solid var(--lime);
}
.brand { display: flex; align-items: center; gap: .75rem; color: #fff; text-decoration: none; }
.brand:hover { color: #fff; }
.brand-logo { height: 34px; width: auto; display: block; }
.brand-app { display: flex; flex-direction: column; line-height: 1.1; padding-left: .75rem; border-left: 1px solid rgba(255,255,255,.25); }
.brand-app b { font-family: var(--font-head); font-weight: 700; font-size: 1.05rem; letter-spacing: .06em; color: var(--lime); }
.brand small { font-weight: 400; font-size: .72rem; opacity: .75; }
.top .project-name { color: #fff; opacity: .9; text-decoration: none; font-size: .92rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; min-width: 0; }
.top .spacer { flex: 1; }
.top .user { display: flex; align-items: center; gap: .75rem; font-size: .9rem; white-space: nowrap; }
.top .user form { margin: 0; }
.linkish { background: none; border: 0; color: inherit; font: inherit; cursor: pointer; text-decoration: underline; padding: 0; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 54px); }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 1rem .6rem; }
.side .role { font-size: .78rem; color: var(--muted); padding: 0 .6rem .75rem; }
.side a {
  display: flex; justify-content: space-between; align-items: center;
  padding: .5rem .65rem; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: .93rem;
}
.side a:hover { background: var(--bg); color: var(--ink); }
.side a.on { background: var(--lime-soft); color: var(--brand); font-weight: 600; box-shadow: inset 3px 0 0 var(--lime); }
.side .group { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: .9rem .65rem .25rem; }
.side .count { font-size: .75rem; background: var(--grey-soft); color: var(--grey); border-radius: 10px; padding: 0 .45rem; }
main { padding: 1.25rem 1.5rem 3rem; min-width: 0; }
main.wide { max-width: none; }
.single main, main.single { max-width: 1100px; margin: 0 auto; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head .sub { color: var(--muted); font-size: .9rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions form { margin: 0; }

/* ---------- cards & grids ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: .9rem 1.1rem 0; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); text-decoration: none; color: var(--ink); display: block; }
a.stat:hover { border-color: var(--accent); color: var(--ink); }
.stat .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-family: var(--font-head); font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--brand); }
.stat .note { font-size: .82rem; color: var(--muted); }
.stat .note.late { color: var(--red); font-weight: 600; }

.meter { height: 8px; background: var(--grey-soft); border-radius: 4px; overflow: hidden; margin: .35rem 0 .2rem; }
.meter > span { display: block; height: 100%; background: var(--lime-hover); }
.meter.time > span { background: var(--a-teal); }
.meter.over > span { background: var(--red); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.facts dt { color: var(--muted); font-size: .88rem; }
dl.facts dd { margin: 0; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: .5rem .65rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #FAF8F3; font-weight: 600; }
tbody tr:hover { background: #FBFAF6; }
tr.clickable { cursor: pointer; }
tr.total td { font-weight: 700; background: #FAF8F3; }
tr.warn td { background: var(--amber-soft); }
td a.row-link { font-weight: 600; text-decoration: none; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }

/* ---------- badges & alerts ---------- */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; }
.badge.grey { background: var(--grey-soft); color: var(--grey); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.teal { background: var(--teal-soft); color: var(--teal); }
.late { color: var(--red); font-weight: 600; }

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li, .alert { padding: .65rem .9rem; border-radius: var(--radius); margin-bottom: .5rem; border: 1px solid transparent; overflow-wrap: anywhere; }
.messages .success { background: var(--green-soft); border-color: #b7e0c6; }
.messages .info, .alert.info { background: var(--blue-soft); border-color: #c4d8f2; }
.messages .warning, .alert.warn { background: var(--amber-soft); border-color: #f1d58a; }
.messages .error, .alert.error { background: var(--red-soft); border-color: #f3b8b2; }

.todo { list-style: none; margin: 0; padding: 0; }
.todo li { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.todo li:last-child { border-bottom: 0; }
.todo a { text-decoration: none; font-weight: 500; }
.feed { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.feed li { padding: .4rem 0; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .35rem; justify-content: center;
  padding: .5rem .95rem; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: 600 .9rem var(--font);
  text-decoration: none; cursor: pointer; min-height: 38px; white-space: nowrap;
}
.btn:hover { border-color: #C9C3B6; color: var(--ink); background: #FBFAF6; }
.btn.primary { background: var(--lime); border-color: var(--lime); color: var(--brand); }
.btn.primary:hover { background: var(--lime-hover); border-color: var(--lime-hover); color: var(--brand); }
.btn.navy { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.navy:hover { background: var(--brand-dark); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: #f3b8b2; }
.btn.small { padding: .25rem .6rem; min-height: 30px; font-size: .82rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .85rem 1rem; }
.field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: .84rem; font-weight: 600; color: var(--ink); }
.field .help { font-size: .8rem; color: var(--muted); }
.field .errors { color: var(--red); font-size: .82rem; margin: 0; padding: 0; list-style: none; }
.field.check { flex-direction: row; align-items: center; gap: .5rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time],
input[type=search], input[type=url], input[type=tel], select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid #c9d1da; border-radius: 6px;
  font: 15px var(--font); color: var(--ink); background: #fff; min-height: 38px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(79, 168, 168, .4); border-color: var(--accent); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.1rem; align-items: center; }
.errorlist { color: var(--red); }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: 1rem; }
.filters .field { min-width: 140px; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs a { padding: .35rem .8rem; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: .88rem; border: 1px solid var(--line); background: var(--surface); }
.tabs a.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* formset tables */
table.rows th, table.rows td { padding: .35rem .4rem; border-bottom: 0; }
table.rows td input, table.rows td select { min-width: 70px; }
table.rows td.del { text-align: center; width: 60px; }
table.rows tr.deleted td { opacity: .4; }
.formset { margin-bottom: 1rem; }
.formset .add-row { margin-top: .4rem; }

/* ---------- photos ---------- */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .75rem; }
.photo { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.photo img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: var(--grey-soft); }
.photo .cap { padding: .4rem .55rem; font-size: .8rem; }
.photo .cap form { display: inline; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(ellipse at 20% 0%, var(--brand-mid) 0%, var(--brand) 55%, var(--brand-dark) 100%); }
.auth .card { width: 100%; max-width: 400px; padding: 1.75rem; border-top: 4px solid var(--lime); }
.auth-brand { margin-bottom: 1.25rem; }
.auth-brand img { width: 220px; max-width: 100%; height: auto; display: block; margin-bottom: .85rem; }
.auth-brand b { display: block; font-family: var(--font-head); font-size: 1.25rem; color: var(--brand); letter-spacing: .04em; }
.auth-brand small { color: var(--muted); }
.auth .btn.primary { width: 100%; }
.auth .field { margin-bottom: .85rem; }

/* ---------- small screens: sidebar becomes a scrolling tab strip ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: flex; overflow-x: auto; gap: .25rem; padding: .5rem; border-right: 0; border-bottom: 1px solid var(--line); position: sticky; top: 50px; z-index: 10; }
  .side a.on { box-shadow: inset 0 -3px 0 var(--lime); }
  .brand-logo { height: 28px; }
  .brand-app { padding-left: .6rem; }
  .side .group, .side .role { display: none; }
  .side a { white-space: nowrap; padding: .4rem .7rem; }
  .side .count { margin-left: .35rem; }
  main { padding: 1rem .8rem 3rem; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .top .project-name, .brand small, .top .user .who { display: none; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  table.rows thead { display: none; }
  table.rows tr { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
  table.rows td { padding: 0; }
  table.rows td.span2 { grid-column: 1 / -1; }
  table.rows td::before { content: attr(data-label); display: block; font-size: .72rem; color: var(--muted); }
}
@media (max-width: 480px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- print ---------- */
.print-page { max-width: 8.5in; margin: 0 auto; background: #fff; padding: .5in; font-size: 11pt; }
.print-page table { font-size: 9.5pt; }
.print-page th, .print-page td { padding: .25rem .35rem; }
.print-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 3px solid var(--lime); padding-bottom: .5rem; margin-bottom: .75rem; }
.print-logo { height: 46px; width: auto; display: block; margin-bottom: .2rem; }
.print-bar { background: var(--brand); color: #fff; padding: .5rem 1rem; display: flex; gap: .75rem; align-items: center; justify-content: center; }
.signature { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin-top: 2.5rem; }
.signature div { border-top: 1px solid var(--ink); padding-top: .25rem; font-size: .85rem; }
@media print {
  body { background: #fff; }
  .print-bar, .no-print { display: none !important; }
  .print-page { padding: 0; max-width: none; }
  a { color: inherit; text-decoration: none; }
  tr { break-inside: avoid; }
}
