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

:root {
  --primary: #1677ff;
  --primary-hover: #4096ff;
  --primary-bg: #e6f4ff;
  --sidebar-bg: #001529;
  --sidebar-text: rgba(255,255,255,0.65);
  --sidebar-active: #fff;
  --header-height: 56px;
  --bg-body: #f0f2f5;
  --bg-card: #fff;
  --border: #e8e8e8;
  --border-light: #f0f0f0;
  --text-primary: #1f1f1f;
  --text-secondary: #666;
  --text-muted: #999;
  --danger: #ff4d4f;
  --success: #52c41a;
  --warning: #faad14;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 6px 16px rgba(0,0,0,0.12);
  --radius: 6px;
  --radius-lg: 8px;
  --transition: 0.25s ease;
  --sidebar-width: 220px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-body);
}

a { text-decoration: none; color: inherit; }
ul, ol { list-style: none; }
button { border: none; outline: none; cursor: pointer; font-family: inherit; font-size: inherit; background: none; }
table { border-collapse: collapse; width: 100%; }
input, select { font-family: inherit; font-size: inherit; }

/* ===== App Layout ===== */
#app {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 24px;
  overflow-y: auto;
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow-y: auto;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

.sidebar-header {
  padding: 16px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-text {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.5px;
}

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

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: 4px 16px;
}

.nav-group {
  margin-bottom: 2px;
}

.nav-group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px 6px;
  font-size: 11px;
  color: rgba(255,255,255,0.3);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px 10px 24px;
  color: var(--sidebar-text);
  font-size: 14px;
  transition: all 0.25s ease;
  border-left: 3px solid transparent;
  cursor: pointer;
}

.nav-item:hover {
  color: #fff;
  background: rgba(255,255,255,0.06);
}

.nav-item.active {
  color: var(--sidebar-active);
  background: var(--primary);
  border-left-color: #fff;
}

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

.sidebar-footer {
  padding: 10px 20px;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.version {
  font-size: 11px;
  color: rgba(255,255,255,0.2);
}

/* ===== Top Header ===== */
.top-header {
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 rgba(0,0,0,0.03);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.top-header.loaded {
  opacity: 1;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-icon-btn {
  position: relative;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-secondary);
  transition: all 0.25s ease;
}

.header-icon-btn:hover {
  background: #f5f5f5;
  color: var(--text-primary);
}

.notif-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid var(--bg-card);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: background 0.25s ease;
}

.user-info:hover {
  background: #f5f5f5;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}

.username {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
}

/* ===== Page Header ===== */
.page-header {
  flex-shrink: 0;
  margin-bottom: 20px;
}

.page-header h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.page-header p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ===== Platform Layout ===== */
.platform-layout {
  display: flex;
  flex: 1;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  animation: fadeInUp 0.4s ease forwards;
}

.platform-sidebar {
  width: 168px;
  flex-shrink: 0;
  background: #fafafa;
  border-right: 1px solid var(--border-light);
  padding: 8px 0;
}

.platform-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.25s ease;
  border-right: 2px solid transparent;
  position: relative;
}

.platform-nav-item:hover {
  color: var(--primary);
  background: rgba(22,119,255,0.04);
}

.platform-nav-item.active {
  color: var(--primary);
  background: var(--primary-bg);
  border-right-color: var(--primary);
  font-weight: 500;
}

.platform-nav-item .nav-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #d9d9d9;
  transition: all 0.25s ease;
}

.platform-nav-item.active .nav-dot { background: var(--primary); }
.platform-nav-item:hover .nav-dot { background: var(--primary); }

.platform-content {
  flex: 1;
  padding: 20px 24px;
  min-width: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px 20px;
  transition: all 0.3s ease;
}

.stat-card:hover {
  box-shadow: var(--shadow-sm);
  border-color: #e0e0e0;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.stat-card .stat-value {
  font-size: 26px;
  font-weight: 600;
  color: var(--text-primary);
}

.stat-card .stat-value.primary { color: var(--primary); }
.stat-card .stat-value.success { color: var(--success); }
.stat-card .stat-value.danger { color: var(--danger); }
.stat-card .stat-value.warning { color: var(--warning); }

/* ===== Content Panel ===== */
.content-panel {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

/* ===== Table ===== */
.table-container {
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
  gap: 8px;
}

.table-toolbar .left { display: flex; align-items: center; gap: 10px; }
.table-toolbar .right { display: flex; align-items: center; gap: 8px; }
.table-toolbar h3 { font-size: 14px; font-weight: 600; }

.data-table { width: 100%; background: #fff; }

.data-table thead { background: #f0f0f0; }

.data-table th {
  padding: 11px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
  user-select: none;
}

.data-table td {
  padding: 11px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}

.data-table tbody tr {
  transition: background-color 0.2s ease;
}

.data-table tbody tr:hover {
  background-color: #fafafa;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* ===== Status Badge ===== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.status-badge.success {
  color: #389e0d;
  background: #f6ffed;
  border: 1px solid #b7eb8f;
}

.status-badge.error {
  color: #cf1322;
  background: #fff2f0;
  border: 1px solid #ffa39e;
}

.status-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-badge.success .dot { background: #52c41a; }
.status-badge.error .dot { background: #ff4d4f; }

/* ===== Toggle Switch ===== */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
}

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

.toggle-track {
  width: 34px;
  height: 18px;
  background: #d9d9d9;
  border-radius: 9px;
  position: relative;
  transition: all 0.3s ease;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: all 0.3s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.toggle-switch input:checked + .toggle-track {
  background: var(--primary);
}

.toggle-switch input:checked + .toggle-track::after {
  left: 18px;
}

.toggle-label {
  transition: color 0.25s ease;
}

.toggle-switch input:checked ~ .toggle-label {
  color: var(--success);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  transition: all 0.25s ease;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.btn:active { transform: scale(0.96); }

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

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-default {
  background: #fff;
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-default:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.btn-text {
  background: none;
  color: var(--primary);
  padding: 4px 6px;
}

.btn-text:hover {
  background: var(--primary-bg);
}

.btn-text.btn-danger { color: var(--danger); }
.btn-text.btn-danger:hover { background: #fff2f0; }

.btn-sm { padding: 3px 8px; font-size: 12px; }

.btn-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

/* ===== Dropdown ===== */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-trigger { cursor: pointer; }

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 130px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 500;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all 0.25s ease;
}

.dropdown-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text-primary);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.dropdown-item:hover { background: #f5f5f5; }
.dropdown-item.danger { color: var(--danger); }

.dropdown-divider {
  height: 1px;
  background: var(--border-light);
  margin: 4px 0;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 480px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  transform: scale(0.92) translateY(16px);
  transition: transform 0.3s ease;
}

.modal-overlay.open .modal {
  transform: scale(1) translateY(0);
}

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

.modal-header h3 { font-size: 15px; font-weight: 600; }

.modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 18px;
  color: var(--text-secondary);
  transition: background 0.2s ease;
}

.modal-close:hover { background: #f5f5f5; }

.modal-body { padding: 24px; }

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

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

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-control {
  width: 100%;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
  font-size: 14px;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(22,119,255,0.1);
}

.form-control:disabled {
  background: #f5f5f5;
  cursor: not-allowed;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ===== Confirm Dialog ===== */
.confirm-body {
  text-align: center;
  padding: 8px 0;
}

.confirm-body .confirm-icon {
  font-size: 36px;
  margin-bottom: 12px;
  display: block;
}

.confirm-body p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state p { font-size: 14px; }

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 72px;
  right: 24px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 20px;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideInRight 0.3s ease forwards;
  border-left: 4px solid var(--primary);
  min-width: 260px;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(60px); }
  to { opacity: 1; transform: translateX(0); }
}

.toast.removing {
  animation: slideOutRight 0.3s ease forwards;
}

@keyframes slideOutRight {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(60px); }
}

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

/* ===== Sub Tabs ===== */
.order-sub-tabs { display:flex;gap:0;border-bottom:1px solid var(--border);background:#fafafa;flex-shrink:0;border-radius:var(--radius) var(--radius) 0 0; }
.order-sub-tab { padding:10px 24px;font-size:13px;cursor:pointer;color:var(--text-secondary);border-bottom:2px solid transparent;transition:all 0.25s ease;user-select:none;position:relative; }
.order-sub-tab:hover { color:var(--primary);background:rgba(22,119,255,0.04); }
.order-sub-tab.active { color:var(--primary);border-bottom-color:var(--primary);font-weight:500;background:#fff; }
.order-sub-tab::after { content:'';position:absolute;right:0;top:20%;height:60%;width:1px;background:var(--border-light); }
.order-sub-tab:last-child::after { display:none; }

.link-cell { cursor:pointer;color:var(--primary);font-size:12px;transition:color 0.2s; }
.link-cell:hover { color:#1677ff;text-decoration:underline; }
.empty-row { text-align:center;padding:48px 0;color:var(--text-muted);font-size:13px; }
.amount-cell { text-align:right;font-weight:600; }
.amount-cell.danger { color:var(--danger); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d9d9d9; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #bfbfbf; }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .page-container { padding: 16px; }
  .platform-sidebar { width: 140px; }
}

@media (max-width: 768px) {
  .main-content { margin-left: 0; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .platform-layout { flex-direction: column; }
  .platform-sidebar {
    width: 100%;
    display: flex;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-light);
    padding: 4px 8px;
  }
  .platform-nav-item {
    white-space: nowrap;
    border-right: none;
    border-bottom: 2px solid transparent;
  }
  .platform-nav-item.active {
    border-right-color: transparent;
    border-bottom-color: var(--primary);
  }
  .form-row { grid-template-columns: 1fr; }
  .page-container { padding: 12px; }
}
