:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --bg-color: #f3f4f6;
  --card-bg: #ffffff;
  --text-main: #111827;
  --text-muted: #6b7280;
  --border-color: #e5e7eb;
  --border-radius: 12px;
  --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 -1px rgba(0, 0, 0, 0.06);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
}

a {
  color: var(--primary);
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  outline: none;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 8px 16px;
  background: #ffffff;
  color: var(--text-main);
  border: 1px solid var(--border-color);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

button:hover:not(:disabled) {
  background: #f9fafb;
}

button.btn-primary,
#applyFiltersButton,
#batchImportButton,
#createRecordButton,
button[type="submit"] {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

button.btn-primary:hover,
#applyFiltersButton:hover,
#batchImportButton:hover,
#createRecordButton:hover,
button[type="submit"]:hover {
  background: var(--primary-hover);
}

button.btn-cancel {
  background: #ffffff;
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

button.btn-danger {
  background: #dc2626;
  color: #ffffff;
  border-color: #dc2626;
}

button.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

input,
select,
textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #ffffff;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

input[type="checkbox"] {
  width: auto;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

#batchImportText {
  min-height: 200px;
  font-family: monospace;
  font-size: 13px;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 32px;
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.admin-header h1 {
  margin: 0 0 4px 0;
  font-size: 24px;
  font-weight: 600;
}

.admin-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

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

.admin-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 24px;
  margin: 0 32px 32px;
}

.admin-sidebar {
  align-self: start;
  display: grid;
  gap: 8px;
  padding: 14px;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
}

.admin-nav-item {
  width: 100%;
  text-align: left;
}

.admin-nav-item.is-active {
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
}

.admin-nav-item.is-active:hover {
  background: var(--primary-hover);
}

.admin-content {
  min-width: 0;
}

.admin-content > .admin-section {
  margin: 0;
}

.admin-content > .admin-section[hidden] {
  display: none;
}

.admin-section,
.action-bar,
.public-batch-eligibility,
.filter-section,
.table-wrap,
.pagination-bar {
  margin: 0 32px 24px;
}

.admin-content .action-bar,
.admin-content .public-batch-eligibility,
.admin-content .filter-section,
.admin-content .table-wrap,
.admin-content .pagination-bar,
.admin-content #batchDeleteProgressSection {
  margin-right: 0;
  margin-left: 0;
}

.admin-content #batchDeleteProgressSection {
  margin-bottom: 24px;
}

.section-heading,
.admin-section-placeholder {
  padding: 20px 24px;
  margin-bottom: 24px;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
}

.section-heading h2 {
  margin: 0;
  font-size: 20px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.section-heading p,
.admin-section-placeholder {
  margin-top: 6px;
  margin-bottom: 0;
  color: var(--text-muted);
}

.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 24px;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
}

.action-bar-left,
.action-bar-right {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.action-bar-right {
  justify-content: flex-end;
}

.management-filter-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(4, minmax(150px, 180px)) auto auto;
  gap: 12px;
  align-items: center;
  padding: 16px 24px;
  margin-bottom: 24px;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
}

#opApplicationsSection .management-filter-bar {
  grid-template-columns: minmax(240px, 1fr) minmax(140px, 180px) auto auto;
}

.public-batch-eligibility {
  padding: 16px 20px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
}

.public-batch-eligibility.has-warning {
  background: #fff7ed;
  border-color: #fdba74;
}

.public-batch-eligibility-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 6px;
}

.public-batch-eligibility-head strong {
  font-size: 15px;
}

.public-batch-eligibility-head span,
.public-batch-eligibility-details {
  color: var(--text-muted);
  font-size: 14px;
}

.public-batch-eligibility-details {
  margin: 0;
}

.filter-section {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  transition: all 0.3s ease;
  overflow: hidden;
}

.filter-section.hidden {
  display: none;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.filter-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-item label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

.table-wrap {
  overflow: auto;
  border-radius: var(--border-radius);
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1200px;
  font-size: 14px;
}

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

th:first-child,
td:first-child {
  width: 52px;
  text-align: center;
}

th {
  background: #f9fafb;
  font-weight: 600;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  white-space: nowrap;
}

tbody tr:hover {
  background: #f9fafb;
}

td .row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.cell-truncate {
  display: inline-block;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.cell-truncate-op {
  display: block;
}

.cell-truncate-link {
  display: block;
}

.cell-truncate-op-nickname {
  display: block;
}

#recordTable {
  table-layout: fixed;
  min-width: 0;
}

#recordTable col.record-col-select {
  width: 3%;
}

#recordTable col.record-col-order {
  width: 5%;
}

#recordTable col.record-col-google-account {
  width: 10%;
}

#recordTable col.record-col-google-password {
  width: 8%;
}

#recordTable col.record-col-google-assist {
  width: 8%;
}

#recordTable col.record-col-google-expire {
  width: 7%;
}

#recordTable col.record-col-uid {
  width: 5%;
}

#recordTable col.record-col-uid-created {
  width: 7%;
}

#recordTable col.record-col-op {
  width: 9%;
}

#recordTable col.record-col-op-nickname {
  width: 6%;
}

#recordTable col.record-col-op-link {
  width: 9%;
}

#recordTable col.record-col-op-expire {
  width: 7%;
}

#recordTable col.record-col-remark {
  width: 6%;
}

#recordTable col.record-col-actions {
  width: 10%;
}

#recordTable th,
#recordTable td {
  padding: 14px 10px;
  font-size: 13px;
}

#recordTable td {
  overflow-wrap: anywhere;
}

#recordTable .row-actions {
  justify-content: flex-start;
}

#recordTable .row-actions button {
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}

#shortOpTable {
  table-layout: fixed;
  min-width: 1200px;
}

#shortOpTable .cell-truncate {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#shortOpTable col.short-op-col-code { width: 7%; }
#shortOpTable col.short-op-col-link { width: 10%; }
#shortOpTable col.short-op-col-app-name { width: 9%; }
#shortOpTable col.short-op-col-app-id { width: 9%; }
#shortOpTable col.short-op-col-value { width: 16%; }
#shortOpTable col.short-op-col-owner { width: 8%; }
#shortOpTable col.short-op-col-status { width: 7%; }
#shortOpTable col.short-op-col-expire { width: 12%; }
#shortOpTable col.short-op-col-remark { width: 8%; }
#shortOpTable col.short-op-col-actions { width: 14%; }

#shortOpTable th,
#shortOpTable td,
#opApplicationTable th,
#opApplicationTable td {
  padding: 12px 10px;
  font-size: 13px;
}

#shortOpTable .row-actions,
#opApplicationTable .row-actions {
  gap: 6px;
}

#shortOpTable .row-actions button,
#opApplicationTable .row-actions button {
  padding: 6px 9px;
  font-size: 12px;
  white-space: nowrap;
}

#opApplicationTable {
  table-layout: fixed;
  min-width: 0;
}

.status-label {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  color: #166534;
  background: #dcfce7;
  font-size: 12px;
  white-space: nowrap;
}

.status-label.is-disabled {
  color: #991b1b;
  background: #fee2e2;
}

.default-label {
  color: var(--primary);
  font-weight: 600;
}

.empty-table-cell {
  padding: 36px 16px;
  color: var(--text-muted);
  text-align: center !important;
}

.import-result-summary {
  min-height: 22px;
  margin: 0;
  font-weight: 600;
}

.import-error-list {
  max-height: 180px;
  margin: 0;
  padding-left: 24px;
  overflow: auto;
  color: #b91c1c;
  font-size: 13px;
}

@media (max-width: 1920px) {
  #recordTable th,
  #recordTable td {
    padding: 12px 8px;
  }

  #recordTable col.record-col-google-account {
    width: 9.5%;
  }

  #recordTable col.record-col-google-password,
  #recordTable col.record-col-google-assist {
    width: 8%;
  }

  #recordTable col.record-col-op,
  #recordTable col.record-col-op-link {
    width: 10%;
  }

  #recordTable col.record-col-actions {
    width: 9.5%;
  }
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  padding: 16px 24px;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
}

.page-size-control {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
}

.page-size-control select {
  width: auto;
  min-width: 92px;
}

.stack-form {
  display: grid;
  gap: 16px;
}

.dialog-heading {
  display: grid;
  gap: 6px;
}

.stack-form label {
  font-weight: 500;
  font-size: 14px;
  margin-bottom: -8px;
  color: var(--text-main);
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
}

.checkbox-inline input[type="checkbox"] {
  width: auto;
}

.wifi-preview-card {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: #f9fafb;
  text-align: center;
}

.wifi-preview-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.wifi-preview-image {
  width: 180px;
  height: 180px;
  max-width: 100%;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid var(--border-color);
  object-fit: contain;
}

.wifi-preview-text {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-muted);
  word-break: break-all;
}

.form-error {
  color: #ef4444;
}

dialog {
  width: min(640px, calc(100vw - 32px));
  border: 0;
  border-radius: 16px;
  padding: 32px;
  background: var(--card-bg);
  box-shadow: var(--shadow-md);
}

dialog::backdrop {
  background: rgba(17, 24, 39, 0.6);
  backdrop-filter: blur(4px);
}

dialog h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.dialog-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

.import-help {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  padding: 16px;
  border-radius: 8px;
  font-size: 13px;
  color: #1e3a8a;
  line-height: 1.6;
}

.import-help p {
  margin-top: 0;
  font-weight: 600;
}

.import-help ul {
  margin: 0;
  padding-left: 20px;
}

.import-help code {
  background: #dbeafe;
  padding: 2px 4px;
  border-radius: 4px;
}

.batch-import-progress {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid #dbeafe;
  background: #f8fbff;
  border-radius: 12px;
}

.batch-import-progress.hidden {
  display: none;
}

.batch-import-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 600;
  color: #1d4ed8;
}

.batch-import-progress-track {
  width: 100%;
  height: 10px;
  background: #dbeafe;
  border-radius: 999px;
  overflow: hidden;
}

.batch-import-progress-bar {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4f46e5 0%, #0ea5e9 100%);
  transition: width 0.25s ease;
}

.batch-import-progress-text {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.batch-action-progress {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid #fecaca;
  background: #fff5f5;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
}

.batch-action-progress.hidden {
  display: none;
}

.batch-action-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 600;
  color: #b91c1c;
}

.batch-action-progress-track {
  width: 100%;
  height: 10px;
  background: #fee2e2;
  border-radius: 999px;
  overflow: hidden;
}

.batch-action-progress-bar {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #f97316 0%, #dc2626 100%);
  transition: width 0.25s ease;
}

.batch-action-progress-bar.danger {
  background: linear-gradient(90deg, #fb7185 0%, #dc2626 100%);
}

.batch-action-progress-text {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.dialog-menu,
menu {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin: 16px 0 0;
  padding: 0;
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
}

#adminToastStack {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 1200;
  display: grid;
  gap: 12px;
}

.admin-toast {
  min-width: 240px;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 12px;
  background: rgba(17, 24, 39, 0.96);
  color: #ffffff;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.admin-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.feedback-dialog {
  width: min(440px, calc(100vw - 32px));
}

.feedback-dialog-form {
  gap: 20px;
}

@media (max-width: 900px) {
  .admin-layout {
    display: block;
    margin: 0 16px 24px;
  }

  .admin-sidebar {
    display: flex;
    overflow-x: auto;
    gap: 10px;
    margin-bottom: 16px;
    padding: 10px;
    border-radius: 10px;
  }

  .admin-nav-item {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .management-filter-bar,
  #opApplicationsSection .management-filter-bar {
    grid-template-columns: 1fr;
  }

  #opApplicationTable {
    min-width: 760px;
  }
}
