@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --brand: #e5354b;
  --brand-dark: #b71c36;
  --brand-soft: #fff0f1;
  --tech: #2563eb;
  --tech-soft: #eff6ff;
  --green: #16a34a;
  --orange: #f59e0b;
  --red: #ef4444;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --heading: #111827;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 16px rgba(0, 0, 0, .06);
  --shadow-hover: 0 8px 28px rgba(0, 0, 0, .1);
  --radius: 12px;
}

* { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }

html, body {
  background: var(--bg);
  color: var(--text);
}

a, a:hover { color: var(--tech); text-decoration: none; }
a:hover { color: #1d4ed8; }

/* ---- Helpers ---- */
.text-primary { color: var(--brand) !important; }
.text-info { color: var(--tech) !important; }
.text-success { color: var(--green) !important; }
.text-danger { color: var(--red) !important; }
.text-muted { color: var(--muted) !important; }
.text-dark { color: var(--heading) !important; }

.bg-primary { background-color: var(--brand) !important; color: #fff !important; }
.bg-success { background-color: var(--green) !important; color: #fff !important; }
.bg-danger { background-color: var(--red) !important; color: #fff !important; }
.bg-info { background-color: var(--tech) !important; color: #fff !important; }
.bg-secondary { background-color: #f1f5f9 !important; color: var(--text) !important; }
.bg-light { background-color: #f8fafc !important; color: var(--text) !important; }

.border { border-color: var(--border) !important; }

/* ---- Cards ---- */
.dashboard-card,
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  transition: transform .2s ease, box-shadow .2s ease;
}

.dashboard-card:hover,
.card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.dashboard-card {
  padding: 20px;
  margin-bottom: 20px;
}

.card-header {
  background: transparent;
  color: var(--heading);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 1.05rem;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px 20px;
}

.card-header h3 { margin: 0; font-size: 1.05rem; }

/* ---- Tables ---- */
.table {
  color: var(--text);
  border-color: var(--border);
  margin-bottom: 0;
  width: 100%;
}

.table thead th {
  background: #f8fafc;
  color: var(--heading);
  border-bottom: 2px solid var(--brand);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
  padding: 8px 4px;
  white-space: normal;
  line-height: 1.25;
  vertical-align: middle;
  height: auto;
}

.table td,
.table th {
  padding: 6px 4px;
  font-size: .8rem;
  vertical-align: middle;
}

.table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-striped tbody tr:nth-of-type(odd) {
  background: #f8fafc;
}

.table-hover tbody tr:hover {
  background: #fff0f1;
  transition: background .15s ease;
}

.table-responsive {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow-x: auto;
}

/* Cố định tỷ lệ cột để bảng vừa 1 dòng, không scroll ngang trên máy tính */
#subdomainTable { table-layout: fixed; width: 100%; }
#subdomainTable th,
#subdomainTable td { width: auto; vertical-align: middle; }
#subdomainTable th:nth-child(1),
#subdomainTable td:nth-child(1) { width: 9%; padding: 6px 2px; }
#subdomainTable th:nth-child(2),
#subdomainTable td:nth-child(2) { width: 17%; }
#subdomainTable th:nth-child(3),
#subdomainTable td:nth-child(3) { width: 4%; }
#subdomainTable th:nth-child(4),
#subdomainTable td:nth-child(4) { width: 7%; }
#subdomainTable th:nth-child(5),
#subdomainTable td:nth-child(5) { width: 5%; }
#subdomainTable th:nth-child(6),
#subdomainTable td:nth-child(6) { width: 12%; }
#subdomainTable th:nth-child(7),
#subdomainTable td:nth-child(7) { width: 10%; }
#subdomainTable th:nth-child(8),
#subdomainTable td:nth-child(8) { width: 4%; }
#subdomainTable th:nth-child(9),
#subdomainTable td:nth-child(9) { width: 10%; }
#subdomainTable th:nth-child(10),
#subdomainTable td:nth-child(10) { width: 9%; }
#subdomainTable th:nth-child(11),
#subdomainTable td:nth-child(11) { width: 13%; }
#subdomainTable td:nth-child(11) { font-size: 0; white-space: nowrap; }

/* Giữ các nút nằm cùng hàng, không nhảy dòng */
.table td.text-center { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#subdomainTable td:nth-child(11) { overflow: visible; }
.table tbody td .btn,
.table tbody td form { display: inline-block; vertical-align: middle; }

.ip-cell {
  font-family: 'Courier New', monospace;
  color: var(--tech);
  font-weight: 600;
}

.status-cell .badge {
  font-size: .6rem;
  padding: .15em .25em;
  white-space: nowrap;
}

/* ---- DDNS configuration alerts ---- */
/* Amber pill shown under the online/offline badge when the device sends a
   misconfigured update. Clicking it opens the explanation modal. */
.ddns-flag {
  display: block;
  margin-top: 3px;
  border: 0;
  width: 100%;
  font-size: .58rem;
  font-weight: 700;
  line-height: 1.2;
  padding: .2em .3em;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}

.ddns-flag:hover { background: #fde68a; transform: translateY(-1px); }
.ddns-flag i { margin-right: 2px; }

.ddns-alert {
  display: none;
  align-items: flex-start;
  gap: 14px;
  background: linear-gradient(135deg, #fffbeb 0%, #fff7ed 100%);
  border: 1px solid #fcd34d;
  border-left: 5px solid var(--orange);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 20px;
}

.ddns-alert.show { display: flex; }

.ddns-alert-icon {
  flex: 0 0 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--orange);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.ddns-alert-body { flex: 1 1 auto; min-width: 0; }
.ddns-alert-title { font-weight: 700; color: #92400e; margin: 0 0 3px; font-size: .98rem; }
.ddns-alert-text { color: #a16207; font-size: .85rem; margin: 0 0 10px; }

.ddns-alert-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ddns-alert-list li {
  background: #fff;
  border: 1px solid #fcd34d;
  border-radius: 999px;
  padding: 3px 11px;
  font-size: .78rem;
  font-weight: 600;
  color: #92400e;
  font-family: 'Courier New', monospace;
}

.ddns-alert-action { flex: 0 0 auto; align-self: center; }

@media (max-width: 575.98px) {
  .ddns-alert { flex-direction: column; }
  .ddns-alert-action { align-self: stretch; }
  .ddns-alert-action .btn { width: 100%; }
}

.ddns-issue-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--orange);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--surface);
}

.ddns-issue-card:last-child { margin-bottom: 0; }
.ddns-issue-host { font-family: 'Courier New', monospace; font-weight: 700; color: var(--heading); word-break: break-all; }
.ddns-issue-problem { color: #b45309; font-weight: 600; font-size: .88rem; margin-top: 4px; }
.ddns-issue-when { color: var(--muted); font-size: .78rem; margin-top: 2px; }

.ddns-issue-fix {
  margin-top: 10px;
  background: var(--tech-soft);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .85rem;
  color: #1e3a8a;
}

.ddns-issue-fix strong { display: block; margin-bottom: 3px; color: #1d4ed8; }

.sort-icon {
  color: var(--tech);
  font-size: .65rem;
  margin-left: 3px;
}

.sortable { cursor: pointer; }
.sortable:hover { color: var(--brand); }

/* ---- Buttons ---- */
.btn-primary {
  background: var(--brand) !important;
  border: none !important;
  color: #fff !important;
  border-radius: 8px;
  font-weight: 600;
  padding: 8px 16px;
  transition: all .2s ease;
}

.btn-primary:hover {
  background: var(--brand-dark) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(229, 53, 75, .25);
}

.btn-info {
  background: var(--tech-soft) !important;
  border: 1px solid #bfdbfe !important;
  color: var(--tech) !important;
  border-radius: 8px;
  font-weight: 600;
  transition: all .2s ease;
}

.btn-info:hover {
  background: #dbeafe !important;
  border-color: #93c5fd !important;
}

.btn-success {
  background: var(--green) !important;
  border: none !important;
  color: #fff !important;
  font-weight: 600;
}

.btn-danger {
  background: var(--red) !important;
  border: none !important;
  color: #fff !important;
  font-weight: 600;
}

.btn-warning {
  background: var(--orange) !important;
  border: none !important;
  color: #0f172a !important;
  font-weight: 600;
}

.btn-secondary {
  background: #f1f5f9 !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
}

.btn-outline-dark {
  border-color: var(--border) !important;
  color: var(--heading) !important;
}

.btn-outline-dark:hover {
  background: var(--brand-soft) !important;
  border-color: var(--brand) !important;
  color: var(--brand) !important;
}

.btn-action {
  padding: 5px 6px;
  border-radius: 8px;
  font-size: 0;
  margin: 0 2px;
  line-height: 1;
  transition: all .2s ease;
  white-space: nowrap;
}

.btn-action i,
.btn-action svg {
  font-size: .75rem;
  margin: 0;
}

.btn-action:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, .1);
}

/* Trên màn hình rất rộng (>1600px) mới hiện cả chữ lẫn icon */
@media (min-width: 1600px) {
  .btn-action {
    font-size: .72rem;
    padding: 5px 8px;
  }
  .btn-action i,
  .btn-action svg {
    margin-right: 4px;
  }
}

/* ---- Progress ---- */
.progress {
  background: #e2e8f0;
  border-radius: 12px;
  height: 14px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .06);
}

.progress-bar {
  background: linear-gradient(90deg, var(--brand), var(--tech)) !important;
  color: #fff;
  font-weight: 600;
  font-size: .75rem;
  line-height: 1.4;
  border-radius: 12px;
}

/* ---- Modals ---- */
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .12);
  color: var(--text);
}

.modal-header {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  color: var(--heading);
  border-radius: var(--radius) var(--radius) 0 0;
}

.modal-header .btn-close { filter: none; }

.modal-body .form-control[readonly],
.modal-body .form-control.bg-light {
  background: #f8fafc !important;
  color: var(--text);
}

/* ---- Forms ---- */
.form-control,
.form-select {
  background-color: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  transition: border-color .2s, box-shadow .2s;
}

.form-control::placeholder { color: #94a3b8; }

.form-control:focus,
.form-select:focus {
  background-color: #fff;
  color: var(--text);
  border-color: var(--tech);
  box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .15);
}

.input-group .form-control { border-right: 0; }

.input-group .btn-outline-secondary {
  background: #f8fafc;
  border-color: var(--border);
  color: var(--muted);
}

.input-group .btn-outline-secondary:hover {
  background: var(--tech);
  color: #fff;
  border-color: var(--tech);
}

/* ---- Badges ---- */
.badge {
  font-size: .72rem;
  padding: .4em .65em;
  border-radius: 6px;
  font-weight: 600;
}

.record-type-badge {
  background: var(--tech) !important;
  color: #fff !important;
  font-size: .62rem;
  padding: 2px 5px;
  border-radius: 5px;
  font-weight: 700;
  text-transform: uppercase;
}

/* ---- Search ---- */
.search-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  margin-bottom: 20px;
}

#searchInput {
  background: #fff;
  border: 1px solid var(--brand);
  border-radius: 25px 0 0 25px;
  color: var(--text);
  height: 38px;
  font-size: .9rem;
}

#searchInput::placeholder { color: #94a3b8; }

#searchButton {
  border-radius: 0 25px 25px 0;
  background: var(--brand) !important;
  border: none;
  color: #fff;
  font-weight: 600;
  height: 38px;
}

/* ---- Alerts ---- */
.alert { border-radius: 12px; border-width: 1px; }

.alert-info { background: var(--tech-soft); border-color: #bfdbfe; color: var(--tech); }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-danger { background: #fff0f1; border-color: #fecdd3; color: var(--brand); }

/* ---- Pagination ---- */
.page-link {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
  border-radius: 8px;
  margin: 0 2px;
  font-weight: 600;
}

.page-link:hover {
  background: var(--brand-soft);
  color: var(--brand);
  border-color: var(--brand);
}

.page-item.active .page-link {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.page-item.disabled .page-link {
  background: #f8fafc;
  color: #94a3b8;
}

/* ---- Nav pills inside modal ---- */
.nav-pills .nav-link {
  background: transparent;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  border-radius: 0;
}

.nav-pills .nav-link.active,
.nav-pills .nav-link:hover {
  background: var(--brand-soft);
  color: var(--brand);
}

/* ---- Config / code ---- */
.config-box {
  background: #f8fafc;
  color: var(--text);
  border-left: 4px solid var(--brand);
  border-radius: 8px;
  padding: 15px;
  font-family: 'Courier New', monospace;
}

.config-box label { color: var(--tech); }

.step-badge {
  background: var(--brand);
  color: #fff;
  min-width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.setup-guide {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ---- Toast ---- */
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--heading);
}

/* ---- Animation ---- */
@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: .6; }
  100% { opacity: 1; }
}

.anim-pulse { animation: pulse 2s infinite; }

/* ---- Wide screens ---- */
@media (min-width: 1600px) {
  .table th,
  .table td { font-size: .85rem; padding: 8px 6px; }
  #subdomainTable th:nth-child(11),
  #subdomainTable td:nth-child(11) { width: 16%; }
}

/* ---- Mobile ---- */
@media (max-width: 768px) {
  body { font-size: .9rem; }
  h2 { font-size: 1.3rem; }
  h3, .card-header h3 { font-size: .95rem; }
  .dashboard-card { padding: 15px; margin-bottom: 15px; }
  .dashboard-card h5 { font-size: .95rem; }
  .table th,
  .table td { font-size: .78rem; padding: 8px 5px; }
  .table thead th { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.25; }
  .btn-action { padding: 4px 6px; font-size: .7rem; }
  .btn-action i { font-size: 10px; }
  .progress { height: 12px; }
  .search-box { padding: 10px; }
  .table-responsive { -webkit-overflow-scrolling: touch; }
  #subdomainTable { table-layout: auto; width: auto; min-width: 950px; }
  #subdomainTable th:nth-child(n),
  #subdomainTable td:nth-child(n) { width: auto; }
  #subdomainTable th:nth-child(7),
  #subdomainTable td:nth-child(7),
  #subdomainTable th:nth-child(8),
  #subdomainTable td:nth-child(8),
  #subdomainTable th:nth-child(10),
  #subdomainTable td:nth-child(10) { display: none; }
}
