/* ==================== V2 PREMIUM — DESIGN SYSTEM ==================== */
:root {
  --primary: #1a1a2e;
  --primary-light: #16213e;
  --accent: #0f3460;
  --accent-hover: #e94560;
  --bg-main: #f4f6f9;
  --bg-card: #ffffff;
  --text-dark: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e2e5ea;
  --border-light: #f0f1f3;
  --shadow: rgba(0, 0, 0, .06);
  --shadow-lg: rgba(0, 0, 0, .12);
  --danger: #dc3545;
  --success: #28a745;
  --warning: #f59e0b;
}

/* ==================== THEMES ==================== */
.theme-contrast {
  --primary: #1a1a1a;
  --primary-light: #2d2d2d;
  --accent: #e67e22;
  --accent-hover: #d35400;
  --bg-main: #121212;
  --bg-card: #1e1e1e;
  --text-dark: #f0f0f0;
  --text-muted: #888;
  --border: #333;
  --border-light: #2a2a2a;
  --shadow: rgba(0, 0, 0, .3);
  --shadow-lg: rgba(0, 0, 0, .5);
}

.theme-solid {
  --primary: #2c3e50;
  --primary-light: #34495e;
  --accent: #2ecc71;
  --accent-hover: #27ae60;
  --bg-main: #ecf0f1;
  --bg-card: #ffffff;
  --text-dark: #2c3e50;
  --text-muted: #7f8c8d;
  --border: #bdc3c7;
  --border-light: #dfe6e9;
  --shadow: rgba(0, 0, 0, .08);
  --shadow-lg: rgba(0, 0, 0, .15);
}

.theme-fun {
  --primary: #6c5ce7;
  --primary-light: #a29bfe;
  --accent: #fd79a8;
  --accent-hover: #e84393;
  --bg-main: #ffeef8;
  --bg-card: #ffffff;
  --text-dark: #2d3436;
  --text-muted: #b2bec3;
  --border: #dfe6e9;
  --border-light: #f8e8f0;
  --shadow: rgba(108, 92, 231, .08);
  --shadow-lg: rgba(253, 121, 168, .15);
}

/* ==================== RESET ==================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-main);
  color: var(--text-dark);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

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

/* ==================== ONBOARDING ==================== */
.onboarding {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-main);
  padding: 20px;
}

.onboarding-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 48px 40px;
  max-width: 460px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px var(--shadow-lg);
}

.onboarding-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
  font-size: 28px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.onboarding-card h1 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.onboarding-card>p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ==================== NAVBAR ==================== */
.navbar {
  background: var(--primary);
  color: white;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  height: 56px;
}

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

.brand-icon {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
}

.brand-text {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.5px;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.theme-select {
  background: var(--primary-light);
  color: white;
  border: 1px solid rgba(255, 255, 255, .15);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
}

.nav-stats {
  display: flex;
  gap: 20px;
}

.nav-stat {
  text-align: right;
}

.nav-stat-label {
  display: block;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.6;
}

.nav-stat-value {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
}

/* ==================== TABS ==================== */
.tabs-container {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 56px;
  z-index: 90;
}

.tabs {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  overflow-x: auto;
}

.tab-btn {
  padding: 14px 20px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s;
}

.tab-btn:hover {
  color: var(--text-dark);
}

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

/* ==================== MAIN CONTENT ==================== */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.section-title {
  font-size: 1.2rem;
  font-weight: 700;
}

/* ==================== DASHBOARD ==================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.dash-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px var(--shadow);
  transition: transform .2s;
}

.dash-card:hover {
  transform: translateY(-2px);
}

.dc-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.dc-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent);
}

.dc-danger {
  color: var(--danger);
}

/* ==================== TOOLBAR ==================== */
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
}

.search-input {
  width: 100%;
  padding: 12px 12px 12px 40px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--bg-card);
  color: var(--text-dark);
  transition: border .2s;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.filter-select {
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--bg-card);
  color: var(--text-dark);
  cursor: pointer;
}

/* ==================== TABLE ==================== */
.table-wrapper {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: 0 1px 3px var(--shadow);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 14px 16px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.9rem;
}

.data-table tr:hover {
  background: var(--border-light);
}

.item-preview {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
}

/* ==================== BADGES ==================== */
.status-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.status-paid {
  background: rgba(40, 167, 69, .12);
  color: var(--success);
}

.status-pending {
  background: rgba(245, 158, 11, .12);
  color: var(--warning);
}

.status-partial {
  background: rgba(15, 52, 96, .12);
  color: var(--accent);
}

.badge-type {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.6rem;
  font-weight: 700;
  background: rgba(108, 92, 231, .1);
  color: #6c5ce7;
  margin-left: 6px;
}

.badge-overdue {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.6rem;
  font-weight: 700;
  background: rgba(220, 53, 69, .1);
  color: var(--danger);
  margin-left: 4px;
}

/* ==================== LOADING / PAGINATION ==================== */
.loading-row {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-style: italic;
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
}

/* ==================== BUTTONS ==================== */
.btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .2s;
}

.btn-outline {
  background: var(--bg-card);
  border: 2px solid var(--border);
  color: var(--text-dark);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger {
  background: rgba(220, 53, 69, .1);
  color: var(--danger);
  border: 2px solid transparent;
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .2s;
  color: var(--text-dark);
}

.btn-icon:hover {
  background: var(--border-light);
  color: var(--accent);
}

.submit-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}

.submit-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--shadow-lg);
}

/* ==================== FORMS ==================== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--bg-card);
  color: var(--text-dark);
  transition: border .2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
}

.item-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.grand-total {
  text-align: right;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 12px;
  padding-top: 12px;
  border-top: 2px solid var(--border);
}

/* ==================== MODALS ==================== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, .5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 28px;
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px var(--shadow-lg);
  animation: modalIn .25s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
}

.modal-close:hover {
  background: var(--border-light);
}

/* ==================== DETAIL MODAL ==================== */
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}

.detail-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.detail-value {
  font-weight: 600;
}

.detail-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

.detail-items-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px;
  border-bottom: 2px solid var(--border);
  text-align: left;
}

.detail-items-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.85rem;
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 2px solid var(--border);
}

/* ==================== LEDGER ==================== */
.ledger-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--border-light);
  margin-top: 6px;
  overflow: hidden;
}

.ledger-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.3s ease;
}

/* ==================== SETTINGS ==================== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.setting-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px var(--shadow);
}

.setting-card h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 16px;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}

.toggle-row:last-child {
  border-bottom: none;
}

.toggle-label {
  font-size: 0.85rem;
  color: var(--text-dark);
}

.toggle-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--border);
  border-radius: 24px;
  transition: 0.3s;
}

.toggle-slider:before {
  position: absolute;
  content: '';
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}

.toggle-switch input:checked+.toggle-slider {
  background: var(--accent);
}

.toggle-switch input:checked+.toggle-slider:before {
  transform: translateX(20px);
}

/* ==================== PRINT ==================== */
#printArea {
  display: none;
}

@media print {

  .navbar,
  .tabs-container,
  .main-content,
  .modal-overlay,
  .dashboard-grid,
  .onboarding,
  #appMain>* {
    display: none !important;
  }

  body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  #printArea {
    display: block !important;
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    padding: 40px !important;
    background: #fff !important;
    font-family: 'Cambria', Georgia, serif !important;
    font-size: 12pt !important;
    color: #000 !important;
    z-index: 999999 !important;
  }

  #printArea table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
  }

  #printArea th,
  #printArea td {
    border: 1px solid #ddd;
    padding: 8px 12px;
    text-align: left;
  }

  #printArea th {
    background: #f5f5f5;
    font-weight: 700;
  }

  #printArea .print-header {
    text-align: center;
    margin-bottom: 24px;
    border-bottom: 2px solid #333;
    padding-bottom: 16px;
  }

  #printArea .print-header h1 {
    font-size: 18pt;
    margin: 0;
  }

  #printArea .print-header p {
    font-size: 10pt;
    color: #666;
    margin: 4px 0 0;
  }

  #printArea .print-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
  }

  #printArea .print-total {
    text-align: right;
    font-size: 14pt;
    font-weight: 700;
    margin-top: 16px;
    border-top: 2px solid #333;
    padding-top: 12px;
  }

  #printArea .print-footer {
    text-align: center;
    margin-top: 40px;
    font-size: 8pt;
    color: #999;
    border-top: 1px solid #ddd;
    padding-top: 12px;
  }
}

/* ==================== TOAST ==================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--primary);
  color: white;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  pointer-events: auto;
  animation: toastIn .3s ease, toastOut .4s ease 2.5s forwards;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.toast-success {
  background: var(--success);
}

.toast.toast-error {
  background: var(--danger);
}

.toast.toast-loading {
  background: var(--accent);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* ==================== RECIPE / HPP ==================== */
.recipe-section {
  border: 2px solid var(--border);
  border-radius: 12px;
  margin-top: 16px;
  overflow: hidden;
}

.recipe-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-dark);
  background: var(--border-light);
  transition: background .2s;
}

.recipe-header:hover {
  background: var(--border);
}

.recipe-toggle-icon {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

.recipe-content {
  padding: 16px;
}

.recipe-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1.5fr auto;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.recipe-row .form-input {
  padding: 8px 10px;
  font-size: 0.8rem;
}

.hpp-summary {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
  border-radius: 10px;
  padding: 16px;
  margin-top: 16px;
}

.hpp-summary .hpp-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.85rem;
}

.hpp-summary .hpp-total {
  display: flex;
  justify-content: space-between;
  padding: 8px 0 0;
  margin-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, .3);
  font-size: 1rem;
  font-weight: 700;
}

/* ==================== ANALISA ==================== */
.analisa-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.analisa-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px var(--shadow);
}

.analisa-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--primary);
}

.margin-positive {
  color: var(--success);
  font-weight: 700;
}

.margin-negative {
  color: var(--danger);
  font-weight: 700;
}

.bep-result {
  background: var(--border-light);
  border-radius: 10px;
  padding: 16px;
  margin-top: 8px;
}

.bep-result .bep-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.bep-result .bep-row:last-child {
  border-bottom: none;
}

.bep-result .bep-explanation {
  margin-top: 12px;
  padding: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 900px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .nav-stats {
    display: none;
  }

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

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

@media (max-width: 600px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    flex-direction: column;
  }

  .search-box {
    min-width: 100%;
  }

  .data-table th:nth-child(3),
  .data-table td:nth-child(3) {
    display: none;
  }

  .detail-actions .btn {
    min-width: auto;
  }

  .onboarding-card {
    padding: 32px 24px;
  }
}