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

:root {
  --bg: #ffffff;
  --bg2: #f8f8f7;
  --bg3: #f2f2f0;
  --text: #1a1a1a;
  --text2: #6b6b6b;
  --text3: #9a9a9a;
  --border: rgba(0,0,0,0.1);
  --border2: rgba(0,0,0,0.2);
  --radius: 8px;
  --radius-lg: 12px;
  --success-bg: #eaf3de;
  --success-text: #3b6d11;
  --danger-bg: #fcebeb;
  --danger-text: #a32d2d;
  --warning-bg: #faeeda;
  --warning-text: #854f0b;
  --info-bg: #e6f1fb;
  --info-text: #185fa5;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1c;
    --bg2: #242424;
    --bg3: #2c2c2c;
    --text: #f0f0f0;
    --text2: #a0a0a0;
    --text3: #666;
    --border: rgba(255,255,255,0.1);
    --border2: rgba(255,255,255,0.2);
    --success-bg: #1a2e0a; --success-text: #7dc44a;
    --danger-bg: #2e0a0a; --danger-text: #e87070;
    --warning-bg: #2e1e00; --warning-text: #f0b84a;
    --info-bg: #0a1e35; --info-text: #5b9fd4;
  }
}

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

/* ===================== AUTH ===================== */
.auth-page { background: var(--bg3); min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-wrap { width: 100%; max-width: 400px; padding: 20px; }
.auth-card { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 36px; box-shadow: var(--shadow); }
.auth-logo { text-align: center; margin-bottom: 28px; }
.logo-icon { width: 48px; height: 48px; background: var(--text); color: var(--bg); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700; margin: 0 auto 12px; }
.logo-icon.small { width: 28px; height: 28px; font-size: 14px; font-weight: 700; border-radius: 6px; }
.auth-logo h1 { font-size: 20px; font-weight: 600; }
.auth-logo p { font-size: 13px; color: var(--text2); margin-top: 4px; }
.tab-switch { display: flex; border: 0.5px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 24px; }
.tab-btn { flex: 1; padding: 8px; border: none; background: none; cursor: pointer; font-size: 13px; color: var(--text2); }
.tab-btn.active { background: var(--text); color: var(--bg); }
.demo-section { margin-top: 20px; padding-top: 16px; border-top: 0.5px solid var(--border); }
.demo-label { font-size: 11px; color: var(--text3); margin-bottom: 8px; }
.demo-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.demo-pill { padding: 4px 10px; border: 0.5px solid var(--border2); border-radius: 20px; font-size: 12px; cursor: pointer; color: var(--text2); }
.demo-pill:hover { background: var(--bg3); }

/* ===================== LAYOUT ===================== */
.header {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  padding: 0 24px;
  height: 52px;
  display: flex; align-items: center; gap: 20px;
}
.header-left { display: flex; align-items: center; gap: 8px; }
.logo-text { font-size: 15px; font-weight: 600; }
.main-nav { flex: 1; display: flex; gap: 2px; }
.nav-btn { padding: 6px 14px; border: none; background: none; cursor: pointer; font-size: 13px; color: var(--text2); border-radius: var(--radius); }
.nav-btn:hover { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: var(--bg3); color: var(--text); font-weight: 500; }
.header-right { display: flex; align-items: center; gap: 12px; }
.user-info { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--info-bg); color: var(--info-text); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; }
.btn-logout { padding: 5px 12px; border: 0.5px solid var(--border2); border-radius: var(--radius); background: none; cursor: pointer; font-size: 12px; color: var(--text2); }
.btn-logout:hover { background: var(--danger-bg); color: var(--danger-text); border-color: transparent; }

.main-content { max-width: 1200px; margin: 0 auto; padding: 24px 24px; }
.tab-section { display: none; }
.tab-section.active { display: block; }

/* ===================== FORMS ===================== */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 10px;
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--text3); }
.field.full { grid-column: span 2; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.error-msg { color: var(--danger-text); font-size: 12px; min-height: 16px; margin-bottom: 8px; }

.btn-primary {
  padding: 8px 18px;
  background: var(--text); color: var(--bg);
  border: none; border-radius: var(--radius);
  cursor: pointer; font-size: 13px; font-weight: 500;
}
.btn-primary:hover { opacity: .85; }
.btn-secondary {
  padding: 8px 18px;
  border: 0.5px solid var(--border2); border-radius: var(--radius);
  background: none; cursor: pointer; font-size: 13px; color: var(--text);
}
.btn-secondary:hover { background: var(--bg3); }
.btn-danger { padding: 6px 12px; background: var(--danger-bg); color: var(--danger-text); border: none; border-radius: var(--radius); cursor: pointer; font-size: 12px; }
.btn-sm { padding: 5px 10px; border: 0.5px solid var(--border); border-radius: var(--radius); background: none; cursor: pointer; font-size: 12px; color: var(--text); }
.btn-sm:hover { background: var(--bg3); }

/* ===================== STATS ===================== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 28px; }
.stat-card { background: var(--bg2); border-radius: var(--radius); padding: 16px; }
.stat-num { font-size: 24px; font-weight: 600; }
.stat-lbl { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* ===================== TOOLBAR ===================== */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.search-box {
  flex: 1; min-width: 200px;
  padding: 8px 12px;
  border: 0.5px solid var(--border2); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font-size: 13px;
}
.filters { display: flex; flex-wrap: wrap; gap: 5px; }
.filter-pill {
  padding: 5px 12px; border: 0.5px solid var(--border); border-radius: 20px;
  font-size: 12px; cursor: pointer; color: var(--text2); background: var(--bg);
}
.filter-pill:hover { border-color: var(--border2); color: var(--text); }
.filter-pill.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-header h2 { font-size: 15px; font-weight: 500; }

/* ===================== PRODUCT CARDS ===================== */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.p-card {
  background: var(--bg); border: 0.5px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px;
  display: flex; flex-direction: column; gap: 6px;
}
.p-card:hover { border-color: var(--border2); }
.p-card-top { display: flex; justify-content: space-between; align-items: flex-start; }
.p-name { font-size: 13px; font-weight: 500; line-height: 1.3; }
.p-owner { font-size: 11px; color: var(--text3); }
.p-stock-row { display: flex; align-items: baseline; gap: 4px; margin-top: 4px; }
.p-stock { font-size: 22px; font-weight: 600; }
.p-unit { font-size: 12px; color: var(--text2); }
.p-price { font-size: 12px; color: var(--text2); }
.p-desc { font-size: 11px; color: var(--text3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-actions { display: flex; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 0.5px solid var(--border); }
.p-actions button { flex: 1; }

/* ===================== BADGES ===================== */
.badge { font-size: 10px; padding: 2px 8px; border-radius: 10px; font-weight: 500; white-space: nowrap; }
.badge-in { background: var(--success-bg); color: var(--success-text); }
.badge-low { background: var(--warning-bg); color: var(--warning-text); }
.badge-out { background: var(--danger-bg); color: var(--danger-text); }
.badge-cat { background: var(--info-bg); color: var(--info-text); }

/* ===================== ORDERS ===================== */
.orders-list { display: flex; flex-direction: column; gap: 8px; }
.order-row {
  background: var(--bg); border: 0.5px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px 16px;
  display: flex; align-items: center; gap: 14px;
}
.order-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.order-icon.buy { background: var(--success-bg); }
.order-icon.sell { background: var(--info-bg); }
.order-body { flex: 1; }
.order-title { font-size: 13px; font-weight: 500; }
.order-sub { font-size: 12px; color: var(--text2); margin-top: 2px; }
.order-right { text-align: right; flex-shrink: 0; }
.order-amount { font-size: 14px; font-weight: 600; }
.order-date { font-size: 11px; color: var(--text3); margin-top: 2px; }
.order-info-row { background: var(--bg3); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 14px; font-size: 13px; }
.order-info-row span { color: var(--text2); font-size: 12px; }

/* ===================== MODALS ===================== */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 200;
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg); border-radius: var(--radius-lg);
  border: 0.5px solid var(--border); width: 100%; max-width: 480px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.modal-sm { max-width: 360px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 0; }
.modal-header h3 { font-size: 15px; font-weight: 500; }
.modal-close { border: none; background: none; font-size: 20px; cursor: pointer; color: var(--text3); line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 18px 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 18px; }

/* ===================== TOAST ===================== */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: var(--radius);
  font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
  transform: translateY(8px);
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ===================== EMPTY STATE ===================== */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text3); }
.empty-state p { font-size: 13px; margin-top: 8px; }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 640px) {
  .main-content { padding: 16px; }
  .header { padding: 0 16px; }
  .main-nav .nav-btn span { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: span 1; }
  .product-grid { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 400px) {
  .product-grid { grid-template-columns: 1fr; }
}

/* ===================== ORDER STATUS ===================== */
.order-status { font-size: 11px; font-weight: 500; padding: 3px 10px; border-radius: 10px; display: inline-block; margin-top: 4px; }
.badge-waiting { background: var(--warning-bg); color: var(--warning-text); }
.badge-ok      { background: var(--success-bg); color: var(--success-text); }
.badge-no      { background: var(--danger-bg);  color: var(--danger-text); }

/* ===================== ORDER ACTIONS ===================== */
.order-actions { display: flex; gap: 8px; margin-top: 10px; }
.btn-accept {
  padding: 6px 14px; border: none; border-radius: var(--radius);
  background: var(--success-bg); color: var(--success-text);
  cursor: pointer; font-size: 12px; font-weight: 500;
}
.btn-accept:hover { filter: brightness(0.92); }
.btn-reject {
  padding: 6px 14px; border: none; border-radius: var(--radius);
  background: var(--danger-bg); color: var(--danger-text);
  cursor: pointer; font-size: 12px; font-weight: 500;
}
.btn-reject:hover { filter: brightness(0.92); }
.btn-disabled {
  width: 100%; padding: 5px; border: 0.5px solid var(--border);
  border-radius: var(--radius); background: none; color: var(--text3); cursor: not-allowed;
}

.order-seller-note { font-size: 12px; color: var(--text2); margin-top: 4px; font-style: italic; }

/* ===================== PENDING CARDS ===================== */
.pending-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 28px; }
.pending-card {
  background: var(--warning-bg); border: 1px solid var(--warning-text);
  border-radius: var(--radius-lg); padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  opacity: 1; transition: opacity .3s;
}
.pending-info { flex: 1; }
.pending-title { font-size: 13px; font-weight: 500; color: var(--warning-text); }
.pending-sub { font-size: 12px; color: var(--text2); margin-top: 3px; }
.pending-time { font-size: 11px; color: var(--text3); margin-top: 2px; }
.pending-btns { display: flex; gap: 8px; flex-shrink: 0; }
.pending-title-label { color: var(--warning-text); }

/* ===================== STAT CARD ALERT ===================== */
.stat-alert { border: 1px solid var(--warning-text); background: var(--warning-bg); }
.stat-alert .stat-num { color: var(--warning-text); }
.stat-badge { font-size: 11px; background: var(--warning-text); color: #fff; padding: 2px 8px; border-radius: 10px; margin-left: 6px; vertical-align: middle; }

/* ===================== INFO NOTE ===================== */
.info-note { font-size: 12px; color: var(--info-text); background: var(--info-bg); padding: 7px 10px; border-radius: var(--radius); margin-bottom: 14px; }
