:root {
  --green-dark: #1b5e3b;
  --green-mid: #2e7d52;
  --green-light: #d4ecd9;
  --green-row: #e8f5e9;
  --text: #1a1a1a;
  --border: #b8d4be;
  --bg: #f4f7f5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

[hidden] {
  display: none !important;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 20px;
  background: #fff;
  border-bottom: 2px solid var(--green-dark);
  position: sticky;
  top: 0;
  z-index: 20;
}

.toolbar-no-capture {
  justify-content: flex-end;
}

.toolbar-app {
  align-items: center;
  gap: 10px 14px;
  justify-content: flex-end;
}

.toolbar-actions-top {
  flex: 0 1 auto;
  justify-content: flex-end;
}

.toolbar-nav,
.toolbar-user {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.btn-nav.is-active {
  background: var(--green-dark);
  color: #fff;
  border-color: var(--green-dark);
}

.user-badge {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 8px 12px;
  background: var(--green-row);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--green-dark);
  font-weight: 600;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 34, 24, 0.36);
}

.auth-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 14px 40px rgba(27, 94, 59, 0.12);
  position: relative;
  z-index: 1;
}

.auth-dialog {
  max-width: 460px;
}

.auth-card-head h1,
.panel-card h2 {
  margin: 0;
  color: var(--green-dark);
}

.auth-card-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.auth-card-head p,
.auth-hint {
  margin: 8px 0 0;
  color: #5d6c63;
}

.auth-form,
.stack-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.auth-form label,
.stack-form label {
  display: grid;
  gap: 6px;
}

.auth-form span,
.stack-form span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--green-dark);
}

.auth-form input,
.stack-form input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}

.auth-form input:focus,
.stack-form input:focus {
  outline: none;
  border-color: var(--green-mid);
  box-shadow: 0 0 0 3px rgba(46, 125, 82, 0.12);
}

.btn-block {
  width: 100%;
}

.app-main {
  display: grid;
  gap: 16px;
}

.app-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 20px;
  color: #5f6e66;
  font-size: 0.85rem;
}

.app-footer strong {
  color: var(--green-dark);
}

.view-panel {
  display: block;
}

.panel-wrap,
.panel-inner-wrap {
  border-top: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
}

.panel-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 16px;
  background: #fff;
}

.pagination-label {
  min-width: 180px;
  text-align: center;
  color: #4f5f57;
}

.inline-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--green-dark);
  font-weight: 600;
}

.inline-control select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
  color: var(--text);
}

.master-filter-row th {
  padding: 8px;
}

.col-check {
  width: 42px;
  text-align: center;
}

.master-table .col-check input {
  width: 16px;
  height: 16px;
}

.master-header-tools {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bulk-toolbar {
  display: grid;
  grid-template-columns: minmax(200px, 260px) minmax(200px, 260px) auto;
  gap: 10px;
  margin-top: 14px;
}

@media (max-width: 900px) {
  .bulk-toolbar {
    grid-template-columns: 1fr;
  }
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 16px;
}

.panel-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.panel-card-wide {
  min-width: 0;
}

.col-actions {
  width: 120px;
  text-align: center;
}

.list-table td:last-child,
.list-table th:last-child {
  text-align: left;
}

.report-header {
  padding: 12px 16px 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}

.report-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.report-header h1 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--green-dark);
}

.subtitle {
  margin: 4px 0 0;
  color: #555;
  font-size: 0.85rem;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid var(--green-mid);
  border-radius: 6px;
  background: #fff;
  color: var(--green-dark);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--green-row);
}

.btn-primary {
  background: var(--green-dark);
  color: #fff;
  border-color: var(--green-dark);
}

.btn-primary:hover {
  background: var(--green-mid);
}

.btn-danger {
  background: #8f2d24;
  color: #fff;
  border-color: #8f2d24;
}

.btn-danger:hover {
  background: #a73b31;
}

.main {
  padding: 16px;
  max-width: 100%;
  overflow-x: auto;
}

.table-wrap {
  background: #fff;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  overflow-x: auto;
  overflow-y: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

#captureArea {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  border-radius: 8px;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

.summary-table thead th {
  background: var(--green-dark);
  color: #fff;
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-right: 1px solid rgba(255, 255, 255, 0.15);
  position: sticky;
  top: 0;
  z-index: 5;
}

.summary-table thead .filter-row th {
  background: #edf6ef;
  color: var(--text);
  padding: 6px 8px;
  border-right: 1px solid var(--border);
  position: static;
}

.filter-dropdown {
  position: relative;
  width: 100%;
  min-width: 120px;
}

.filter-dropdown > input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.filter-dropdown > input:focus {
  outline: none;
  border-color: var(--green-mid);
  box-shadow: 0 0 0 2px rgba(46, 125, 82, 0.15);
}

.filter-options {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 4px 4px;
  max-height: 280px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.filter-dropdown > input:focus + .filter-options,
.filter-dropdown:focus-within .filter-options,
.filter-options.show {
  display: block;
}

.filter-option {
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  border-bottom: 1px solid rgba(184, 212, 190, 0.3);
}

.filter-option:hover {
  background: var(--green-light);
}

.filter-option input[type="checkbox"] {
  cursor: pointer;
  margin: 0;
  width: 14px;
  height: 14px;
}

.filter-option label {
  flex: 1;
  cursor: pointer;
  margin: 0;
}

.col-filter {
  width: 100%;
  min-width: 120px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
  background: #fff;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-filter:focus {
  outline: none;
  border-color: var(--green-mid);
  box-shadow: 0 0 0 2px rgba(46, 125, 82, 0.15);
}

.summary-table thead th:last-child {
  text-align: right;
}

.summary-table thead th.sortable {
  cursor: pointer;
  user-select: none;
}

.summary-table thead th.sortable:hover {
  background: #236b45;
}

.summary-table thead th.sort-asc,
.summary-table thead th.sort-desc {
  background: #165233;
}

.summary-table td {
  padding: 7px 12px;
  border-bottom: 1px solid #e0e0e0;
  vertical-align: middle;
  white-space: nowrap;
}

.summary-table th:nth-child(2),
.summary-table th:nth-child(3),
.summary-table th:nth-child(4),
.summary-table th:nth-child(5),
.summary-table td:nth-child(2),
.summary-table td:nth-child(3),
.summary-table td:nth-child(4),
.summary-table td:nth-child(5) {
  text-align: left;
}


.summary-table th:last-child,
.summary-table td:last-child {
  text-align: right;
}
.summary-table tbody tr:hover {
  background: #f9fcfa;
}

.col-total {
  text-align: right;
  font-weight: 600;
  width: 72px;
}

.grand-total td {
  background: var(--green-dark);
  color: #fff;
  font-weight: 700;
  border: none;
}

.row-group td {
  background: var(--green-row);
  font-weight: 600;
}

.row-level-0 td:first-child {
  background: var(--green-light);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  padding: 0;
  text-align: left;
  width: 100%;
  white-space: nowrap;
}

.toggle-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border: 1px solid var(--green-mid);
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  background: #fff;
  color: var(--green-dark);
}

.toggle.leaf .toggle-icon {
  visibility: hidden;
}

.indent-0 { padding-left: 12px !important; }
.indent-1 { padding-left: 28px !important; }
.indent-2 { padding-left: 44px !important; }
.indent-3 { padding-left: 60px !important; }
.indent-4 { padding-left: 76px !important; }

.cell-empty {
  color: transparent;
}

.row-leaf td {
  font-weight: 400;
}

.cell-input {
  width: 100%;
  min-width: 160px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  color: var(--text);
}

.cell-input:focus {
  outline: none;
  border-color: var(--green-mid);
  box-shadow: 0 0 0 3px rgba(46, 125, 82, 0.12);
}

.master-table td {
  white-space: normal;
}

.summary-table td.group-label-cell {
  vertical-align: top;
  padding-top: 7px;
}

.loading {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  z-index: 100;
}

.loading[hidden] {
  display: none !important;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  max-width: 360px;
  padding: 12px 16px;
  background: var(--green-dark);
  color: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  z-index: 101;
}

.toast.error {
  background: #b71c1c;
}

@media (max-width: 640px) {
  .toolbar {
    padding: 12px;
  }

  .toolbar h1 {
    font-size: 1rem;
  }

  .btn {
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  .main {
    padding: 8px;
  }

  .toolbar-actions-top {
    justify-content: flex-start;
  }

  .panel-grid {
    grid-template-columns: 1fr;
  }

  .panel-footer {
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .report-header-row {
    flex-direction: column;
    align-items: stretch;
  }
}
