/* Margiqo — Design System */
:root {
  --primary-600: #EA580C;
  --primary-500: #F97316;
  --primary-400: #FB923C;
  --primary-100: #FFEDD5;

  --bg:          #07090D;
  --sidebar-bg:  #0B0E14;
  --card-bg:     #10141C;
  --surface:     #151A24;
  --border:      #222938;

  --text-primary:   #F8FAFC;
  --text-secondary: #94A3B8;

  --green:   #22C55E;
  --red:     #EF4444;
  --yellow:  #F59E0B;

  --sidebar-width: 240px;
  --topbar-height: 60px;
  --radius: 8px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary-500); text-decoration: none; }
a:hover { color: var(--primary-400); }

/* Layout */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo img {
  height: 28px;
  width: auto;
}

.sidebar-logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.sidebar-logo-text span {
  color: var(--primary-500);
}

.sidebar-nav {
  padding: 12px 0;
  flex: 1;
}

.sidebar-section-label {
  padding: 12px 20px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  text-decoration: none;
}

.sidebar-item:hover {
  background: rgba(234, 88, 12, 0.08);
  color: var(--text-primary);
}

.sidebar-item.active {
  background: rgba(234, 88, 12, 0.15);
  color: var(--primary-400);
  border-right: 2px solid var(--primary-500);
}

.sidebar-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.sidebar-bottom {
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

/* Main area */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Topbar */
.topbar {
  height: var(--topbar-height);
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Date range picker */
.date-range-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.date-range-btn:hover {
  border-color: var(--primary-500);
  background: rgba(234, 88, 12, 0.06);
}

.date-range-btn svg { width: 14px; height: 14px; color: var(--text-secondary); }

/* Content area */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--primary-600);
  opacity: 0;
  transition: opacity 0.2s;
}

.kpi-card:hover::before { opacity: 1; }

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.kpi-value.positive { color: var(--green); }
.kpi-value.negative { color: var(--red); }

.kpi-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  margin-top: 6px;
  padding: 2px 6px;
  border-radius: 4px;
}

.kpi-delta.up { color: var(--green); background: rgba(34,197,94,0.12); }
.kpi-delta.down { color: var(--red); background: rgba(239,68,68,0.12); }

/* Cards */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.card-body { padding: 20px; }

/* Tables */
.table-wrapper {
  overflow-x: auto;
}

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

thead th {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
}

thead th:first-child { border-radius: var(--radius) 0 0 0; }
thead th:last-child { border-radius: 0 var(--radius) 0 0; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.025); }

tbody td {
  padding: 12px 14px;
  font-size: 13.5px;
  color: var(--text-primary);
  vertical-align: middle;
}

.td-secondary { color: var(--text-secondary); font-size: 12px; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green  { background: rgba(34,197,94,0.12); color: var(--green); }
.badge-red    { background: rgba(239,68,68,0.12); color: var(--red); }
.badge-yellow { background: rgba(245,158,11,0.12); color: var(--yellow); }
.badge-blue   { background: rgba(234,88,12,0.12); color: var(--primary-400); }
.badge-gray   { background: rgba(148,163,184,0.12); color: var(--text-secondary); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
  line-height: 1;
}

.btn-primary {
  background: var(--primary-600);
  color: #fff;
  border-color: var(--primary-600);
}
.btn-primary:hover { background: var(--primary-500); color: #fff; }

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: rgba(255,255,255,0.05);
  border-color: var(--primary-500);
  color: var(--primary-400);
}

.btn-danger {
  background: rgba(239,68,68,0.12);
  color: var(--red);
  border-color: rgba(239,68,68,0.2);
}
.btn-danger:hover { background: rgba(239,68,68,0.2); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 14px; }

.btn svg { width: 14px; height: 14px; }

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

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.03em;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13.5px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.form-control:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(234,88,12,0.15);
}

.form-control::placeholder { color: rgba(148,163,184,0.5); }

select.form-control { cursor: pointer; }

.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.form-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary-500);
  cursor: pointer;
}

.form-text {
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(3px);
  padding: 16px;
}

.modal {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
}

.modal-body { padding: 20px; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* Charts */
.chart-container {
  position: relative;
  height: 220px;
}

/* Search */
.search-input-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.search-input-wrap svg {
  position: absolute;
  left: 10px;
  width: 14px;
  height: 14px;
  color: var(--text-secondary);
  pointer-events: none;
}

.search-input {
  padding-left: 32px;
  min-width: 220px;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.pagination-info {
  font-size: 12px;
  color: var(--text-secondary);
}

.pagination-btns {
  display: flex;
  gap: 4px;
}

.page-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.page-btn:hover, .page-btn.active {
  border-color: var(--primary-500);
  color: var(--primary-400);
  background: rgba(234,88,12,0.1);
}

/* Product cell */
.product-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}

.product-thumb {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.product-thumb-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
  font-size: 16px;
}

.product-name { font-weight: 500; font-size: 13.5px; }
.product-meta { font-size: 11.5px; color: var(--text-secondary); margin-top: 1px; }

/* Currency amount */
.amount-primary { font-weight: 600; }
.amount-secondary { font-size: 11.5px; color: var(--text-secondary); }

/* Status badge dot */
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
}

/* Sync status */
.sync-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.sync-status:last-child { border-bottom: none; }

/* File upload */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--primary-500);
  background: rgba(234,88,12,0.04);
}

/* Progress bar */
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary-600);
  border-radius: 3px;
  transition: width 0.3s;
}

/* Alert */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
}

.alert-info    { background: rgba(234,88,12,0.1); color: var(--primary-400); border: 1px solid rgba(234,88,12,0.2); }
.alert-success { background: rgba(34,197,94,0.1);  color: var(--green);       border: 1px solid rgba(34,197,94,0.2); }
.alert-error   { background: rgba(239,68,68,0.1);  color: var(--red);         border: 1px solid rgba(239,68,68,0.2); }
.alert-warning { background: rgba(245,158,11,0.1); color: var(--yellow);      border: 1px solid rgba(245,158,11,0.2); }

/* Donut chart placeholder */
.donut-wrapper {
  display: flex;
  align-items: center;
  gap: 24px;
}

/* Inline separator */
.sep { color: var(--border); margin: 0 6px; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 40px;
  height: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

/* Connection status */
.conn-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
}
.conn-status.connected    { background: rgba(34,197,94,0.1);  color: var(--green);  border: 1px solid rgba(34,197,94,0.2); }
.conn-status.disconnected { background: rgba(239,68,68,0.1);  color: var(--red);    border: 1px solid rgba(239,68,68,0.2); }

/* Misc */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-blue { color: var(--primary-400); }
.text-secondary { color: var(--text-secondary); }
.font-mono { font-family: 'Courier New', monospace; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

/* Filter row */
.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

/* Hamburger for mobile */
.hamburger {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  color: var(--text-secondary);
}

/* Loading spinner */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

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

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 16px;
}

.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo-text {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.login-logo-text span { color: var(--primary-500); }

/* P&L statement */
.pnl-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

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

.pnl-row.total {
  font-weight: 700;
  font-size: 16px;
  border-top: 2px solid var(--border);
  margin-top: 4px;
  padding-top: 14px;
}

.pnl-indent { padding-left: 20px; color: var(--text-secondary); }

/* Tier table */
.tier-table td { padding: 6px 10px; }
.tier-table input { width: 80px; }

/* Responsive */
@media (max-width: 900px) {
  :root { --sidebar-width: 0px; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.25s;
    width: 240px;
    z-index: 200;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
  }

  .sidebar-overlay.show { display: block; }

  .hamburger { display: flex; }

  .content { padding: 16px; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }

  .modal { max-width: 100%; }
}

@media (max-width: 500px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .topbar { padding: 0 16px; }
}

/* Date dropdown */
.date-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-width: 220px;
  z-index: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  padding: 6px 0;
}

.date-dropdown-item {
  padding: 9px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.date-dropdown-item:hover {
  background: rgba(59,130,246,0.08);
  color: var(--text-primary);
}

.date-dropdown-item.active {
  color: var(--primary-400);
  background: rgba(234,88,12,0.1);
}

.date-dropdown-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.custom-date-range {
  padding: 10px 14px;
}

.custom-date-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.custom-date-row input[type="date"] {
  flex: 1;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
}

.custom-date-row input[type="date"]:focus {
  border-color: var(--primary-500);
}

/* Notification toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideUp 0.2s ease;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--primary-500); }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
