*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242836;
  --border: #2e3348;
  --text: #e8eaef;
  --text-muted: #8b92a8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --accent: #22c55e;
  --accent-bg: rgba(34, 197, 94, 0.12);
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.user-badge {
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.btn-logout {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: all 0.2s;
}

.btn-logout:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.08);
}

/* Login page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.login-wrap {
  width: 100%;
  max-width: 400px;
}

.login-card {
  padding: 2rem;
}

.login-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-brand .logo-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.5rem;
}

.login-brand h1 {
  font-size: 1.35rem;
  margin-bottom: 0.25rem;
}

.login-brand p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-form .btn-primary {
  margin-top: 0.5rem;
}

.login-error {
  margin-bottom: 1rem;
  text-align: center;
  font-size: 0.88rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  font-size: 2rem;
}

.logo h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.logo p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tabs {
  display: flex;
  gap: 0.5rem;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 10px;
}

.tab-btn {
  padding: 0.5rem 1.25rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  background: var(--primary);
  color: white;
}

/* Main */
.main {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.layout-2col {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .layout-2col {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1.1rem;
  margin-bottom: 0;
  font-weight: 600;
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.card-header-row.compact {
  margin-bottom: 1rem;
}

.result-heading {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.btn-refresh {
  padding: 0.4rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.btn-refresh:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(99, 102, 241, 0.08);
}

.btn-refresh:active {
  transform: scale(0.97);
}

.toast.refresh-toast {
  background: var(--primary);
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.login-form input[type="text"],
.login-form input[type="password"] {
  display: block;
  width: 100%;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
}

.checkbox-group {
  background: var(--surface-2);
  padding: 0.85rem;
  border-radius: 8px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
}

.checkbox-group small {
  display: block;
  margin-top: 0.4rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.price-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.price-tag {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  transition: all 0.15s;
}

.price-tag.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary);
  color: var(--text);
  font-weight: 600;
}

.auto-update-note {
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

.partial-hint {
  padding: 1rem 0 0;
  text-align: center;
}

/* Buttons */
.btn {
  padding: 0.7rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
  width: 100%;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.btn-outline:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.btn-sm {
  padding: 0.4rem 0.85rem;
  font-size: 0.82rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}

.btn-sm:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-block {
  width: 100%;
  margin-bottom: 0.5rem;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.btn-icon:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* Results */
.results-side {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.hint {
  color: var(--text-muted);
  text-align: center;
  padding: 2rem;
}

.error-box {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid var(--danger);
  color: #fca5a5;
  padding: 1rem;
  border-radius: 8px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.result-card {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.result-card.highlight {
  border: 1px solid var(--primary);
  background: rgba(99, 102, 241, 0.08);
}

.result-card.accent {
  border: 1px solid var(--accent);
  background: var(--accent-bg);
}

.result-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.result-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.result-value.big {
  font-size: 2rem;
  color: var(--primary);
}

.result-card.accent .result-value.big {
  color: var(--accent);
}

.result-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.detail-box,
.comparison-box {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.detail-box h3,
.comparison-box h3 {
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
}

.detail-table {
  width: 100%;
  font-size: 0.88rem;
}

.detail-table td {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.detail-table td:first-child {
  color: var(--text-muted);
  width: 45%;
}

.compare-row {
  display: flex;
  gap: 1rem;
}

.compare-item {
  flex: 1;
  background: var(--surface-2);
  padding: 0.85rem;
  border-radius: 8px;
  text-align: center;
  border: 1px solid transparent;
}

.compare-item.winner {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.compare-item strong {
  display: block;
  margin-bottom: 0.25rem;
}

.compare-item span {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.compare-waste {
  display: block;
  font-size: 0.75rem !important;
  margin-top: 0.2rem;
}

.compare-note {
  margin-top: 0.75rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.field-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Grid Preview */
.preview-card h3 {
  font-size: 0.9rem;
  margin-bottom: 1rem;
  color: var(--text-muted);
}

.preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sheet-canvas {
  background: #2a2f42;
  border: 2px solid var(--border);
  border-radius: 4px;
  display: grid;
  overflow: hidden;
}

.grid-cell {
  border: 1px solid rgba(99, 102, 241, 0.4);
  background: rgba(99, 102, 241, 0.2);
  box-sizing: border-box;
}

.preview-note {
  margin-top: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}

/* Admin */
.admin-header {
  margin-bottom: 1.5rem;
}

.admin-header h2 {
  font-size: 1.25rem;
}

.admin-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.admin-section.full-width {
  grid-column: 1 / -1;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.admin-section h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
}

.section-header h3 {
  margin-bottom: 0;
}

.admin-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.admin-row input[type="text"] {
  flex: 1;
  min-width: 120px;
}

.admin-row input[type="number"] {
  width: 70px;
}

.admin-row .unit {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.types-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.type-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.type-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.type-badge {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
  background: rgba(99, 102, 241, 0.12);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.type-actions {
  display: flex;
  gap: 0.15rem;
}

.type-actions .btn-icon:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.form-row-admin {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.form-row-admin label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.form-row-admin select,
.form-row-admin input[type="number"] {
  padding: 0.5rem 0.65rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
}

.offset-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.reference-pricing {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}

.tiers-preview {
  margin-top: 0.5rem;
}

.tier-preview-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.tier-preview-row:last-child {
  border-bottom: none;
}

.force-badge {
  font-size: 0.68rem;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  margin-left: auto;
}

.pricing-body {
  margin-top: 0.25rem;
}

.type-header {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.tier-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
  font-size: 0.82rem;
}

.tier-row label {
  color: var(--text-muted);
}

.tier-row input[type="number"] {
  width: 70px;
  padding: 0.4rem;
  font-size: 0.85rem;
}

.tier-row .checkbox-label {
  font-size: 0.78rem;
}

.admin-note {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
}

.actions-section {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--accent);
  color: white;
  padding: 0.85rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s;
  z-index: 200;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* Footer */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

@media (max-width: 700px) {
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }
}
