/* ЭНПИК brand tokens — from the official brand guide (~/Projects/npeg-brand/DESIGN.md),
   not sampled from a sibling project. --brand-green = Primary/500, --brand-green-hover =
   Primary/700 (guide's own documented hover state), --graphite = Background/Black,
   --bg = Gray/50 (page background). */
:root {
  --brand-green: #1A8D3A;
  --brand-green-hover: #146B2C;
  --graphite: #202020;
  --bg: #FAFAFA;
}

body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--graphite);
  margin: 0;
  padding: 2rem;
}

header {
  background: var(--graphite);
  color: white;
  padding: 1rem 2rem;
  margin: -2rem -2rem 2rem;
}

.card {
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  max-width: 480px;
  margin: 0 auto;
}

button, .button {
  background: var(--brand-green);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  font-size: 1rem;
}

button:hover, .button:hover {
  background: var(--brand-green-hover);
}

input, select {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem;
  margin: 0.5rem 0 1rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #eee;
}

.uncategorized {
  color: #b45309;
}

.rule-label {
  display: block;
  white-space: nowrap;
  font-size: 0.9rem;
}

.rule-label input[type="checkbox"] {
  display: inline;
  width: auto;
  margin: 0 0.3rem 0 0;
}

.rule-keyword {
  min-width: 12rem;
}

.col-statya {
  min-width: 16rem;
}

#tx-table {
  font-size: 0.8rem;
}

#tx-table th, #tx-table td {
  padding: 0.35rem 0.5rem;
}

.cell-truncate {
  display: block;
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-select.invalid {
  border-color: #f05252;
}

.combobox {
  position: relative;
}

.combobox-list {
  position: absolute;
  z-index: 50;
  top: 100%;
  left: 0;
  right: 0;
  margin: 2px 0 0;
  padding: 4px 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  max-height: 200px;
  overflow-y: auto;
  list-style: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.combobox-list li {
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.9rem;
}

.combobox-list li:hover {
  background: var(--bg);
}

td small {
  display: block;
  color: #666;
  font-size: 0.75rem;
  max-width: 16rem;
}

.section-row td {
  font-weight: bold;
  background: var(--bg);
}

.subtotal-row td {
  font-weight: bold;
}

.total-row td {
  font-weight: bold;
  border-top: 2px solid var(--graphite);
}

.report-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.report-filters > div {
  display: flex;
  flex-direction: column;
}

.report-filters input,
.report-filters select {
  margin: 0;
}

#dds-drilldown {
  position: fixed;
  top: 5%;
  left: 50%;
  transform: translateX(-50%);
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
  z-index: 101;
}

#dds-drilldownClose {
  float: right;
}

#tx-editModal {
  position: fixed;
  top: 5%;
  left: 50%;
  transform: translateX(-50%);
  max-width: 480px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
  z-index: 101;
}

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

/* ── M6: ported component library from finance-app-archive, re-accented ── */

.app-header {
  background: var(--graphite);
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  margin: -2rem -2rem 0;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.app-header a#logout {
  margin-left: auto;
  color: #fff;
  text-decoration: none;
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 2px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 0 20px;
  position: sticky;
  top: 52px;
  z-index: 99;
  margin: 0 -2rem 2rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  padding: 12px 20px;
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 3px solid transparent;
  font-weight: 500;
  font-size: 14px;
  color: #6b7280;
  transition: 0.15s;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--brand-green);
  background: none;
}

.tab-btn.active {
  color: var(--brand-green);
  border-bottom-color: var(--brand-green);
}

.hidden {
  display: none !important;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 16px;
  min-width: 0;
}

.stat-label {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
}

.stat-value.green { color: #0e9f6e; }
.stat-value.red { color: #f05252; }
.stat-value.blue { color: var(--brand-green); }
.stat-value.orange { color: #ff8c00; }

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

.toolbar input,
.toolbar select {
  width: auto;
  margin: 0;
}

.btn {
  padding: 7px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.15s;
}

.btn-primary { background: var(--brand-green); color: #fff; }
.btn-primary:hover { background: var(--brand-green-hover); }
.btn-success { background: #0e9f6e; color: #fff; }
.btn-success:hover { background: #0c8a61; }
.btn-danger { background: #f05252; color: #fff; }
.btn-danger:hover { background: #dc3d3d; }
.btn-ghost { background: transparent; border: 1px solid #e5e7eb; color: var(--graphite); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
}

.amount-pos { color: #0e9f6e; font-weight: 600; }
.amount-neg { color: #f05252; font-weight: 600; }

.badge-checked { background: #d1fae5; color: #065f46; padding: 2px 7px; border-radius: 10px; font-size: 11px; }
.badge-auto { background: #fef3c7; color: #92400e; padding: 2px 7px; border-radius: 10px; font-size: 11px; }
.badge-unknown { background: #fee2e2; color: #991b1b; padding: 2px 7px; border-radius: 10px; font-size: 11px; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 8px;
  color: #fff;
  font-weight: 500;
  z-index: 9999;
  animation: slideIn 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.toast.success { background: #0e9f6e; }
.toast.error { background: #f05252; }

@keyframes slideIn {
  from { transform: translateX(100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(0, 0, 0, 0.15);
  border-top-color: var(--brand-green);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty {
  text-align: center;
  padding: 48px 20px;
  color: #6b7280;
}

@media (max-width: 640px) {
  .stats-row { grid-template-columns: 1fr 1fr; }
  .tab-btn { padding: 10px 12px; font-size: 13px; }
  table { font-size: 12px; }
}

.chart-text {
  font-size: 12px;
  fill: var(--graphite);
  font-family: inherit;
}
