* {
  box-sizing: border-box;
}

:root {
  --ink: #243041;
  --muted: #667085;
  --line: #d8dee8;
  --panel: #ffffff;
  --page: #f4f6f8;
  --soft: #eef3f8;
  --primary: #145c8f;
  --primary-dark: #0d436c;
  --accent: #8a5a13;
  --danger: #b42318;
  --success: #067647;
}

body {
  margin: 0;
  font-family: Arial, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--page);
  font-size: 16px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  background:
    linear-gradient(120deg, rgba(20, 92, 143, .11), rgba(138, 90, 19, .10)),
    #eef2f6;
}

.login-card {
  width: min(470px, 94vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 16px 42px rgba(36, 48, 65, .12);
}

.brand-mark {
  width: fit-content;
  padding: 7px 10px;
  margin-bottom: 16px;
  color: #fff;
  background: var(--primary);
  border-radius: 4px;
  font-size: .84rem;
  font-weight: 700;
  letter-spacing: 0;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 1.8rem;
}

.muted {
  color: var(--muted);
  margin: 0 0 18px;
}

label {
  display: grid;
  gap: 6px;
  margin: 11px 0;
  color: #39465a;
  font-size: .92rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cbd3df;
  border-radius: 6px;
}

textarea {
  resize: vertical;
}

.login-card button,
.primary-btn {
  min-height: 42px;
  width: 100%;
  padding: 10px 14px;
  color: #fff;
  background: var(--primary);
  border-radius: 6px;
  font-weight: 700;
}

.login-card button:hover,
.primary-btn:hover {
  background: var(--primary-dark);
}

.secondary-btn,
.ghost-btn {
  color: var(--primary);
  background: #eaf3fb;
}

.config-panel {
  margin: 18px 0;
  padding: 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.section-title {
  margin-bottom: 8px;
  color: #182230;
  font-weight: 800;
}

.message {
  min-height: 22px;
  margin-top: 14px;
  color: var(--danger);
  font-size: .92rem;
}

.message.success {
  color: var(--success);
}

.app {
  min-height: 100vh;
}

.topbar {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(36, 48, 65, .04);
}

.leftnav,
.rightnav {
  display: flex;
  align-items: center;
}

.leftnav {
  gap: 2px;
}

.navitem {
  position: relative;
}

.navbutton {
  min-height: 60px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  color: #41506a;
  background: transparent;
  white-space: nowrap;
  font-weight: 700;
}

.navbutton:hover,
.navitem:focus-within .navbutton,
.navitem.active .navbutton {
  background: var(--soft);
  color: var(--primary-dark);
}

.home-button {
  font-size: 1.22rem;
}

.caret {
  margin-left: 1px;
  color: #667085;
  font-size: .7rem;
}

.dropdown {
  position: absolute;
  top: 60px;
  left: 0;
  min-width: 290px;
  padding: 6px;
  display: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0 0 10px 10px;
  box-shadow: 0 12px 24px rgba(36, 48, 65, .12);
  z-index: 20;
}

.navgroup-code {
  display: inline-grid;
  min-width: 31px;
  height: 23px;
  place-items: center;
  color: var(--primary-dark);
  background: #e5f0f8;
  border: 1px solid #c7ddec;
  border-radius: 5px;
  font-size: .68rem;
  letter-spacing: .02em;
}

.menu-count {
  display: inline-grid;
  min-width: 20px;
  height: 20px;
  margin-left: 1px;
  padding: 0 4px;
  place-items: center;
  color: var(--primary-dark);
  background: #f1f6fa;
  border-radius: 10px;
  font-size: .7rem;
}

.dropdown-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 9px 8px;
  color: var(--primary-dark);
  border-bottom: 1px solid #edf1f5;
  font-size: .82rem;
}

.dropdown-head span {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 400;
}

.navitem:hover .dropdown,
.navitem:focus-within .dropdown {
  display: block;
}

.dropitem {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 9px;
  color: #36435a;
  background: #fff;
  border-radius: 6px;
  text-align: left;
}

.dropitem:hover {
  background: #f4f7fb;
}

.dropitem.active {
  color: var(--primary-dark);
  background: #eaf3fb;
  font-weight: 800;
}

.dropitem-mark {
  color: var(--primary);
  font-size: 1.1rem;
  line-height: 1;
}

.dropitem:disabled {
  color: #98a2b3;
  background: #fafafa;
}

.rightnav {
  gap: 14px;
  margin-left: auto;
  white-space: nowrap;
  font-size: .9rem;
}

.branch {
  color: var(--primary);
  font-weight: 800;
}

.userlabel {
  color: var(--muted);
}

.logout {
  padding: 8px 10px;
  color: #7a271a;
  background: #fff4ed;
  border-radius: 6px;
  font-weight: 700;
}

.workspace {
  min-height: calc(100vh - 60px);
}

.page {
  padding: 24px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.page h1 {
  margin: 0;
  color: #172033;
  font-size: 1.55rem;
}

.page-description {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: .94rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 10px;
  color: var(--primary);
  background: #e9f4fb;
  border: 1px solid #c8e2f3;
  border-radius: 6px;
  font-size: .86rem;
  font-weight: 800;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

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

.panel,
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.card h3,
.panel h2 {
  margin: 0 0 10px;
  color: #202b3d;
  font-size: 1rem;
}

.card p,
.card li,
.panel p {
  color: #5e6b7f;
  line-height: 1.55;
  font-size: .92rem;
}

.metric {
  font-size: 1.8rem;
  font-weight: 800;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 12px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid #edf1f5;
  text-align: left;
  vertical-align: top;
  font-size: .9rem;
}

th {
  color: #344054;
  background: #f8fafc;
  font-weight: 800;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.form-actions button {
  width: auto;
  min-width: 120px;
}

.purchase-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.workflow-label {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 12px;
}

.workflow-label > span {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #145c8f;
  color: #fff;
  font-weight: 800;
}

.workflow-label h2 {
  margin: 0;
  font-size: 1rem;
}

.workflow-label p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: .88rem;
}

.purchase-metric {
  min-height: 108px;
  padding: 16px;
  border: 1px solid var(--line);
  border-top: 3px solid #1d7a8c;
  border-radius: 6px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.purchase-metric span,
.purchase-metric small,
.purchase-lines-heading p,
.list-heading p {
  color: var(--muted);
}

.purchase-metric strong {
  font-size: 1.45rem;
  color: var(--ink);
}

.purchase-lines-heading,
.list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 20px 0 10px;
}

.purchase-lines-heading h2,
.list-heading h2 {
  margin: 0;
  font-size: 1rem;
}

.purchase-lines-heading p,
.list-heading p {
  margin: 4px 0 0;
  font-size: .88rem;
}

.compact-btn,
.table-action {
  width: auto;
  min-height: 36px;
  padding: 7px 12px;
}

.purchase-lines-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.purchase-lines-table {
  min-width: 820px;
}

.purchase-lines-table input,
.purchase-lines-table select {
  min-width: 100px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px;
  background: #fff;
}

.purchase-lines-table .purchase-product {
  min-width: 250px;
}

.purchase-lines-table .line-total,
.amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.purchase-totals {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 18px;
  padding-top: 14px;
  color: var(--muted);
}

.purchase-totals strong {
  color: var(--ink);
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
}

.purchase-totals .grand-total {
  color: var(--ink);
  font-weight: 700;
}

.purchase-totals .grand-total strong {
  font-size: 1.1rem;
}

.purchase-list {
  margin-top: 18px;
}

.status-chip {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-draft { background: #fff1c2; color: #7a5200; }
.status-approved { background: #dceff5; color: #145c73; }
.status-closed { background: #dff3e6; color: #17633e; }
.status-cancelled { background: #f9e0e2; color: #922b3a; }

.icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid #e2bac0;
  border-radius: 4px;
  background: #fff;
  color: #9a2334;
  font-size: 1.2rem;
  line-height: 1;
}

.icon-btn:hover { background: #fff1f2; }

.notice {
  padding: 13px 14px;
  color: #63400e;
  background: #fff8e6;
  border: 1px solid #f2d58b;
  border-radius: 8px;
}

.empty {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.loading {
  color: var(--muted);
}

.error-text {
  color: var(--danger);
}

@media (max-width: 1220px) {
  .topbar {
    align-items: stretch;
    overflow-x: auto;
  }

  .rightnav {
    position: sticky;
    right: 0;
    padding-left: 12px;
    background: #fff;
  }
}

@media (max-width: 900px) {
  .grid,
  .grid.two,
  .form-grid,
  .purchase-summary {
    grid-template-columns: 1fr;
  }

  .purchase-lines-heading,
  .list-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .purchase-totals {
    justify-content: flex-start;
  }

  .page-header {
    display: block;
  }

  .status-pill {
    margin-top: 10px;
  }
}

@media (max-width: 640px) {
  .login-card {
    padding: 22px;
  }

  .page {
    padding: 16px;
  }

  .rightnav {
    gap: 8px;
    font-size: .82rem;
  }
}
