/* styles.css — SINH TỰ ĐỘNG: almanac-base.css (nguyên văn V0.1.1) + gate-extra.css */
:root{
    color-scheme: light;
    --paper:#EDE6D6;
    --paper-deep:#E3D9C4;
    --ink:#221E18;
    --ink-soft:#4A4235;
    --lacquer:#9E2B25;
    --lacquer-soft:#C24A3E;
    --lacquer-text:#7C231F;
    --brass:#A67A2E;
    --jade:#3F6B54;
    --jade-text:#2C4C3C;
    --jade-soft:#E3EEE8;
    --lacquer-tint:#F5E4E0;
    --line: rgba(38,34,28,0.14);
    --shadow: 0 1px 0 rgba(38,34,28,0.06);
  }
  *{box-sizing:border-box;}
  html,body{margin:0;padding:0; background:var(--paper);}
  body{
    background:
      radial-gradient(1200px 600px at 15% -10%, rgba(185,141,62,0.10), transparent 60%),
      radial-gradient(900px 500px at 110% 10%, rgba(158,43,37,0.06), transparent 55%),
      var(--paper);
    color:var(--ink);
    font-family:-apple-system,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif;
    line-height:1.5;
    min-height:100vh;
  }
  .wrap{
    max-width:760px;
    margin:0 auto;
    padding:48px 20px 90px;
    background-color:var(--paper);
  }

  /* ---------- Header ---------- */
  .brand-mark{
    width:180px;margin:0 auto 16px;
    display:flex;align-items:center;justify-content:center;
  }
  .brand-mark img{width:100%; height:auto; display:block;}
  header{text-align:center;margin-bottom:44px;}
  h1{
    font-family:Georgia,'Iowan Old Style','Times New Roman',serif;
    font-weight:600;
    font-size:clamp(30px,5vw,42px);
    margin:0 0 10px;
    letter-spacing:0.2px;
  }
  header p{
    margin:0;
    color:var(--ink-soft);
    font-size:15px;
    max-width:440px;
    margin:0 auto;
  }

  /* ---------- Form card ---------- */
  .card{
    background:#FBF8F1;
    border:1px solid var(--line);
    border-radius:6px;
    box-shadow: var(--shadow);
    padding:28px 26px;
  }
  .form-grid{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:18px 16px;
  }
  .field{display:flex;flex-direction:column;gap:7px;}
  .field.full{grid-column:1 / -1;}
  label{
    font-size:12.5px;
    font-weight:600;
    color:var(--ink-soft);
    text-transform:uppercase;
    letter-spacing:0.06em;
  }
  input[type=number]{
    font-family:-apple-system,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif;
    font-size:16px;
    padding:11px 12px;
    border:1px solid var(--line);
    border-radius:4px;
    background:#fff;
    color:var(--ink);
    width:100%;
  }
  input[type=number]:focus{
    outline:none;
    border-color:var(--brass);
    box-shadow:0 0 0 3px rgba(185,141,62,0.18);
  }
  .dir-seg{
    display:grid;
    grid-template-columns:repeat(3,1fr);
    gap:8px;
  }
  .dir-seg button{
    padding:11px 4px;
    background:#fff;
    border:1px solid var(--line);
    border-radius:4px;
    font-family:inherit;
    font-size:13px;
    font-weight:600;
    color:var(--ink-soft);
    cursor:pointer;
  }
  .dir-seg button.active{
    background:var(--ink);
    color:#fff;
    border-color:var(--ink);
  }
  .dir-seg button[data-d=""]{
    grid-column: 1 / -1;
    font-weight:500;
  }
  .seg{
    display:flex;
    border:1px solid var(--line);
    border-radius:4px;
    overflow:hidden;
  }
  .seg button{
    flex:1;
    padding:10px 8px;
    background:#fff;
    border:none;
    border-left:1px solid var(--line);
    font-family:inherit;
    font-size:15px;
    color:var(--ink-soft);
    cursor:pointer;
  }
  .seg button:first-child{border-left:none;}
  .seg button.active{
    background:var(--ink);
    color:#fff;
  }
  .submit-row{margin-top:22px;}
  button.primary{
    width:100%;
    padding:14px;
    background:var(--lacquer);
    color:#fff;
    border:none;
    border-radius:4px;
    font-family:inherit;
    font-size:16px;
    font-weight:600;
    cursor:pointer;
    letter-spacing:0.02em;
    transition:background 0.15s ease;
  }
  button.primary:hover{background:var(--lacquer-soft);}
  button.primary:focus-visible{outline:3px solid var(--brass); outline-offset:2px;}

  /* ---------- Results ---------- */
  #results{margin-top:36px; display:none;}
  .id-line{
    text-align:center;
    color:var(--ink-soft);
    font-size:14.5px;
    margin-bottom:22px;
    background-color:var(--paper);
  }
  .id-line b{color:var(--ink); font-weight:600;}

  .verdict{
    text-align:center;
    font-family:Georgia,'Iowan Old Style','Times New Roman',serif;
    font-style:italic;
    font-size:clamp(20px,3.6vw,26px);
    padding:22px 20px;
    border-radius:6px;
    margin-bottom:28px;
    border:1px solid var(--line);
  }
  .verdict.good{background:var(--jade-soft); color:var(--jade-text); border-color:rgba(44,76,60,0.28);}
  .verdict.bad{background:var(--lacquer-tint); color:var(--lacquer-text); border-color:rgba(124,35,31,0.25);}

  .criteria{
    display:grid;
    grid-template-columns:repeat(3,1fr);
    gap:14px;
    margin-bottom:24px;
  }
  .crit{
    background:#FBF8F1;
    border:1px solid var(--line);
    border-radius:6px;
    padding:16px 14px;
    text-align:center;
  }
  .crit .name{
    font-size:12px;
    text-transform:uppercase;
    letter-spacing:0.07em;
    color:var(--ink-soft);
    font-weight:700;
    margin-bottom:8px;
  }
  .crit .dot{
    width:10px;height:10px;border-radius:50%;
    margin:0 auto 8px;
  }
  .dot.good{background:var(--jade);}
  .dot.bad{background:var(--lacquer);}
  .crit .status{font-size:14.5px; font-weight:700; margin-bottom:5px;}
  .crit .detail{font-size:12.5px; color:var(--ink-soft); line-height:1.45;}

  .secondary-row{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:14px;
    margin-bottom:32px;
  }
  .sec{
    border:1px solid var(--line);
    border-radius:6px;
    padding:13px 15px;
    background:#FBF8F1;
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:10px;
  }
  .sec .label{font-size:12.5px; color:var(--ink-soft); font-weight:600;}
  .sec .val{font-size:13.5px; font-weight:600; text-align:right;}

  .table-title{
    font-family:Georgia,'Iowan Old Style','Times New Roman',serif;
    font-size:24px;
    font-weight:700;
    margin:0 0 14px;
    border-bottom:1px solid var(--line);
    padding-bottom:10px;
    background-color:var(--paper);
    color:var(--ink);
  }

  /* ---------- Mệnh & màu sắc ---------- */
  .menh-card{
    background:#FBF8F1;
    border:1px solid var(--line);
    border-radius:6px;
    padding:20px 22px;
    margin-bottom:28px;
  }
  .menh-head{
    display:flex;
    align-items:baseline;
    gap:10px;
    margin-bottom:14px;
    flex-wrap:wrap;
  }
  .menh-head .menh-name{
    font-family:Georgia,'Iowan Old Style','Times New Roman',serif;
    font-size:22px;
    font-weight:600;
  }
  .menh-head .menh-tag{
    font-size:12px;
    color:var(--ink-soft);
    background:var(--paper-deep);
    padding:3px 10px;
    border-radius:12px;
  }
  .color-row{display:flex; flex-wrap:wrap; gap:22px;}
  .color-group{flex:1; min-width:200px;}
  .color-group .cg-title{
    font-size:12px;
    text-transform:uppercase;
    letter-spacing:0.06em;
    font-weight:700;
    margin-bottom:9px;
  }
  .color-group.hop .cg-title{color:var(--jade-text);}
  .color-group.ky .cg-title{color:var(--lacquer-text);}
  .swatches{display:flex; flex-wrap:wrap; gap:8px;}
  .swatch{
    display:flex;
    align-items:center;
    gap:6px;
    background:#fff;
    border:1px solid var(--line);
    border-radius:16px;
    padding:5px 11px 5px 6px;
    font-size:12.5px;
    font-weight:600;
  }
  .swatch .dotc{width:14px; height:14px; border-radius:50%; border:1px solid rgba(0,0,0,0.15); flex-shrink:0;}

  /* ---------- Hướng nhà ---------- */
  .cungphi-line{
    text-align:center;
    font-size:14px;
    color:var(--ink-soft);
    margin-bottom:18px;
    background-color:var(--paper);
  }
  .cungphi-line b{color:var(--ink); font-weight:700;}
  .dir-grid{
    display:grid;
    grid-template-columns:repeat(4,1fr);
    gap:8px;
    margin-bottom:22px;
  }
  .dir-cell{
    text-align:center;
    border-radius:6px;
    padding:10px 4px;
    border:1px solid var(--line);
    font-size:11.5px;
  }
  .dir-cell.tot{background:var(--jade-soft); color:var(--jade-text); border-color:rgba(44,76,60,0.25);}
  .dir-cell.xau{background:var(--lacquer-tint); color:var(--lacquer-text); border-color:rgba(124,35,31,0.22);}
  .dir-cell .dname{font-weight:700; font-size:13px; margin-bottom:3px;}
  .dir-cell .dstar{font-weight:600;}
  .dir-cell.chosen{outline:2px solid var(--brass); outline-offset:2px;}
  .huong-verdict{
    border-radius:6px;
    padding:16px 18px;
    border:1px solid var(--line);
    margin-bottom:14px;
  }
  .huong-verdict.tot{background:var(--jade-soft); border-color:rgba(44,76,60,0.25);}
  .huong-verdict.xau{background:var(--lacquer-tint); border-color:rgba(124,35,31,0.22);}
  .huong-verdict .hv-title{font-weight:700; font-size:15.5px; margin-bottom:4px;}
  .huong-verdict.tot .hv-title{color:var(--jade-text);}
  .huong-verdict.xau .hv-title{color:var(--lacquer-text);}
  .huong-verdict .hv-detail{font-size:13px; color:var(--ink-soft); line-height:1.5;}

  /* ---------- Hướng bếp ---------- */
  .bep-note{
    font-size:12.5px;
    color:var(--ink-soft);
    margin:0 0 16px;
    background-color:var(--paper);
    line-height:1.55;
  }
  table{width:100%; border-collapse:collapse; font-size:13.5px;}
  th{
    text-align:left;
    font-size:11px;
    text-transform:uppercase;
    letter-spacing:0.05em;
    color:var(--ink-soft);
    padding:0 8px 8px;
    font-weight:700;
  }
  td{padding:11px 8px; border-top:1px solid rgba(255,255,255,0.6);}
  tr.good-row{background:var(--jade-soft);}
  tr.bad-row{background:var(--lacquer-tint);}
  tr.good-row td:first-child{border-left:3px solid var(--jade); padding-left:11px;}
  tr.bad-row td:first-child{border-left:3px solid var(--lacquer); padding-left:11px;}
  tr.good-row td.result{color:var(--jade-text); font-weight:700;}
  tr.bad-row td.result{color:var(--lacquer-text); font-weight:700;}
  td.star{font-weight:700;}

  .good-ages-title{
    font-family:Georgia,'Iowan Old Style','Times New Roman',serif;
    font-size:24px;
    font-weight:700;
    margin:0 0 6px;
  }
  .good-ages-sub{
    font-size:12.5px;
    color:var(--ink-soft);
    margin:0 0 16px;
    background-color:var(--paper);
  }
  .age-chips{
    display:flex;
    flex-wrap:wrap;
    gap:8px;
    margin-bottom:32px;
  }
  .age-chip{
    background:var(--jade-soft);
    border:1px solid rgba(44,76,60,0.28);
    color:var(--jade-text);
    border-radius:20px;
    padding:7px 13px;
    font-size:13px;
    font-weight:700;
    white-space:nowrap;
  }
  .age-chip small{
    display:block;
    font-weight:600;
    font-size:11px;
    color:var(--ink-soft);
    margin-top:1px;
  }

  .foot-note{
    margin-top:30px;
    font-size:12px;
    color:var(--ink-soft);
    text-align:center;
    line-height:1.6;
    background-color:var(--paper);
  }

  .copyright{
    margin-top:22px;
    font-size:11.5px;
    color:var(--ink-soft);
    text-align:center;
    line-height:1.6;
    background-color:var(--paper);
  }
  .footer-brand{
    margin-top:36px;
    padding-top:24px;
    border-top:1px solid var(--line);
    text-align:center;
    background-color:var(--paper);
  }
  .footer-brand .credit{
    font-size:clamp(16px, 2.2vw, 20px);
    font-weight:700;
    line-height:1.6;
    color:var(--ink);
    letter-spacing:0.02em;
  }

  @media (max-width:520px){
    .form-grid{grid-template-columns:1fr;}
    .criteria{grid-template-columns:1fr;}
    .secondary-row{grid-template-columns:1fr;}
    table{font-size:12.5px;}
    th:nth-child(2), td:nth-child(2){display:none;}
  }

  /* Chặn cứng: một số webview nội bộ tự áp dark mode bất kể color-scheme,
     buộc lại đúng theme sáng cho toàn bộ vùng chữ + nền chính */
  @media (prefers-color-scheme: dark){
    html, body, .wrap, h1, h2, p, .id-line, .table-title, .good-ages-sub,
    .foot-note, .cungphi-line, header p, .copyright, .footer-brand, .credit,
    .app-limit-note, .verdict-note, .section-note, .version-line{
      background-color:var(--paper) !important;
      color:var(--ink) !important;
    }
    .id-line, .good-ages-sub, .foot-note, .cungphi-line, header p, .copyright, .credit,
    .app-limit-note, .verdict-note, .section-note, .version-line{
      color:var(--ink-soft) !important;
    }
  }

  /* ---------- V0.1.1 additions ---------- */
  .app-limit-note{
    background:#FBF3E6;
    border:1px solid var(--brass);
    border-radius:6px;
    padding:12px 14px;
    font-size:12.5px;
    line-height:1.55;
    color:var(--ink-soft);
    margin:0 0 20px;
  }
  #results .app-limit-note{margin:0 0 22px;}
  .verdict-note{
    font-size:12.5px;
    color:var(--ink-soft);
    line-height:1.55;
    margin:-16px 0 26px;
    text-align:center;
  }
  .section-note{
    font-size:12.5px;
    color:var(--ink-soft);
    line-height:1.55;
    margin:0 0 14px;
    background-color:var(--paper);
  }
  .bep-list{display:flex; flex-direction:column; gap:8px;}
  .bep-row{
    display:flex;
    flex-wrap:wrap;
    align-items:baseline;
    gap:6px 12px;
    background:#FBF8F1;
    border:1px solid var(--line);
    border-radius:6px;
    padding:11px 14px;
    font-size:13px;
  }
  .bep-row-top{border-color:rgba(44,76,60,0.4); background:var(--jade-soft);}
  .bep-row .bep-dir{font-weight:700;}
  .bep-row .bep-flag{
    font-size:10.5px; font-weight:700; text-transform:uppercase; letter-spacing:0.04em;
    color:var(--jade-text); border:1px solid rgba(44,76,60,0.4); border-radius:8px; padding:1px 6px; margin-left:4px;
  }
  .bep-row .bep-star{color:var(--jade-text); font-weight:600;}
  .bep-row .bep-face{flex-basis:100%; color:var(--ink-soft); font-size:12px;}
  tr.oor-row td{color:var(--ink-soft); font-style:italic;}
  tr.oor-row td.result{font-weight:600;}
  .version-line{
    margin-top:10px;
    font-size:11.5px;
    color:var(--ink-soft);
    letter-spacing:0.02em;
  }
  #results:focus{outline:none;}
  .sr-only{
    position:absolute !important;
    width:1px;height:1px;
    padding:0;margin:-1px;
    overflow:hidden;
    clip:rect(0 0 0 0);
    white-space:nowrap;border:0;
  }
  .seg button[aria-checked="true"]{background:var(--ink); color:#fff;}
  .dir-seg button[aria-checked="true"]{background:var(--ink); color:#fff; border-color:var(--ink);}

/* gate-extra.css — bổ sung cho lớp cấp phép + trạng thái offline.
 * Nối SAU almanac-base.css (nguyên văn V0.1.1) khi build styles.css. */

#app[hidden] { display: none !important; }

/* Thanh trạng thái giấy phép (trên cùng phần tra cứu) */
.status-bar {
  max-width: 760px;
  margin: 0 auto 10px;
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  align-items: baseline;
  justify-content: space-between;
  background: var(--jade-soft);
  border: 1px solid rgba(44, 76, 60, 0.28);
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--jade-text);
}
.status-bar .lic-btn {
  background: none;
  border: 1px solid rgba(44, 76, 60, 0.5);
  color: var(--jade-text);
  border-radius: 6px;
  padding: 5px 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.status-bar .lic-btn:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; }

.offline-state {
  max-width: 760px;
  margin: 0 auto 22px;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
}
.offline-state.ok { background: var(--jade-soft); color: var(--jade-text); border: 1px solid rgba(44, 76, 60, 0.28); }
.offline-state.pending { background: #FBF3E6; color: var(--ink-soft); border: 1px solid var(--brass); }
.offline-state.warn { background: var(--lacquer-tint); color: var(--lacquer-text); border: 1px solid rgba(124, 35, 31, 0.35); }

/* Màn hình khoá / nhập giấy phép — phủ toàn màn hình */
.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--paper);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.gate[hidden] { display: none; }
.gate-inner {
  max-width: 460px;
  margin: 0 auto;
  padding: 44px 22px 60px;
}
.gate h1 {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-weight: 600;
  font-size: clamp(22px, 5vw, 30px);
  margin: 0 0 6px;
}
.gate .gate-sub { color: var(--ink-soft); font-size: 13px; margin: 0 0 22px; }
.gate-card {
  background: #FBF8F1;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 22px 20px;
}
.gate-card h2 { font-size: 16px; margin: 0 0 6px; }
.gate-card p.gate-msg { font-size: 13.5px; color: var(--ink-soft); line-height: 1.55; margin: 0 0 16px; }

.gate-demo {
  background: var(--lacquer-tint);
  color: var(--lacquer-text);
  border: 1px solid rgba(124, 35, 31, 0.4);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
  margin-bottom: 16px;
}
.gate-demo[hidden] { display: none; }

.gate-field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.gate-field label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.06em; }
.gate input[type="file"] {
  font: inherit;
  font-size: 14px;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  width: 100%;
}
.gate textarea {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  width: 100%;
  min-height: 96px;
  resize: vertical;
}
.gate .gate-or { text-align: center; font-size: 11.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.08em; margin: 4px 0 12px; }
.gate .btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.gate button.primary {
  width: auto;
  flex: 1;
  min-width: 140px;
  padding: 12px 16px;
  background: var(--lacquer);
  color: #fff;
  border: none;
  border-radius: 4px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.gate button.primary:hover { background: var(--lacquer-soft); }
.gate button.ghost {
  padding: 12px 16px;
  background: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  font: inherit;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.gate button:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; }
.gate .gate-status {
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--lacquer-text);
  min-height: 1.2em;
  line-height: 1.5;
}
.gate .gate-help {
  margin-top: 22px;
  font-size: 11.5px;
  color: var(--ink-soft);
  line-height: 1.6;
}

@media (prefers-color-scheme: dark) {
  .gate, .gate h1, .gate .gate-sub, .gate-card, .gate-card h2, .gate-card p, .gate .gate-help,
  .status-bar, .offline-state {
    background-color: var(--paper) !important;
    color: var(--ink) !important;
  }
  .gate .gate-sub, .gate-card p.gate-msg, .gate .gate-help, .offline-state.pending { color: var(--ink-soft) !important; }
}

/* V0.4 — gợi ý miền năm khi ô "Năm dự định xây" để trống do năm thiết bị ngoài 1900–2099 */
.year-hint { font-weight: 500; color: var(--lacquer-text); text-transform: none; letter-spacing: 0; }
