/* =====================================================================
   ADMIN COMPONENTS CSS
   Reusable UI components: buttons, forms, tables, cards, badges, etc.
   ===================================================================== */

/* =====================================================================
   BUTTONS
   Based on demo button styling
   ===================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-lg);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  line-height: 1;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-normal);
  white-space: nowrap;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

/* Button Sizes */
.btn--sm {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: var(--font-size-sm);
}

.btn--lg {
  padding: var(--spacing-md) var(--spacing-xl);
  font-size: var(--font-size-lg);
}

/* Button Variants - Updated to match demo */
.btn-primary,
.btn.brand {
  background: var(--btn-primary-bg);
  border-color: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}

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

.btn-secondary,
.btn.gray {
  background: var(--btn-gray-bg);
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover,
.btn.gray:hover {
  background: var(--btn-gray-hover);
  border-color: var(--border-color);
}

.btn-success,
.btn.green {
  background: var(--btn-success-bg);
  border-color: var(--btn-success-bg);
  color: var(--text-white);
}

.btn-success:hover,
.btn.green:hover {
  background: var(--btn-success-hover);
  border-color: var(--btn-success-hover);
}

.btn-danger,
.btn.red {
  background: var(--btn-danger-bg);
  border-color: var(--btn-danger-bg);
  color: var(--text-white);
}

.btn-danger:hover,
.btn.red:hover {
  background: var(--btn-danger-hover);
  border-color: var(--btn-danger-hover);
}

.btn-warning,
.btn.orange {
  background: var(--btn-warning-bg);
  border-color: var(--btn-warning-bg);
  color: var(--text-white);
}

.btn-warning:hover,
.btn.orange:hover {
  background: var(--btn-warning-hover);
  border-color: var(--btn-warning-hover);
}

.btn-outline,
.btn.white {
  background: #2D3748;
  border-color: var(--border-color);
  color: var(--text-primary);
}

.btn-outline:hover,
.btn.white:hover {
  background: #4A5568;
  border-color: var(--border-color);
}

/* Light theme button overrides */
.theme-light .btn-outline,
.theme-light .btn.white {
  background: #FFFFFF;
  border: 1px solid #D1D5DB;
  color: var(--text-main);
}

.theme-light .btn-outline:hover,
.theme-light .btn.white:hover {
  background: #F5F7FA;
  border-color: #9CA3AF;
}

.theme-light .btn-primary {
  color: #FFFFFF;
}

/* Button Group */
.btn-group {
  display: inline-flex;
}

.btn-group .btn {
  border-radius: 0;
}

.btn-group .btn:first-child {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.btn-group .btn:last-child {
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.btn-group .btn + .btn {
  margin-left: -1px;
}

/* =====================================================================
   FORM ELEMENTS
   ===================================================================== */

/* Form Group */
.form-group {
  margin-bottom: var(--spacing-lg);
}

.form-label {
  display: block;
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  margin-bottom: var(--spacing-sm);
}

.form-label--required::after {
  content: " *";
  color: var(--text-error);
}

/* Input, Select, Textarea */
.input,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: var(--input-padding-y) var(--input-padding-x);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  border: var(--input-border-width) solid var(--border-color);
  border-radius: var(--radius-xl);
  background: var(--bg-panel);
  color: var(--text-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.input:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--focus-border-color);
  box-shadow: 0 0 0 var(--focus-ring-width) var(--focus-ring-color);
}

.input::placeholder,
input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

.input--error,
.input.is-invalid {
  border-color: var(--text-error);
}

.input--error:focus,
.input.is-invalid:focus {
  box-shadow: 0 0 0 var(--focus-ring-width) rgba(217, 45, 32, 0.15);
}

/* Textarea */
textarea {
  min-height: 100px;
  resize: vertical;
}

/* Select */
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='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--input-padding-x) center;
  padding-right: calc(var(--input-padding-x) * 2 + 12px);
}

/* Input Wrapper (for icons) */
.input-wrap {
  position: relative;
}

.input-wrap .input,
.input-wrap input {
  padding-right: 48px;
}

.input-wrap__icon {
  position: absolute;
  right: var(--input-padding-x);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* Checkbox & Radio */
.checkbox,
.radio {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  cursor: pointer;
}

.checkbox input,
.radio input {
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
}

/* Form Error */
.form-error {
  margin-top: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  background: #fdecec;
  color: var(--text-error);
  border: 1px solid #ffd1d1;
  font-size: var(--font-size-sm);
}

/* Form Hint */
.form-hint {
  margin-top: var(--spacing-xs);
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

/* Mobile: Prevent zoom on input focus */
@media (max-width: 1000px) {
  input,
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* =====================================================================
   TABLES
   Based on demo table styling with border-radius 12px
   ===================================================================== */

.table-wrap,
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--card-bg);
  margin-bottom: 40px;
}

/* Light theme table shadow */
.theme-light .table-wrap,
.theme-light .table-container {
  box-shadow: var(--card-shadow);
}

@supports (-webkit-overflow-scrolling: touch) {
  .table-wrap {
    -webkit-overflow-scrolling: touch;
  }
}

.table,
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

.table th,
.table td,
th,
td {
  padding: 16px 24px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
  font-size: 14px;
}

.table th,
th,
thead {
  background: #0B1015;
  font-weight: var(--font-weight-semibold);
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-secondary);
  white-space: nowrap;
  letter-spacing: 0.5px;
}

/* Light theme table header */
.theme-light .table th,
.theme-light th,
.theme-light thead {
  background: #F5F7FA;
  color: var(--text-secondary);
  font-weight: var(--font-weight-bold);
}

.table tr:hover,
tr:hover {
  background: rgba(232, 180, 77, 0.05);
}

.theme-light .table tr:hover,
.theme-light tr:hover {
  background: #F0F9FF;
}

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

.theme-light td {
  color: var(--text-main);
}

/* Table Actions */
.table td .btn,
td .btn {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: var(--font-size-sm);
}

/* Table Responsive */
@media (max-width: 768px) {
  .table,
  table {
    min-width: auto;
  }
  
  .table th,
  .table td,
  th,
  td {
    padding: var(--spacing-sm);
    font-size: var(--font-size-sm);
  }
}

/* =====================================================================
   CARDS
   Based on demo card styling with border-radius 12px and padding 24px
   ===================================================================== */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
}

/* Stats grid - 3 columns layout from demo */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 24px;
  border: 1px solid var(--border-color);
}

/* Light theme card shadow */
.theme-light .card {
  box-shadow: var(--card-shadow);
}

.card--hover:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  transition: all var(--transition-normal);
}

.card__header,
.card-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card__title,
.card-title {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.5px;
}

.card-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-white);
  margin-top: 4px;
}

.theme-light .card-value {
  color: var(--text-main);
}

.card__body {
  /* Default body styles */
}

.card__footer {
  margin-top: var(--spacing-md);
  padding-top: var(--spacing-md);
  border-top: 1px solid var(--border-color);
}

/* Stat Card */
.card--stat {
  text-align: center;
}

.card--stat .num,
.card .num {
  font-size: var(--font-size-4xl);
  font-weight: var(--font-weight-bold);
  color: var(--brand);
  margin-bottom: var(--spacing-sm);
}

.card--stat .label,
.card span {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

/* Charts row - 2 columns layout from demo */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

/* =====================================================================
   BADGES & TAGS
   Based on demo badge styling
   ===================================================================== */

/* =====================================================================
   BADGES & TAGS
   Based on demo badge styling
   ===================================================================== */

.badge,
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid;
}

.badge--primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--text-white);
}

.badge--success,
.badge-success,
.status-online,
.status-active,
.online {
  background: var(--status-online-bg);
  border-color: var(--status-online-border);
  color: var(--status-online-text);
}

.badge--danger,
.badge-danger,
.badge-critical,
.status-offline,
.status-inactive,
.offline {
  background: var(--status-offline-bg);
  border-color: var(--status-offline-border);
  color: var(--status-offline-text);
}

.badge--warning,
.badge-warning,
.status-pending {
  background: var(--status-pending-bg);
  border-color: var(--status-pending-border);
  color: var(--status-pending-text);
}

.badge--info,
.badge-info {
  background: rgba(232, 180, 77, 0.15);
  border-color: rgba(232, 180, 77, 0.3);
  color: #F0C169;
}

/* Light theme badge overrides */
.theme-light .badge-critical {
  background: #FEE2E2;
  color: #B91C1C;
  border: 1px solid #FECACA;
}

.theme-light .badge-warning {
  background: #FED7AA;
  color: #B45309;
  border: 1px solid #FDBA74;
}

.theme-light .badge-info {
  background: #D1FAE5;
  color: #047857;
  border: 1px solid #A7F3D0;
}

/* Status Badge */
.status {
  display: inline-block;
  padding: var(--spacing-xs) var(--spacing-md);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  border-radius: var(--radius-sm);
}

/* =====================================================================
   TABS
   ===================================================================== */

.tabs {
  display: flex;
  gap: var(--spacing-xs);
  border-bottom: 2px solid var(--border-color);
  margin-bottom: var(--spacing-xl);
}

.tab {
  padding: var(--spacing-md) var(--spacing-xl);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition-normal);
}

.tab:hover {
  color: var(--brand);
}

.tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* =====================================================================
   PAGINATION
   ===================================================================== */

.pagination {
  display: inline-flex;
  gap: var(--spacing-sm);
}

.pagination .page {
  padding: var(--spacing-sm) var(--spacing-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pagination .page:hover {
  background: var(--bg-page);
  border-color: var(--text-muted);
}

.pagination .page.active {
  background: var(--btn-success-bg);
  border-color: var(--btn-success-bg);
  color: var(--text-white);
}

.pagination .page.disabled,
.pagination .page.ellipsis {
  opacity: 0.5;
  pointer-events: none;
}

.toolbar--pager {
  justify-content: flex-end;
}

/* =====================================================================
   MODALS / DIALOGS
   ===================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-modal-backdrop);
  display: none;
}

.modal-backdrop.active {
  display: block;
}

/* Native <dialog> element support */
dialog.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-modal);
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow: auto;
  padding: 0;
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

dialog.modal[open] {
  display: block;
}

dialog.modal .modal-card {
  padding: var(--spacing-xl);
}

dialog.modal h3 {
  margin: 0 0 var(--spacing-lg) 0;
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
}

/* Legacy div.modal support */
.modal:not(dialog) {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-modal);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow: auto;
  display: none;
}

.modal:not(dialog).active {
  display: block;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-xl);
  border-bottom: 1px solid var(--border-color);
}

.modal__title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  margin: 0;
}

.modal__close {
  padding: var(--spacing-sm);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius-md);
}

.modal__close:hover {
  background: var(--bg-page);
  color: var(--text-primary);
}

.modal__body {
  padding: var(--spacing-xl);
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--spacing-sm);
  padding: var(--spacing-lg) var(--spacing-xl);
  border-top: 1px solid var(--border-color);
}

/* =====================================================================
   ALERTS / NOTIFICATIONS
   ===================================================================== */

.alert {
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--radius-lg);
  margin-bottom: var(--spacing-lg);
  border: 1px solid;
}

.alert--info {
  background: #e0f2fe;
  border-color: #7dd3fc;
  color: #0369a1;
}

.alert--success {
  background: var(--status-online-bg);
  border-color: var(--status-online-border);
  color: var(--status-online-text);
}

.alert--warning {
  background: var(--status-pending-bg);
  border-color: var(--status-pending-border);
  color: var(--status-pending-text);
}

.alert--danger {
  background: var(--status-offline-bg);
  border-color: var(--status-offline-border);
  color: var(--status-offline-text);
}

/* =====================================================================
   LOADING / SPINNER
   ===================================================================== */

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner--sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.spinner--lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

.spinner--white {
  border-color: rgba(255, 255, 255, 0.3);
  border-top-color: var(--text-white);
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Loading Overlay */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}

/* =====================================================================
   TOOLTIPS
   ===================================================================== */

.tooltip {
  position: relative;
}

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: var(--spacing-xs) var(--spacing-sm);
  background: var(--bg-dark);
  color: var(--text-white);
  font-size: var(--font-size-sm);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  z-index: var(--z-tooltip);
}

.tooltip:hover::after {
  opacity: 1;
  visibility: visible;
}

/* =====================================================================
   DROPDOWN
   ===================================================================== */

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown__menu {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 160px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  display: none;
}

.dropdown__menu.active {
  display: block;
}

.dropdown__item {
  display: block;
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md);
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-primary);
  transition: background var(--transition-fast);
}

.dropdown__item:hover {
  background: var(--bg-page);
}

.dropdown__item:first-child {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.dropdown__item:last-child {
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.dropdown__divider {
  height: 1px;
  background: var(--border-color);
  margin: var(--spacing-xs) 0;
}

/* =====================================================================
   AVATAR
   ===================================================================== */

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-page);
}

.avatar--sm {
  width: 32px;
  height: 32px;
}

.avatar--lg {
  width: 56px;
  height: 56px;
}

.avatar--xl {
  width: 80px;
  height: 80px;
}

/* Avatar Group */
.avatar-group {
  display: flex;
}

.avatar-group .avatar {
  margin-left: -8px;
  border: 2px solid var(--bg-panel);
}

.avatar-group .avatar:first-child {
  margin-left: 0;
}

/* =====================================================================
   PROGRESS BAR
   ===================================================================== */

.progress {
  width: 100%;
  height: 8px;
  background: var(--bg-page);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  background: var(--brand);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}

.progress__bar--success {
  background: var(--btn-success-bg);
}

.progress__bar--warning {
  background: var(--btn-warning-bg);
}

.progress__bar--danger {
  background: var(--btn-danger-bg);
}

/* =====================================================================
   MISC UTILITIES
   ===================================================================== */

/* Muted text */
.muted {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

/* Divider */
.divider {
  height: 1px;
  background: var(--border-color);
  margin: var(--spacing-lg) 0;
}

/* Thumbnail */
.thumbnail {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: var(--radius-md);
  background: var(--bg-page);
}

.thumbnail--lg {
  width: 80px;
  height: 80px;
}

.thumbnail--sm {
  width: 32px;
  height: 32px;
}

/* =====================================================================
   STATUS PILL (Fixed position footer indicator)
   From demo-admin-dark.html
   ===================================================================== */

.status-pill {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--primary);
  color: #0B1015;
  padding: 12px 24px;
  border-radius: 50px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  letter-spacing: 0.5px;
  z-index: 999;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #0B1015;
  border-radius: 50%;
  display: block;
}

/* Light theme status pill */
.theme-light .status-pill {
  background: #FFFFFF;
  color: var(--text-main);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
  border: 1px solid #D1D5DB;
}

.theme-light .status-dot {
  background: var(--primary);
}
