:root {
  --bg-primary: #0D1117;
  --bg-secondary: #161B22;
  --bg-tertiary: #21262D;
  --border: #30363D;
  --border-light: #484F58;
  --text-primary: #E6EDF3;
  --text-secondary: #8B949E;
  --text-muted: #6E7681;
  --up: #3FB950;
  --up-bg: rgba(63, 185, 80, 0.15);
  --down: #F85149;
  --down-bg: rgba(248, 81, 73, 0.15);
  --neutral: #D29922;
  --neutral-bg: rgba(210, 153, 34, 0.15);
  --accent: #58A6FF;
  --accent-hover: #79B8FF;
  --warn: #D29922;
  --danger: #F85149;
  --success: #3FB950;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
}
.mono { font-family: 'JetBrains Mono', monospace; }
a { text-decoration: none; color: inherit; }

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

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
}
.sidebar-header { padding: 24px 20px; border-bottom: 1px solid var(--border); }
.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--accent), var(--up));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.logo-text { font-size: 16px; font-weight: 600; }
.user-info { padding: 16px 20px; border-bottom: 1px solid var(--border); background: var(--bg-tertiary); }
.user-name { font-weight: 500; font-size: 14px; margin-bottom: 4px; }
.user-role {
  font-size: 12px; color: var(--text-secondary);
  display: inline-block; padding: 2px 8px;
  background: var(--bg-secondary); border-radius: 4px;
}
.user-role.admin { color: var(--down); }
.user-role.operator { color: var(--accent); }
.user-role.viewer { color: var(--text-secondary); }

.nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav-section { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.nav-section:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.nav-section-title { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; padding: 8px 16px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 8px;
  color: var(--text-secondary); cursor: pointer;
  transition: all 0.15s ease; font-size: 14px; font-weight: 500;
}
.nav-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.nav-item.active { background: var(--accent); color: white; }
.nav-icon { font-size: 18px; width: 24px; text-align: center; }

.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); }
.logout-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 8px;
  color: var(--text-secondary); cursor: pointer;
  font-size: 14px; font-weight: 500;
  transition: all 0.15s ease; width: 100%; border: none;
  background: none; font-family: inherit;
}
.logout-btn:hover { background: var(--down-bg); color: var(--down); }

/* Main */
.main { flex: 1; margin-left: 240px; padding: 32px; min-width: 0; overflow-x: hidden; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 32px; }
.page-title { font-size: 24px; font-weight: 600; }
.page-meta { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }
.header-actions { display: flex; gap: 12px; }

/* Cards */
.card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 12px; padding: 24px; margin-bottom: 24px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.card-title { font-size: 14px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.card-sublabel { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }

/* Price Hero */
.price-hero {
  background: linear-gradient(135deg, rgba(88, 166, 255, 0.1), rgba(63, 185, 80, 0.05));
  border-radius: 16px; padding: 32px;
  display: flex; align-items: center; gap: 32px;
  margin-bottom: 24px;
}
.price-main { display: flex; align-items: baseline; gap: 8px; }
.price-value { font-size: 56px; font-weight: 600; }
.price-unit { font-size: 16px; color: var(--text-secondary); }
.price-right { flex: 1; }
.price-right .status { display: inline-flex; align-items: center; padding: 6px 14px; border-radius: 20px; font-size: 14px; font-weight: 500; }
.hero-loading { color: var(--text-secondary); font-size: 16px; }

/* Metrics */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.metric-card {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px;
  transition: all 0.2s ease;
}
.metric-card:hover { transform: translateY(-2px); border-color: var(--border-light); box-shadow: 0 8px 24px rgba(0,0,0,0.3); }
.metric-value { font-family: 'JetBrains Mono', monospace; font-size: 28px; font-weight: 600; margin-bottom: 4px; }
.metric-label { font-size: 13px; color: var(--text-secondary); }
.metric-change { font-size: 13px; margin-top: 8px; font-weight: 500; }
.metric-change.up { color: var(--up); }
.metric-change.down { color: var(--down); }

/* Two col */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 8px;
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: all 0.15s ease; border: none; font-family: inherit; text-decoration: none;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--border-light); }
.tab-btn { background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 16px; font-size: 14px; color: #64748b; cursor: pointer; border-radius: 4px 4px 0 0; transition: color 0.2s, border-color 0.2s; margin-bottom: -1px; }
.tab-btn:hover { color: #94a3b8; }
.tab-btn-active { color: #38bdf8; border-bottom-color: #38bdf8; font-weight: 600; }
.btn-danger { background: var(--down-bg); color: var(--down); border: 1px solid rgba(248, 81, 73, 0.3); }
.btn-danger:hover { background: var(--down); color: white; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 500; color: var(--text-secondary); border-bottom: 1px solid var(--border); white-space: normal; word-break: break-word; }
.table td { padding: 10px 12px; font-size: 13px; border-bottom: 1px solid var(--border); vertical-align: middle; word-break: break-word; }
.table tr:hover td { background: var(--bg-tertiary); }
.table-empty { text-align: center; padding: 48px; color: var(--text-secondary); }

/* Status badges */
.status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 500;
}
.status.active, .status.settled { background: var(--up-bg); color: var(--up); }
.status.pending, .status.deposit_paid { background: var(--neutral-bg); color: var(--neutral); }
.status.overdue { background: var(--down-bg); color: var(--down); }
.status.locked { background: rgba(88, 166, 255, 0.15); color: var(--accent); }

/* Modals */
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 12px; }

/* Forms */
.form-group { margin-bottom: 20px; }
.form-label { display: block; font-size: 14px; font-weight: 500; color: var(--text-secondary); margin-bottom: 8px; }
.form-input, .form-select {
  width: 100%; padding: 12px 14px;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-primary);
  font-size: 14px; font-family: inherit;
  transition: border-color 0.15s ease;
}
.form-input:focus, .form-select:focus { outline: none; border-color: var(--accent); }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238B949E' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; }
.badge-admin { background: rgba(248, 81, 73, 0.15); color: var(--down); }
.badge-operator { background: rgba(88, 166, 255, 0.15); color: var(--accent); }
.badge-viewer { background: var(--bg-tertiary); color: var(--text-secondary); }

/* Momentum */
.momentum-grid { display: flex; gap: 32px; }

/* Responsive */
@media (max-width: 1024px) {
  .sidebar { width: 72px; }
  .logo-text, .nav-section-title, .user-info, .logout-btn span, .nav-item span { display: none; }
  .nav-item { justify-content: center; padding: 14px; }
  .main { margin-left: 72px; padding: 20px; }
  .two-col { grid-template-columns: 1fr; }
  .price-hero { flex-direction: column; align-items: flex-start; }
  .price-value { font-size: 40px; }
}

/* === Distributor Card === */
.dist-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}
.dist-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
.dist-card-del { opacity: 0.65; }
.dist-card-del:hover { transform: none; box-shadow: none; border-color: var(--border); cursor: default; }
.dist-level {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; flex-shrink: 0;
}
.level-A { background: rgba(63, 185, 80, 0.15); color: var(--up); }
.level-B { background: rgba(88, 166, 255, 0.15); color: var(--accent); }
.level-C { background: rgba(139, 148, 158, 0.15); color: var(--text-secondary); }
.dist-info { flex: 1; min-width: 0; }
.dist-name { font-weight: 600; font-size: 15px; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dist-meta { font-size: 12px; color: var(--text-secondary); display: flex; gap: 10px; flex-wrap: wrap; }
.dist-status { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; }
.dist-status.active { background: rgba(63, 185, 80, 0.15); color: var(--up); }
.dist-status.paused { background: rgba(210, 153, 34, 0.15); color: var(--warning); }
.dist-status.terminated { background: rgba(248, 81, 73, 0.15); color: var(--down); }

/* === Order Card === */
.order-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}
.order-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.order-info { flex: 1; min-width: 0; }
.order-id { font-family: 'JetBrains Mono', monospace; font-size: 14px; font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.order-meta { font-size: 12px; color: var(--text-secondary); display: flex; gap: 12px; flex-wrap: wrap; }
.order-amount { font-size: 18px; font-weight: 700; margin-bottom: 4px; white-space: nowrap; }

/* === Status Badges === */
.status { display: inline-block; padding: 3px 10px; border-radius: 6px; font-size: 12px; font-weight: 500; }
.status.pending { background: rgba(210, 153, 34, 0.15); color: var(--warning); }
.status.confirmed { background: rgba(63, 185, 80, 0.15); color: var(--up); }
.status.shipped { background: rgba(88, 166, 255, 0.15); color: var(--accent); }
.status.completed { background: rgba(63, 185, 80, 0.2); color: var(--up); }
.status.cancelled { background: rgba(139, 148, 158, 0.15); color: var(--text-secondary); }

/* === Modal === */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.7);
  display: none; align-items: flex-end; justify-content: center;
  padding: 0;
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 20px; }
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  width: 100%; max-width: 100%;
  max-height: 92vh; overflow: hidden;
  display: flex; flex-direction: column;
  animation: modalIn 0.2s ease;
}
@media (min-width: 640px) {
  .modal {
    border-radius: 16px;
    max-width: 560px;
    max-height: 90vh;
  }
}
@keyframes modalIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@media (min-width: 640px) {
  @keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
@media (min-width: 640px) {
  .modal-header { padding: 20px 24px; }
}
.modal-title { font-size: 15px; font-weight: 600; }
@media (min-width: 640px) {
  .modal-title { font-size: 16px; }
}
.modal-close {
  background: none; border: none; color: var(--text-secondary);
  font-size: 22px; cursor: pointer; padding: 4px; line-height: 1;
  border-radius: 6px; transition: background 0.15s;
}
.modal-close:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.modal-body {
  padding: 16px 20px; overflow-y: auto; overflow-x: hidden; flex: 1;
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 640px) {
  .modal-body { padding: 24px; }
}
.modal-footer {
  padding: 12px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end; flex-shrink: 0;
  flex-wrap: wrap;
}
@media (min-width: 640px) {
  .modal-footer { padding: 16px 24px; gap: 12px; }
}

/* === Form responsive === */
.form-group { margin-bottom: 16px; }
@media (min-width: 640px) {
  .form-group { margin-bottom: 20px; }
}
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
@media (min-width: 640px) {
  .form-label { font-size: 14px; margin-bottom: 8px; }
}
.form-input, .form-select {
  width: 100%; padding: 10px 12px;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-primary);
  font-size: 14px; font-family: inherit;
  transition: border-color 0.15s ease;
  box-sizing: border-box;
  max-width: 100%;
}
@media (min-width: 640px) {
  .form-input, .form-select { padding: 12px 14px; }
}
.form-input:focus, .form-select:focus { outline: none; border-color: var(--accent); }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238B949E' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

/* === Table responsive === */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.table { width: 100%; min-width: 0; border-collapse: collapse; table-layout: fixed; }
.table th { text-align: left; padding: 8px 10px; font-size: 11px; font-weight: 500; color: var(--text-secondary); border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 640px) {
  .table th { padding: 10px 12px; font-size: 12px; white-space: normal; }
}
.table td { padding: 10px; font-size: 13px; border-bottom: 1px solid var(--border); vertical-align: middle; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 640px) {
  .table td { padding: 10px 12px; font-size: 13px; white-space: normal; }
}
.table tr:hover td { background: var(--bg-tertiary); }
.table-empty { text-align: center; padding: 32px; color: var(--text-secondary); }

/* === File upload responsive === */
.file-upload-area {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-secondary);
  font-size: 13px;
}
@media (min-width: 640px) {
  .file-upload-area { padding: 24px; font-size: 14px; }
}
.file-upload-area:hover { border-color: var(--accent); background: rgba(88, 166, 255, 0.05); }
.file-upload-area.has-file, .file-upload-area.done { border-color: var(--up); background: rgba(63, 185, 80, 0.05); }
.file-upload-area input[type=file] { display: none; }

/* === Page content responsive === */
.page-header {
  flex-direction: column; align-items: flex-start;
  gap: 12px; margin-bottom: 20px; min-width: 0;
}
.page-header .header-actions { width: 100%; }
.main { padding: 16px; min-width: 0; overflow-x: hidden; }
@media (min-width: 640px) {
  .main { padding: 24px; }
  .page-header { flex-direction: row; align-items: center; gap: 0; margin-bottom: 28px; }
  .page-header .header-actions { width: auto; }
}
.grid-3 { grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) { .grid-3 { grid-template-columns: repeat(3, 1fr); gap: 16px; } }
.grid-2 { grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: repeat(2, 1fr); gap: 16px; } }
.sidebar { width: 0; overflow: hidden; border-radius: 0; }
@media (min-width: 640px) { .sidebar { width: 220px; } }
.main { margin-left: 0; min-width: 0; overflow-x: hidden; }
@media (min-width: 640px) { .main { margin-left: 220px; } }

/* === File Upload === */
.file-upload-area {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-secondary);
}
.file-upload-area:hover { border-color: var(--accent); background: rgba(88, 166, 255, 0.05); }
.file-upload-area.has-file, .file-upload-area.done { border-color: var(--up); background: rgba(63, 185, 80, 0.05); }
.file-upload-area input[type=file] { display: none; }

/* === Buttons === */

/* === Supplier Card === */
.sup-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}
.sup-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
.sup-card-del { opacity: 0.65; cursor: default; }
.sup-card-del:hover { transform: none; box-shadow: none; border-color: var(--border); }
.sup-level {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.sup-type-manufacturer { background: rgba(63, 185, 80, 0.15); }
.sup-type-trading { background: rgba(88, 166, 255, 0.15); }
.sup-info { flex: 1; min-width: 0; }
.sup-name { font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.sup-meta { font-size: 12px; color: var(--text-secondary); display: flex; gap: 10px; flex-wrap: wrap; }
.sup-status { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; }
.sup-status.active { background: rgba(63, 185, 80, 0.15); color: var(--up); }
.sup-status.paused { background: rgba(210, 153, 34, 0.15); color: var(--warning); }
