:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #eef3f2;
  --border: #d8dee7;
  --border-strong: #b6c0cc;
  --text: #24272d;
  --muted: #657181;
  --accent: #287b5f;
  --accent-dark: #1f604b;
  --danger: #9d2f26;
  --danger-bg: #fff1ee;
  --warning: #b26a00;
  --warning-bg: #fff5df;
  --shadow: 0 18px 42px rgba(32, 42, 54, 0.12);
  --overlay: rgba(245, 247, 250, 0.86);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Aptos, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

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

button {
  cursor: pointer;
  transform: translateY(0);
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease, border-color 140ms ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:not(:disabled):active {
  transform: translateY(1px) scale(0.98);
}

button.clicked {
  animation: button-pop 260ms ease;
}

@keyframes button-pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(0.96);
  }
  100% {
    transform: scale(1);
  }
}

.ems-shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

.ems-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 22px;
  padding: 22px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 62px;
  height: 62px;
  place-items: center;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(20, 28, 36, 0.08);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 2px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.eyebrow,
.metric-grid span,
.auth-card p,
small {
  color: var(--muted);
  font-size: 12px;
}

.ems-nav {
  display: grid;
  gap: 6px;
}

.nav-item,
.taskflow-link {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 8px;
  text-align: left;
  text-decoration: none;
}

.nav-item.active,
.nav-item:hover,
.taskflow-link:hover {
  background: var(--surface-soft);
  font-weight: 700;
}

.taskflow-link {
  margin-top: auto;
  border: 1px solid var(--border);
}

.ems-main {
  display: grid;
  align-content: start;
  gap: 18px;
  min-width: 0;
  padding: 24px;
}

.ems-topbar,
.metric-grid > div,
.panel,
.management-toolbar,
.data-table,
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(32, 42, 54, 0.04);
}

.ems-topbar,
.management-toolbar,
.panel-header,
.topbar-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ems-topbar,
.management-toolbar {
  padding: 16px;
}

.management-toolbar > div {
  display: grid;
  gap: 5px;
}

.management-toolbar strong {
  display: block;
  font-size: 16px;
}

.search-row {
  display: grid;
  margin: 16px 0;
}

.search-row input {
  width: 100%;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}

.search-row input:focus {
  outline: 2px solid rgba(40, 123, 95, 0.2);
  border-color: var(--accent);
}

.management-toolbar span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 36px);
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

.primary-button,
.secondary-button,
.google-button,
.icon-action {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-weight: 700;
  text-decoration: none;
}

.primary-button {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button,
.google-button,
.icon-action {
  color: var(--text);
  background: var(--surface);
}

.icon-action {
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  color: var(--muted);
}

.icon-action:hover {
  color: var(--text);
  background: var(--surface-soft);
  border-color: var(--border-strong);
}

.icon-action svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.success-action {
  color: var(--accent);
  background: #e7f6ee;
  border-color: #b9decf;
}

.success-action:hover {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.date-chip,
.user-chip {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  padding: 0 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.date-chip {
  color: var(--text);
  background: #e7f6ee;
  border-color: #b9decf;
  font-size: 13px;
  font-weight: 800;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.metric-grid > div {
  padding: 16px;
}

.metric-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

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

.panel {
  display: grid;
  gap: 12px;
  padding: 16px;
}

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

.stack-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.data-table {
  overflow-x: auto;
}

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.budget-lines-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
  table-layout: fixed;
}

.budget-lines-table th,
.budget-lines-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.budget-lines-table th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  text-align: left;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.budget-lines-table tbody tr:hover {
  background: rgba(40, 123, 95, 0.06);
}

.budget-lines-table input,
.budget-lines-table select {
  width: 100%;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 8px 10px;
  background: var(--surface);
}

.budget-lines-table .icon-action {
  min-width: auto;
  padding: 0;
}

.budget-lines-table th:nth-child(1),
.budget-lines-table td:nth-child(1) {
  width: 140px;
}

.budget-lines-table th:nth-child(3),
.budget-lines-table td:nth-child(3),
.budget-lines-table th:nth-child(5),
.budget-lines-table td:nth-child(5) {
  width: 100px;
}

.budget-lines-table th:nth-child(4),
.budget-lines-table td:nth-child(4),
.budget-lines-table th:nth-child(6),
.budget-lines-table td:nth-child(6) {
  width: 130px;
}

.budget-lines-table th:nth-child(7),
.budget-lines-table td:nth-child(7) {
  width: 110px;
}

.dialog-actions {
  flex-wrap: wrap;
}

.dialog-actions button {
  min-width: 150px;
}

.data-row {
  display: grid;
  gap: 12px;
  align-items: center;
  min-width: 940px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.data-row:first-child {
  border-top: 0;
}

.table-head {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.data-row strong,
.data-row small,
.stack-row strong,
.stack-row small {
  display: block;
}

.data-row select {
  min-height: 34px;
  padding: 6px 8px;
}

.pill {
  display: inline-flex;
  width: fit-content;
  min-height: 24px;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-Pending {
  color: var(--warning);
  background: var(--warning-bg);
}

.status-Approved {
  color: var(--accent);
  background: #e7f6ee;
}

.status-Active {
  color: var(--accent);
  background: #e7f6ee;
}

.status-Inactive {
  color: var(--muted);
  background: var(--surface-soft);
}

.status-Rejected {
  color: var(--danger);
  background: var(--danger-bg);
}

.empty-state {
  display: grid;
  gap: 4px;
  padding: 18px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
}

.row-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
}

.rate-thumb {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
}

img.rate-thumb,
.rate-thumb img {
  object-fit: cover;
}

img.rate-thumb {
  display: block;
}

.image-preview {
  display: flex;
  min-height: 54px;
  align-items: center;
  gap: 10px;
  padding: 10px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  font-size: 13px;
}

.image-preview img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
}

.audit-list {
  display: grid;
  max-height: min(60vh, 520px);
  gap: 10px;
  overflow-y: auto;
}

.audit-entry {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.audit-entry > div {
  display: grid;
  gap: 3px;
}

.audit-entry span,
.audit-entry p {
  color: var(--muted);
  font-size: 12px;
}

.audit-entry ul {
  display: grid;
  gap: 6px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.audit-entry li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.danger-action {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #efc7c1;
}

.danger-action:hover {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

dialog {
  width: min(640px, calc(100vw - 32px));
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(32, 42, 54, 0.38);
}

.dialog-form {
  display: grid;
  gap: 16px;
}

.dialog-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-transform: none;
}

textarea {
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.budget-summary,
.budget-total-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.budget-summary strong,
.budget-total-card strong {
  font-size: 1rem;
}

.detail-grid,
.budget-detail-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.detail-grid div,
.budget-detail-meta div {
  display: grid;
  gap: 6px;
}

.detail-grid strong,
.budget-detail-meta strong {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
}

.detail-grid span,
.budget-detail-meta span {
  color: var(--text);
}

.budget-detail-panel {
  gap: 18px;
  padding: 18px;
}

.budget-detail-heading,
.budget-line-toolbar,
.budget-detail-footer,
.budget-action-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.budget-detail-heading,
.budget-line-toolbar,
.budget-detail-footer {
  justify-content: space-between;
}

.budget-detail-heading {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.budget-detail-heading h2 {
  margin-top: 4px;
  font-size: 24px;
}

.budget-detail-meta {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 0;
}

.budget-detail-meta div {
  min-height: 78px;
  padding: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.budget-line-section {
  display: grid;
  gap: 12px;
}

.budget-line-toolbar {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.budget-line-toolbar span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.budget-lines-wrapper {
  max-width: 100%;
}

.budget-empty-lines {
  display: grid;
  min-height: 150px;
  place-content: center;
  gap: 6px;
  padding: 24px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  text-align: center;
}

.budget-empty-lines strong {
  color: var(--text);
}

.budget-detail-footer {
  position: sticky;
  bottom: 16px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(32, 42, 54, 0.09);
}

.budget-total-card {
  min-width: 240px;
}

.budget-action-group {
  justify-content: flex-end;
}

.auth-gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--overlay);
}

.auth-card {
  display: grid;
  width: min(420px, 100%);
  gap: 16px;
  padding: 24px;
}

.auth-message {
  min-height: 20px;
  color: var(--danger);
}

.toast-stack {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  display: grid;
  width: min(360px, calc(100vw - 32px));
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: grid;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: toast-in 220ms ease;
}

.toast strong,
.toast span {
  display: block;
}

.toast strong {
  font-size: 13px;
}

.toast span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.toast-success {
  border-left-color: var(--accent);
}

.toast-error {
  border-left-color: var(--danger);
}

.toast-info {
  border-left-color: #3867d6;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .ems-shell {
    display: block;
  }

  .ems-sidebar {
    position: static;
    height: auto;
  }

  .dashboard-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

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

  .budget-detail-footer {
    position: static;
    display: grid;
    grid-template-columns: 1fr;
  }

  .budget-total-card,
  .budget-action-group,
  .budget-detail-footer > button {
    width: 100%;
  }

  .budget-action-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 620px) {
  .ems-main {
    padding: 16px;
  }

  .ems-topbar,
  .management-toolbar,
  .panel-header {
    display: grid;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .budget-detail-heading,
  .budget-line-toolbar {
    display: grid;
    justify-items: start;
  }

  .budget-detail-meta,
  .budget-action-group {
    grid-template-columns: 1fr;
  }
}
