/* Tử Vi Đẩu Số - Hệ Thống Thiên Kỷ Nghê Hải Hạ (OURANIC Engine v4.0 - Full Source Edition) */
:root {
  --bg-dark: #090d16;
  --bg-panel: #111726;
  --bg-card: #172033;
  --bg-hover: #1f2b44;
  --border-gold: rgba(212, 175, 55, 0.32);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --gold-primary: #e5c158;
  --gold-light: #f9e29c;
  --text-main: #e8ecf2;
  --text-muted: #94a3b8;
  --red-lu: #ef4444;
  --green-quyen: #10b981;
  --blue-khoa: #3b82f6;
  --purple-ky: #a855f7;
  --cyan-accent: #06b6d4;
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

.serif-title {
  font-family: 'Noto Serif SC', 'Playfair Display', Georgia, serif;
}

/* Header */
.app-header {
  background: linear-gradient(180deg, rgba(17, 23, 38, 0.98) 0%, rgba(9, 13, 22, 0.95) 100%);
  border-bottom: 1px solid var(--border-gold);
  padding: 0.8rem 1.4rem;
  position: sticky;
  top: 0;
  z-index: 60;
  backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1680px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.bagua-badge {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1.5px solid var(--gold-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  color: var(--gold-primary);
  background: radial-gradient(circle, rgba(229,193,88,0.2) 0%, transparent 70%);
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gold-light);
  letter-spacing: 0.03em;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Layout */
.main-container {
  max-width: 1680px;
  margin: 1.1rem auto;
  padding: 0 1rem;
  display: grid;
  grid-template-columns: 340px 1fr 440px;
  gap: 1.1rem;
  align-items: start;
}

@media (max-width: 1420px) {
  .main-container {
    grid-template-columns: 320px 1fr;
  }
  .insight-column {
    grid-column: 1 / -1;
  }
}

@media (max-width: 980px) {
  .main-container {
    grid-template-columns: 1fr;
  }
}

.panel-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-gold);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.panel-heading {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--gold-primary);
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.55rem;
  margin-bottom: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Controls */
.form-group {
  margin-bottom: 0.75rem;
}

.form-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.form-input, .form-select {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-main);
  padding: 0.48rem 0.65rem;
  border-radius: 7px;
  font-size: 0.83rem;
  transition: border-color 0.2s;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--gold-primary);
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #d4af37 0%, #aa8010 100%);
  color: #090d16;
  font-weight: 700;
  border: none;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.86rem;
  letter-spacing: 0.02em;
  transition: filter 0.2s;
}

.btn-primary:hover {
  filter: brightness(1.12);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--gold-light);
  border: 1px solid var(--border-gold);
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.18s;
}

.btn-secondary:hover, .btn-secondary.active {
  background: rgba(229, 193, 88, 0.22);
  border-color: var(--gold-primary);
}

/* Saved Profiles Manager */
.saved-profiles-list {
  max-height: 150px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.profile-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.profile-item:hover {
  border-color: var(--gold-primary);
  background: var(--bg-hover);
}

.profile-del-btn {
  background: transparent;
  border: none;
  color: #f87171;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0 4px;
}

/* 12 Palaces Grid & SVG Overlay */
.astrolabe-wrapper {
  position: relative;
}

.astrolabe-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, minmax(185px, auto));
  gap: 6px;
  position: relative;
}

.sanfang-svg-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

.center-palace {
  grid-column: 2 / 4;
  grid-row: 2 / 4;
  background: radial-gradient(circle at center, #182238 0%, #0d1320 100%);
  border: 1px solid var(--border-gold);
  border-radius: 10px;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  z-index: 10;
}

.palace-cell {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  position: relative;
  transition: all 0.16s ease;
  min-height: 185px;
  z-index: 15;
}

.palace-cell:hover {
  border-color: rgba(229, 193, 88, 0.65);
  background: var(--bg-hover);
}

.palace-cell.selected {
  border: 1.5px solid var(--gold-primary);
  box-shadow: 0 0 18px rgba(229, 193, 88, 0.3);
  background: #1d2840;
}

.palace-cell.sanfang-target {
  border: 1px dashed var(--cyan-accent);
  background: rgba(6, 182, 212, 0.07);
}

.palace-cell.duigong-target {
  border: 1px dashed #f59e0b;
  background: rgba(245, 158, 11, 0.08);
}

.palace-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.25rem;
}

.stars-major {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.star-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
}

.star-pill.major {
  color: #fde68a;
  border-left: 2px solid var(--gold-primary);
}

.star-pill.lucky {
  color: #93c5fd;
  font-weight: 500;
  font-size: 0.71rem;
}

.star-pill.sha {
  color: #fca5a5;
  font-weight: 600;
  font-size: 0.71rem;
}

.star-pill.minor {
  color: #94a3b8;
  font-weight: 400;
  font-size: 0.67rem;
}

.star-pill.void-star {
  color: #fcd34d;
  border: 1px dashed rgba(252, 211, 77, 0.45);
  font-size: 0.66rem;
}

.bright-tag {
  font-size: 0.62rem;
  padding: 0 2px;
  border-radius: 3px;
  font-weight: 600;
}

.bright-Mieu, .bright-Vuong { color: #34d399; }
.bright-Dac, .bright-Loi { color: #60a5fa; }
.bright-Binh { color: #94a3b8; }
.bright-Bat, .bright-Ham { color: #f87171; }

.sihua-badge {
  font-size: 0.61rem;
  font-weight: 700;
  padding: 0 3px;
  border-radius: 3px;
  color: #fff;
  margin-left: 1px;
}

.sihua-Lộc { background: var(--red-lu); }
.sihua-Quyền { background: var(--green-quyen); }
.sihua-Khoa { background: var(--blue-khoa); }
.sihua-Kỵ { background: var(--purple-ky); }

.palace-middle {
  margin: 0.3rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
}

.palace-bottom {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 0.28rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  font-size: 0.72rem;
}

.palace-name-tag {
  font-weight: 700;
  color: var(--gold-light);
  font-size: 0.78rem;
}

.palace-stem-branch {
  color: var(--text-muted);
  font-size: 0.7rem;
}

.badge-Special {
  font-size: 0.6rem;
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 600;
}

.badge-than {
  background: rgba(239, 68, 68, 0.22);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.badge-lainhan {
  background: rgba(168, 85, 247, 0.22);
  color: #d8b4fe;
  border: 1px solid rgba(168, 85, 247, 0.4);
}

/* Bazi 4 Pillars Box in Center */
.bazi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid rgba(212, 175, 55, 0.2);
  border-radius: 6px;
  padding: 0.4rem;
  text-align: center;
  margin-bottom: 0.5rem;
}

.bazi-col-label {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.bazi-col-val {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--gold-light);
}

/* 13 Dimension Individual Tabs */
.dimension-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.3rem;
  margin-bottom: 0.8rem;
  max-height: 195px;
  overflow-y: auto;
  padding-right: 2px;
}

.dim-tab {
  font-size: 0.71rem;
  padding: 0.32rem 0.5rem;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}

.dim-tab:hover {
  border-color: rgba(229, 193, 88, 0.4);
  color: var(--text-main);
}

.dim-tab.active {
  background: rgba(229, 193, 88, 0.2);
  color: var(--gold-light);
  border-color: var(--gold-primary);
  font-weight: 600;
}

.insight-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.85rem;
  margin-bottom: 0.7rem;
}

.insight-card h4 {
  color: var(--gold-light);
  font-size: 0.86rem;
  margin-bottom: 0.4rem;
}

.insight-card p, .insight-card li {
  font-size: 0.8rem;
  color: #cbd5e1;
  margin-bottom: 0.35rem;
}

.quote-box {
  border-left: 3px solid var(--gold-primary);
  background: rgba(229, 193, 88, 0.07);
  padding: 0.55rem 0.7rem;
  border-radius: 0 6px 6px 0;
  font-style: italic;
  font-size: 0.78rem;
  color: #fde68a;
  margin-top: 0.4rem;
}

.solar-audit-box {
  background: rgba(6, 182, 212, 0.08);
  border: 1px solid rgba(6, 182, 212, 0.25);
  border-radius: 7px;
  padding: 0.5rem 0.65rem;
  font-size: 0.73rem;
  color: #a5f3fc;
  margin-top: 0.5rem;
}

@media print {
  .app-header, .insight-column {
    display: none !important;
  }
  .main-container {
    grid-template-columns: 1fr !important;
  }
}
