/* ─── KSP Ecommerce — Design System ─── */
:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-hover: #fff8f5;
  --line: #f0e6de;
  --text: #2d1f14;
  --text-dark: #1a0f05;
  --muted: #8a7a6d;
  --accent: #ee4d2d;
  --accent-light: #ff6633;
  --accent-bg: #fff5f2;
  --heading: #1a0f05;
  --row-hover: #fff8f5;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* ─── Screens ─── */
.screen { display: none; }
.screen.active { display: block; }

/* ─── Login ─── */
.login-card {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: linear-gradient(135deg, #fff5f2 0%, #ffe8e0 100%);
}
.login-logo { filter: drop-shadow(0 2px 8px rgba(238,77,45,0.25)); }
.login-card h1 { font-size: 28px; font-weight: 700; color: var(--accent); letter-spacing: -0.5px; }
.login-sub { color: var(--muted); font-size: 14px; }
.login-footer { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* ─── Header ─── */
.app-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 20px;
  background: linear-gradient(135deg, #ee4d2d 0%, #ff6633 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(238,77,45,0.25);
  position: sticky; top: 0; z-index: 50;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-title { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.header-right { display: flex; align-items: center; gap: 12px; }

/* ─── User Dropdown ─── */
.user-dropdown-container { position: relative; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px; border-radius: 20px;
  background: rgba(255,255,255,0.2); cursor: pointer;
  transition: background 0.2s;
  font-size: 13px; font-weight: 500;
}
.user-chip:hover { background: rgba(255,255,255,0.35); }
.avatar { width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.4); }
.dropdown-arrow { font-size: 8px; opacity: 0.7; }
.user-dropdown-menu {
  display: none; position: absolute; right: 0; top: 42px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); min-width: 180px; overflow: hidden; z-index: 100;
}
.user-dropdown-menu.open { display: block; }
.dropdown-version { padding: 10px 14px; font-size: 11px; color: var(--muted); border-bottom: 1px solid var(--line); }
.dropdown-item {
  display: block; width: 100%; padding: 10px 14px;
  text-align: left; border: none; background: none;
  font-size: 13px; color: var(--text);
  transition: background 0.15s;
}
.dropdown-item:hover { background: var(--row-hover); }
.text-danger { color: #dc2626 !important; }

/* ─── Main Layout ─── */
.app-main { padding: 16px 20px; max-width: 1200px; margin: 0 auto; }

/* ─── Summary Cards ─── */
.summary-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.summary-card {
  background: var(--surface); border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow); border-left: 4px solid var(--accent);
  transition: transform 0.2s, box-shadow 0.2s;
}
.summary-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.summary-card .label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.summary-card .value { font-size: 26px; font-weight: 800; margin-top: 4px; color: var(--text-dark); font-family: 'Outfit', 'Inter', sans-serif; }
.summary-card .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.summary-card.green { border-left-color: #10b981; }
.summary-card.blue { border-left-color: #3b82f6; }
.summary-card.amber { border-left-color: #f59e0b; }
.summary-card.red { border-left-color: #ef4444; }
.summary-card.purple { border-left-color: #8b5cf6; }

/* ─── Status Tabs ─── */
.status-tabs {
  display: flex; gap: 4px; margin-bottom: 16px;
  overflow-x: auto; padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.status-tab {
  padding: 8px 16px; border: none; border-radius: 20px;
  font-size: 13px; font-weight: 600;
  background: var(--surface); color: var(--muted);
  white-space: nowrap;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}
.status-tab:hover { color: var(--accent); background: var(--accent-bg); }
.status-tab.active { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(238,77,45,0.3); }
.status-tab .badge {
  display: inline-block; padding: 1px 7px; border-radius: 10px;
  font-size: 11px; font-weight: 700; margin-left: 4px;
  background: rgba(0,0,0,0.08);
}
.status-tab.active .badge { background: rgba(255,255,255,0.3); }

/* ─── Card ─── */
.card {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow);
}

/* ─── Table ─── */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 10px 12px; text-align: left; font-size: 12px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 2px solid var(--line); white-space: nowrap;
}
tbody td {
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  font-size: 13px; vertical-align: middle;
}
tbody tr { transition: background 0.15s; cursor: pointer; }
tbody tr:hover { background: var(--row-hover); }

/* ─── Status Badge ─── */
.status-badge {
  display: inline-block; padding: 3px 10px; border-radius: 12px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
.status-badge.to-pay { background: #fef3c7; color: #92400e; }
.status-badge.to-ship { background: #dbeafe; color: #1e40af; }
.status-badge.to-receive { background: #e0e7ff; color: #3730a3; }
.status-badge.completed { background: #d1fae5; color: #065f46; }
.status-badge.cancelled { background: #fee2e2; color: #991b1b; }
.status-badge.return-refund { background: #f3e8ff; color: #6b21a8; }

/* ─── Buttons ─── */
.btn {
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; border: 1px solid transparent;
  transition: all 0.2s;
}
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #d9432a; }
.btn-outline { background: transparent; color: var(--text); border-color: var(--line); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-accent { background: linear-gradient(135deg, #ee4d2d, #ff6633); color: #fff; }
.btn-accent:hover { box-shadow: 0 3px 10px rgba(238,77,45,0.3); }

/* ─── Form ─── */
.form-input {
  width: 100%; padding: 8px 12px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: 13px; font-family: var(--font);
  transition: border-color 0.2s;
}
.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(238,77,45,0.1); }

/* ─── Order Detail ─── */
.detail-header-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  font-size: 13px; margin-bottom: 16px;
}
.detail-field { display: flex; gap: 8px; }
.detail-field .label { color: var(--muted); font-weight: 600; min-width: 100px; }
.detail-field .value { color: var(--text-dark); font-weight: 500; }

/* ─── Product Card ─── */
.product-card {
  display: flex; gap: 12px; padding: 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.product-card:hover { background: var(--row-hover); }
.product-img {
  width: 64px; height: 64px; border-radius: 8px;
  object-fit: cover; background: #f3f4f6;
  flex-shrink: 0;
}
.product-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.product-title { font-size: 13px; font-weight: 600; color: var(--text-dark); line-height: 1.4; }
.product-option { font-size: 12px; color: var(--muted); }
.product-price { font-size: 13px; font-weight: 700; color: var(--accent); }

/* ─── Price Breakdown ─── */
.price-breakdown {
  background: var(--accent-bg); border-radius: var(--radius-sm); padding: 16px;
}
.price-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.price-row .label { color: var(--muted); }
.price-row .value { font-weight: 600; }
.price-row.total { border-top: 2px solid var(--accent); margin-top: 8px; padding-top: 8px; }
.price-row.total .label { font-weight: 700; color: var(--text-dark); }
.price-row.total .value { font-size: 18px; font-weight: 800; color: var(--accent); }

/* ─── Tracking Timeline ─── */
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
  content: ''; position: absolute; left: 7px; top: 8px; bottom: 8px;
  width: 2px; background: var(--line);
}
.timeline-item { position: relative; padding: 8px 0 8px 16px; }
.timeline-item::before {
  content: ''; position: absolute; left: -20px; top: 12px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--line); border: 2px solid var(--surface);
}
.timeline-item:first-child::before { background: var(--accent); box-shadow: 0 0 0 3px rgba(238,77,45,0.2); }
.timeline-item .time { font-size: 11px; color: var(--muted); font-weight: 500; }
.timeline-item .desc { font-size: 13px; color: var(--text); margin-top: 2px; line-height: 1.5; }
.timeline-item:first-child .desc { font-weight: 600; color: var(--accent); }

/* ─── Pagination ─── */
.pagination {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 12px; font-size: 13px;
}
.page-info { color: var(--muted); }

/* ─── Search Bar ─── */
.search-bar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .detail-header-grid { grid-template-columns: 1fr; }
  .app-main { padding: 12px; }
  .status-tabs { gap: 2px; }
  .status-tab { padding: 6px 12px; font-size: 12px; }
}
@media (max-width: 480px) {
  .summary-grid { grid-template-columns: 1fr; }
}

/* ─── Animations ─── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.3s ease; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.loading-pulse { animation: pulse 1.5s ease-in-out infinite; }
