/* ==============================================================================
   WEB ĐẠI XOAN SUPER - ADMIN & DASHBOARD CSS (APPLE HIG MODERN SYSTEM)
   ============================================================================== */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bg-app: #f8fafc;
  --bg-sidebar: #0f172a;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border-color: #e2e8f0;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-light: #f0fdf4;
  --accent: #0284c7;
  --purple: #7c3aed;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #16a34a;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 100;
  border-right: 1px solid rgba(255,255,255,0.06);
}

.sidebar-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-toggle-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: #ffffff;
  color: var(--text-main);
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.sidebar-toggle-btn:hover {
  background: #f1f5f9;
}

.sidebar-close-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border: none;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar-close-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.sidebar-backdrop {
  display: none;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
}

.brand-badge {
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.brand-super {
  color: #34d399;
  font-size: 11px;
  text-transform: uppercase;
  margin-left: 4px;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(52, 211, 153, 0.15);
  font-weight: 800;
}

.sidebar-nav {
  padding: 18px 12px;
  flex: 1;
  overflow-y: auto;
}

.nav-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-light);
  font-weight: 700;
  padding: 8px 12px 4px;
  margin-top: 10px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
  transition: all 0.15s ease;
}

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

.nav-link.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(15, 118, 110, 0.4);
}

.nav-icon {
  font-size: 16px;
  width: 20px;
  display: inline-block;
  text-align: center;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #334155;
  color: #f8fafc;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.user-info {
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11px;
  color: var(--text-light);
}

.btn-logout {
  background: transparent;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 18px;
  padding: 6px;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.15);
}

/* Main Content Area */
.main-wrapper {
  margin-left: 260px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border-color);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.page-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.3px;
}

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

.content-body {
  padding: 28px;
  flex: 1;
}

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

.metric-card {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 16px;
}

.metric-icon-box {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 22px;
  flex-shrink: 0;
}

.metric-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
}

.metric-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 3px;
}

/* Panels & Tables */
.card-panel {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  overflow: hidden;
}

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

.panel-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13.5px;
}

.data-table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.data-table tr:hover td {
  background: #f8fafc;
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.badge-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.badge-danger { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.badge-warning { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.badge-info { background: #f0f9ff; color: #0369a1; border: 1px solid #bae6fd; }
.badge-purple { background: #f5f3ff; color: #6d28d9; border: 1px solid #ddd6fe; }
.badge-neutral { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }

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

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

.btn-outline {
  background: #fff;
  border-color: #cbd5e1;
  color: #334155;
}
.btn-outline:hover { background: #f1f5f9; }

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

.btn-danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: #dc2626;
}
.btn-danger:hover { background: #fee2e2; }

.btn-purple {
  background: #7c3aed;
  color: #fff;
  border-color: #7c3aed;
}
.btn-purple:hover {
  background: #6d28d9;
  color: #fff;
}

/* ==============================================================================
   FORMS & FORM CONTROLS (APPLE HIG STANDARD)
   ============================================================================== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 4px;
}

.form-label .required,
.required {
  color: #dc2626;
  font-weight: 700;
}

.form-control,
.form-select,
select.form-control,
input.form-control,
textarea.form-control {
  width: 100%;
  padding: 9px 13px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text-main);
  background-color: #ffffff;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  box-sizing: border-box;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.form-control[readonly],
.form-control:disabled {
  background-color: #f1f5f9;
  color: #64748b;
  cursor: not-allowed;
  border-color: #e2e8f0;
}

/* Responsive Modal Grids */
.modal-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.modal-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.modal-grid-2 > .form-group,
.modal-grid-3 > .form-group {
  margin-bottom: 0 !important;
}

.form-full {
  grid-column: 1 / -1;
}

/* Sub Vendor Link Generator Grid */
.gen-link-grid {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 640px) {
  .modal-grid-2,
  .modal-grid-3 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .gen-link-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
}

/* ==============================================================================
   MODAL DIALOG (APPLE HIG RESPONSIVE & SLEEK)
   ============================================================================== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-card {
  background: #ffffff;
  border-radius: 16px;
  max-width: 580px;
  width: 100%;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.1);
  margin: auto;
  position: relative;
  overflow: hidden;
  animation: modalIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-card > form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

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

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  transition: all 0.15s ease;
}

.modal-close:hover {
  background: #fee2e2;
  color: var(--danger);
}

.modal-body {
  padding: 22px 24px;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}

.modal-footer {
  padding: 16px 24px;
  background: #f8fafc;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

/* Toast Floating Box */
.toast-box {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #ffffff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0,0,0,0.25);
  z-index: 100000;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastFadeIn 0.25s ease-out;
}
@keyframes toastFadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==============================================================================
   RESPONSIVE LAYOUT GRIDS & MEDIA QUERIES (MOBILE / TABLET)
   ============================================================================== */
.dashboard-grid,
.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}

@media (max-width: 992px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.45);
    z-index: 1000;
  }

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

  .main-wrapper {
    margin-left: 0 !important;
    width: 100% !important;
    min-width: 0;
  }

  .sidebar-toggle-btn {
    display: inline-flex !important;
  }

  .sidebar-close-btn {
    display: inline-flex !important;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.25s ease;
  }

  .sidebar-backdrop.active {
    display: block;
    opacity: 1;
  }

  .dashboard-grid,
  .detail-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .content-body {
    padding: 16px 14px !important;
  }
}

@media (max-width: 768px) {
  /* Prevent iOS Safari auto-zoom on input focus */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  input[type="email"],
  input[type="password"],
  select,
  textarea,
  .form-control {
    font-size: 16px !important;
  }

  /* Compact Topbar */
  .topbar {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }

  .topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
  }

  .page-title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-right {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }

  .topbar-right .btn {
    flex: 1;
    justify-content: center;
    text-align: center;
    min-height: 40px;
    font-size: 12.5px;
    padding: 8px 10px;
  }

  /* Compact KPI Cards */
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px;
    margin-bottom: 16px;
  }

  .metric-card {
    padding: 12px;
    gap: 10px;
  }

  .metric-icon-box {
    width: 38px;
    height: 38px;
    font-size: 18px;
    border-radius: 10px;
  }

  .metric-value {
    font-size: 19px;
  }

  .metric-label {
    font-size: 11px;
  }

  /* Card Panels */
  .card-panel {
    margin-bottom: 16px;
    border-radius: 12px;
  }

  .panel-header {
    padding: 12px 14px;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .panel-header .btn {
    width: 100%;
    justify-content: center;
  }

  /* Filter toolbar forms */
  .card-panel form {
    display: flex;
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .card-panel form input,
  .card-panel form select,
  .card-panel form button,
  .card-panel form a.btn {
    max-width: 100% !important;
    width: 100% !important;
    min-height: 42px;
  }

  .card-panel form div[style*="margin-left:auto"] {
    margin-left: 0 !important;
    text-align: center;
    padding-top: 4px;
  }

  /* Responsive Table touch scrolling */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    border-radius: 8px;
  }

  .data-table th,
  .data-table td {
    padding: 10px 12px;
    font-size: 12.5px;
    white-space: nowrap;
  }

  /* Modal Sheet Dialog */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal-card {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 92vh !important;
    border-radius: 20px 20px 0 0 !important;
    margin: 0 !important;
    animation: modalSheetUp 0.26s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes modalSheetUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  .modal-header {
    padding: 14px 18px;
  }

  .modal-body {
    padding: 16px 18px;
  }

  .modal-footer {
    padding: 12px 18px;
    flex-direction: column-reverse;
    gap: 8px;
  }

  .modal-footer .btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }
}

@media (max-width: 480px) {
  .metrics-grid {
    grid-template-columns: 1fr !important;
  }
}

