:root {
  color-scheme: light;
  --bg: #f5f2e8;
  --surface: #fffaf0;
  --ink: #2f3a2e;
  --muted: #716b58;
  --line: #dcc29d;
  --primary: #7f8a5a;
  --primary-strong: #53644a;
  --dark: #2f3a2e;
  --accent: #b85b4d;
  --gold: #c9b489;
  --sand: #f7dec6;
  --khaki: #d6c29d;
  --earth: #a59066;
  --shadow: 0 10px 22px rgba(47, 58, 46, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(110px 70px at 12% 10%, rgba(214, 194, 157, 0.55), transparent 72%),
    radial-gradient(150px 90px at 86% 16%, rgba(127, 138, 90, 0.20), transparent 70%),
    radial-gradient(160px 88px at 18% 82%, rgba(165, 144, 102, 0.24), transparent 74%),
    linear-gradient(135deg, #fffaf0 0%, var(--bg) 100%);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.14;
  background:
    radial-gradient(90px 48px at 18% 22%, var(--earth), transparent 65%),
    radial-gradient(120px 62px at 74% 18%, var(--field), transparent 66%),
    radial-gradient(110px 52px at 66% 72%, var(--khaki), transparent 64%),
    radial-gradient(90px 44px at 28% 76%, var(--sand), transparent 62%);
  background-size: 330px 240px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 4px;
  background: var(--primary);
  color: white;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 0.86rem;
}

button:active {
  transform: translateY(1px);
}

input,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: white;
  color: var(--ink);
  padding: 9px 11px;
}

textarea {
  min-height: 140px;
  resize: vertical;
}

a {
  color: var(--primary-strong);
  font-weight: 700;
}

.login-view {
  display: grid;
  min-height: 100vh;
  padding: 22px;
  place-items: center;
}

.login-panel {
  width: min(100%, 390px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 28px;
  position: relative;
  overflow: hidden;
}

.login-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 9px;
  background: linear-gradient(90deg, var(--sand), var(--field), var(--earth), var(--khaki));
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 82px;
  border-radius: 6px;
  margin-bottom: 8px;
  background:
    url("public/assets/ptva-engineer-icon.png") center / 82px auto no-repeat,
    url("public/assets/ptva-bottom-nav.png") center / cover no-repeat;
  color: transparent;
  box-shadow: 0 8px 18px rgba(47, 58, 46, 0.12);
}

.login-panel h1,
.topbar h1,
.tab-panel h2,
.privacy-note h3 {
  margin: 0;
  letter-spacing: 0;
  font-family: Impact, "Arial Narrow", Arial, sans-serif;
  font-weight: 500;
  text-transform: uppercase;
}

.login-panel p,
.section-head p,
.privacy-note p,
.eyebrow {
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 14px;
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: var(--accent);
}

.app-shell {
  width: min(100%, 460px);
  margin: 0 auto;
  padding: 12px 10px 86px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin: 0 0 8px;
  min-height: 104px;
  padding: 14px;
  overflow: hidden;
  border: 0;
  border-radius: 5px;
  background: url("public/assets/ptva-header-exact.png") center / 100% 100% no-repeat;
  box-shadow: 0 10px 22px rgba(47, 58, 46, 0.12);
}

.topbar::after {
  display: none;
}

.topbar > * {
  position: relative;
  z-index: 2;
}

.topbar h1,
.topbar .eyebrow {
  color: #4d5638;
  text-shadow: 0 1px 0 rgba(255, 250, 240, 0.72);
}

.topbar h1 {
  font-size: 2.25rem;
  line-height: 0.95;
  letter-spacing: 1px;
}

.brand-lockup {
  display: none;
  align-items: center;
  min-width: 0;
  gap: 16px;
}

.engineer-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 70px;
  height: 70px;
  color: #4d5638;
  filter: drop-shadow(0 1px 0 rgba(255, 250, 240, 0.82));
}

.engineer-mark svg {
  width: 70px;
  height: 70px;
  stroke: currentColor;
  fill: none;
  stroke-width: 3.4;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.engineer-mark .mark-castle {
  fill: rgba(77, 86, 56, 0.2);
}

.engineer-mark .mark-ring {
  fill: none;
  stroke-width: 4;
}

.engineer-mark .mark-laurel {
  fill: none;
  stroke-width: 3.6;
}

.eyebrow {
  margin: 5px 0 0;
  font-size: 0.82rem;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 4px;
}

.icon-button {
  background: #23332e;
  min-width: 68px;
  box-shadow: 0 2px 8px rgba(47, 58, 46, 0.22);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.gear-button {
  display: grid;
  place-items: center;
  min-width: 44px;
  width: 44px;
  padding: 0;
}

.gear-button svg {
  width: 19px;
  height: 19px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ask-panel,
.tab-panel,
.privacy-note {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 5px 16px rgba(24, 35, 31, 0.06);
}

.ask-panel {
  padding: 10px;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    linear-gradient(90deg, var(--gold), var(--primary), var(--earth)) border-box;
  border: 1px solid transparent;
}

.ask-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
}

.ask-form input {
  min-width: 0;
}

.ask-form .secondary {
  background: #efe6d4;
  color: var(--ink);
}

.answer-box {
  display: none;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  line-height: 1.45;
}

.answer-box.active {
  display: block;
}

.tabs {
  position: fixed;
  left: max(10px, calc((100vw - 460px) / 2 + 10px));
  right: max(10px, calc((100vw - 460px) / 2 + 10px));
  bottom: 8px;
  z-index: 9;
  display: grid;
  grid-template-columns: repeat(6, minmax(54px, 1fr));
  gap: 3px;
  margin: 8px 0;
  overflow-x: auto;
  min-height: 66px;
  padding: 8px 6px;
  border: 0;
  border-radius: 5px;
  background: url("public/assets/ptva-bottom-nav.png") center / cover no-repeat;
  box-shadow: 0 10px 24px rgba(47, 58, 46, 0.16);
}

.tab {
  display: grid;
  gap: 2px;
  place-items: center;
  background: rgba(255, 250, 240, 0.2);
  color: #2f3a2e;
  min-height: 48px;
  min-width: 56px;
  padding: 5px 3px;
  font-size: 0.67rem;
  border-radius: 4px;
  text-shadow: 0 1px 0 rgba(255, 250, 240, 0.8);
}

.tab.active {
  background: #7f8a5a;
  color: white;
  border-radius: 4px;
  text-shadow: none;
  box-shadow: inset 0 0 0 1px rgba(255, 250, 240, 0.22);
}

.nav-icon {
  display: block;
  font-size: 1.12rem;
  line-height: 1;
}

.tab-panel {
  display: none;
  padding: 12px;
}

.tab-panel.active {
  display: block;
}

.section-head {
  display: block;
  margin-bottom: 8px;
}

.section-head > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.section-head p {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.2;
}

.compact-head {
  margin: 18px 0 10px;
}

.compact-head h2,
.focus-card h3,
.reward-bar h3 {
  margin: 0 0 4px;
  font-family: Impact, "Arial Narrow", Arial, sans-serif;
  font-weight: 500;
  text-transform: uppercase;
}

.focus-card,
.reward-bar {
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: linear-gradient(180deg, #fffaf0, #f8efd9);
  padding: 10px;
  margin-bottom: 8px;
}

.focus-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  column-gap: 12px;
}

.focus-card h3,
.focus-card p {
  margin-bottom: 0;
}

.focus-card p {
  color: var(--muted);
  font-size: 0.9rem;
}

.reward-meter {
  height: 10px;
  border-radius: 999px;
  background: #e4d7c0;
  overflow: hidden;
  margin-top: 8px;
}

.reward-meter span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.honor-help {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.3;
}

.badge-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.badge-card {
  position: relative;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  min-height: 42px;
  border: 1px solid #a59066;
  border-radius: 6px;
  background:
    linear-gradient(90deg, rgba(83, 100, 74, 0.12), transparent 40%),
    linear-gradient(180deg, #f7dec6, #ead4b6);
  padding: 6px;
  color: var(--ink);
  font-size: 0.78rem;
  box-shadow: inset 0 0 0 1px rgba(255, 250, 240, 0.55);
}

.badge-grid strong {
  display: block;
  text-transform: uppercase;
}

.badge-medal {
  display: grid;
  place-items: center;
  width: 28px;
  height: 34px;
  color: #fffaf0;
  background: linear-gradient(180deg, #c9b489, #7f8a5a 52%, #53644a);
  clip-path: polygon(50% 0, 92% 18%, 82% 88%, 50% 100%, 18% 88%, 8% 18%);
  box-shadow: inset 0 0 0 2px rgba(47, 58, 46, 0.22);
}

.badge-medal svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.badge-label {
  min-width: 0;
}

.badge-label em {
  display: block;
  color: var(--muted);
  font-style: normal;
}

.badge-label small {
  display: block;
  color: #53644a;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.badge-rank-command .badge-medal {
  background: linear-gradient(180deg, #f0d077, #b88d2c 52%, #53644a);
}

.badge-rank-first-sergeant .badge-medal {
  background: linear-gradient(180deg, #d7d1c1, #7f8a5a 52%, #2f3a2e);
}

.badge-rank-sergeant .badge-medal {
  background: linear-gradient(180deg, #c98b49, #a59066 52%, #53644a);
}

.badge-rank-specialist .badge-medal {
  background: linear-gradient(180deg, #d6c29d, #7f8a5a);
}

.chip-row {
  display: flex;
  gap: 8px;
  margin: 8px 0 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.doc-layout {
  display: grid;
  gap: 12px;
}

.category-panel {
  display: grid;
  gap: 10px;
  align-content: start;
}

.category-list {
  display: none;
  gap: 8px;
}

.category-list .chip {
  width: 100%;
  text-align: left;
  justify-content: start;
}

.chip {
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid var(--line);
  background: #f7dec6;
  color: var(--ink);
}

.chip.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.list {
  display: grid;
  gap: 8px;
}

.dashboard-grid {
  display: grid;
  gap: 8px;
}

.item {
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 10px;
  background: linear-gradient(180deg, #fffaf0, #f8efd9);
}

.dashboard-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fffaf0, #f8efd9);
  color: var(--ink);
  padding: 10px;
  text-align: left;
  text-transform: none;
}

.dashboard-card strong {
  display: block;
  font-family: Impact, "Arial Narrow", Arial, sans-serif;
  font-weight: 500;
  text-transform: uppercase;
  font-size: 1rem;
}

.dashboard-card small {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.82rem;
}

.card-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  font-size: 1.35rem;
}

.card-count {
  color: var(--primary-strong);
  font-family: Impact, "Arial Narrow", Arial, sans-serif;
  font-size: 1.55rem;
}

.item h3 {
  margin: 0 0 6px;
  font-size: 1rem;
  line-height: 1.25;
  font-family: Impact, "Arial Narrow", Arial, sans-serif;
  font-weight: 500;
  text-transform: uppercase;
}

.item-icon {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-right: 8px;
  border-radius: 6px;
  background: var(--primary);
  color: #fffaf0;
  vertical-align: middle;
}

.item-icon svg,
.nav-icon svg,
.card-icon svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.meta {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.star-button {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  width: 34px;
  min-height: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid #a59066;
  border-radius: 50%;
  background: #efe6d4;
  color: #53644a;
  font-size: 1.25rem;
  line-height: 1;
}

.star-button.active {
  background: #c9b489;
  color: #2f3a2e;
}

.doc-dialog {
  width: min(920px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}

.doc-dialog::backdrop {
  background: rgba(47, 58, 46, 0.42);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(70px 36px at 8% 20%, rgba(165, 144, 102, 0.62), transparent 68%),
    radial-gradient(120px 58px at 80% 12%, rgba(127, 138, 90, 0.45), transparent 70%),
    linear-gradient(135deg, #f7dec6, #f5f2e8);
}

.dialog-head h2,
.dialog-head p {
  margin: 0;
}

.doc-preview {
  min-height: 56vh;
  background: #f5f2e8;
}

.doc-preview iframe,
.doc-preview embed {
  width: 100%;
  height: 62vh;
  border: 0;
}

.doc-preview-message {
  padding: 20px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.secondary {
  background: #efe6d4;
  color: var(--ink);
}

.danger {
  background: var(--accent);
}

.entry-form,
.settings-grid,
.backup-actions,
.doc-tools {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.file-button {
  display: grid;
  place-items: center;
  min-height: 44px;
  border-radius: 5px;
  background: #efe6d4;
  color: var(--ink);
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-button {
  background: var(--primary);
  color: white;
}

.memo-form {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.contact-form {
  gap: 8px;
}

.research-shot {
  width: min(100%, 320px);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 8px;
}

.done h3 {
  color: var(--muted);
  text-decoration: line-through;
}

.privacy-note {
  margin-top: 12px;
  padding: 12px;
  border-left: 5px solid var(--gold);
}

@media (min-width: 1200px) {
  .app-shell {
    padding-top: 14px;
  }

  .section-head {
    grid-template-columns: minmax(0, 1fr) 260px;
    align-items: end;
  }

  .doc-tools {
    grid-template-columns: 104px minmax(0, 1fr);
    margin-bottom: 0;
  }

  .entry-form {
    grid-template-columns: minmax(0, 1.5fr) 170px auto;
  }

  .appointment-form {
    grid-template-columns: minmax(0, 1.4fr) 155px 120px minmax(0, 1fr) auto;
  }

  .contact-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .contact-form button,
  .contact-form input:first-child,
  .contact-form input:nth-child(4),
  .contact-form input:nth-child(5) {
    grid-column: 1 / -1;
  }

  .settings-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
    align-items: end;
  }

  .backup-actions {
    grid-template-columns: repeat(2, minmax(0, 190px));
  }
}
