:root {
  --bg: #0f1419;
  --surface: #161d24;
  --surface-2: #1e2730;
  --border: #2a3642;
  --text: #eef2f6;
  --muted: #93a1b0;
  --amber: #f59e0b;
  --amber-hover: #d97706;
  --green: #10b981;
  --red: #ef4444;
  --blue: #3b82f6;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  margin: 0;
  font-size: 0.875rem;
}

.muted-link {
  color: var(--amber);
  font-size: 0.85rem;
  text-decoration: none;
}

.muted-link:hover {
  text-decoration: underline;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-row h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.brand-badge {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--amber);
  color: #111;
  font-weight: 800;
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.auth-form {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

label {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
}

input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  color: var(--text);
  font-size: 0.95rem;
}

input:focus {
  outline: 2px solid var(--amber);
  outline-offset: -1px;
}

.input-group {
  display: flex;
  gap: 0.5rem;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 0.95rem;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s ease, opacity 0.15s ease;
}

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

.btn-primary {
  background: var(--amber);
  color: #111;
}

.btn-primary:hover:not(:disabled) {
  background: var(--amber-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #283440;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
}

.full-width {
  width: 100%;
}

.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
}

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.kpi-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.text-green { color: var(--green); }
.text-amber { color: var(--amber); }
.text-red { color: var(--red); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.search-input {
  max-width: 280px;
}

.add-form {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.add-form > div {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-grow { flex: 1 1 320px; }
.field-sm { width: 150px; }
.field-xs { width: 110px; }
.field-btn { flex-shrink: 0; }

.feedback-text, .error-text {
  margin: 0.65rem 0 0;
  font-size: 0.86rem;
}

.error-text { color: #fca5a5; }
.feedback-text { color: var(--amber); }

.products-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.product-card {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 1rem;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}

.product-thumb {
  width: 72px;
  height: 72px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  padding: 4px;
}

.product-thumb-placeholder {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px dashed var(--border);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.75rem;
}

.product-info {
  min-width: 0;
}

.product-title {
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  display: block;
  margin-bottom: 0.25rem;
  word-break: break-word;
}

.product-title:hover {
  color: var(--amber);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-green { background: rgba(16, 185, 129, 0.16); color: #6ee7b7; }
.badge-red { background: rgba(239, 68, 68, 0.16); color: #fca5a5; }
.badge-amber { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
.badge-muted { background: rgba(147, 161, 176, 0.16); color: var(--muted); }

.product-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

.price-block {
  text-align: right;
}

.price-current {
  font-size: 1.3rem;
  font-weight: 700;
}

.price-orig {
  font-size: 0.82rem;
  color: var(--muted);
  text-decoration: line-through;
  margin-left: 0.35rem;
}

.product-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.product-actions button {
  padding: 0.38rem 0.65rem;
  font-size: 0.8rem;
}

.product-error {
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: #fca5a5;
}

.modal {
  border: none;
  padding: 0;
  background: transparent;
  color: var(--text);
  max-width: 780px;
  width: calc(100% - 2rem);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-sm {
  max-width: 520px;
  margin: 0 auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.modal-header h3 {
  margin: 0;
}

.chart-box {
  height: 240px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}

.modal-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.sub-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem;
}

.sub-form h4 {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
}

.row-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.history-table-wrap {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.history-table th, .history-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.history-table th {
  background: var(--surface-2);
  color: var(--muted);
  position: sticky;
  top: 0;
}

.small-note {
  font-size: 0.84rem;
}

@media (max-width: 780px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .product-card {
    grid-template-columns: 56px 1fr;
  }
  .product-thumb, .product-thumb-placeholder {
    width: 56px;
    height: 56px;
  }
  .product-right {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 100%;
  }
  .price-block {
    text-align: left;
  }
  .modal-split {
    grid-template-columns: 1fr;
  }
}
