/* ===========================================================================
   CantoBuddy — Daily Tools
   Scoped styles for /tools. Inherits the shared design tokens from styles.css
   (--c-primary, --c-secondary-ink, --c-surface, --radius, ...).
   Every class here is prefixed `t-` (or is a local .btn-ghost / .tools-* )
   so nothing can leak into the main SPA.
   =========================================================================== */

/* ---- Header pill ---- */
.tools-pill {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--c-primary-tint);
  color: var(--c-primary);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* The logo is an <a> here, not a <div> with onclick. Keep it unvisited-blue
   free and visually identical to the SPA logo. */
a.logo { text-decoration: none; color: inherit; }
a.logo:hover .logo-text { color: var(--c-primary-dark); }

/* ---- Intro ---- */
.tools-hero {
  background: linear-gradient(135deg, #fff1f2 0%, #ffffff 70%);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  margin-bottom: 18px;
}
.tools-hero h1 {
  font-size: 1.45rem;
  line-height: 1.25;
  font-weight: 800;
  color: var(--c-text);
  margin-bottom: 8px;
}
.tools-hero p {
  font-size: 0.93rem;
  line-height: 1.6;
  color: var(--c-text-soft);
}

/* ---- Tool tabs ---- */
.tool-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 18px;
}
.tool-tab {
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  padding: 10px 4px;
  min-height: 64px;
  cursor: pointer;
  font-family: var(--font-en);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--c-text-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.tool-tab:hover { border-color: var(--c-primary); }
.tool-tab.active {
  background: var(--c-primary-tint);
  border-color: var(--c-primary);
  color: var(--c-primary);
}
.tool-tab-ic { font-size: 1.3rem; line-height: 1; }

/* ---- Panels ---- */
.tool-panel {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 20px 16px;
  box-shadow: 0 2px 8px var(--c-shadow);
  animation: t-fade 0.22s ease;
}
@keyframes t-fade { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.tool-head h2 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--c-text);
  margin-bottom: 6px;
  line-height: 1.3;
}
.tool-sub {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--c-text-soft);
  margin-bottom: 18px;
}
.tool-note {
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--c-text-soft);
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed var(--c-border);
}

/* ---- Shared local controls ---- */
.btn-ghost {
  background: var(--c-surface);
  color: var(--c-primary);
  border: 1.5px solid var(--c-border);
  font-size: 0.85rem;
  padding: 9px 14px;
  border-radius: 10px;
  min-height: 44px;
}
.btn-ghost:hover { border-color: var(--c-primary); background: var(--c-primary-tint); }

/* min-width:0 matters on iOS Safari. A native date input has a large intrinsic
   min-content width and a grid item defaults to min-width:auto, so the field
   refuses to shrink and pushes the neighbouring column over it (seen on a real
   iPhone at 390px). The contract form is also single-column on phones now —
   a date picker wants the full width, not half of it. */
.t-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
/* The label text only — .t-date is also a <span> child but is a control box,
   not a label, and must not inherit the bold small label type. */
.t-field > span:not(.t-date) {
  font-size: 0.83rem;
  font-weight: 700;
  color: var(--c-text);
}
.t-field > span em {
  font-style: normal;
  font-weight: 500;
  color: var(--c-text-soft);
  font-size: 0.76rem;
}
.t-field select,
.search-row input {
  font-family: var(--font-en);
  font-size: 0.95rem;
  color: var(--c-text);
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  border-radius: 10px;
  padding: 11px 12px;
  min-height: var(--tap);
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

/* iOS Safari renders input[type=date] with a NATIVE control whose own
   min-content width (and, with a Chinese locale, the long "2026年11月7日"
   text) ignores width:100% / min-width:0 on the input. The result on a real
   iPhone: the painted rounded box was ~25px wider than the select beside it
   and poked through the white card's right border.

   So the input no longer owns its box. This wrapper owns the border, padding,
   radius and background, and clips anything the native control paints beyond
   them. Inside, the input has NO padding and NO border — with those gone,
   content-box vs border-box no longer changes its width, and overflow:hidden
   is the final guarantee that the visible edge can never exceed the card. */
.t-date {
  display: flex;
  align-items: center;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  overflow: hidden;
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  border-radius: 10px;
}
.t-date input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  flex: 1 1 0;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: calc(var(--tap) - 3px);
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  outline: none;
  background: transparent;
  color: var(--c-text);
  font-family: var(--font-en);
  font-size: 0.95rem;
  line-height: 1.4;
  text-align: left;
}
/* WebKit's shadow date field keeps a -webkit-min-content width of its own. */
.t-date input[type="date"]::-webkit-datetime-edit,
.t-date input[type="date"]::-webkit-date-and-time-value {
  min-width: 0;
  text-align: left;
}
.t-date:focus-within {
  outline: 2px solid var(--c-primary);
  outline-offset: 1px;
  border-color: var(--c-primary);
}
.t-field select:focus,
.search-row input:focus {
  outline: 2px solid var(--c-primary);
  outline-offset: 1px;
  border-color: var(--c-primary);
}

/* ===========================================================================
   TOOL 1 — Recipe Translator
   =========================================================================== */
.search-row { margin-bottom: 12px; }
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 18px;
}
.chip-btn {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  color: var(--c-text-soft);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 34px;
  font-family: var(--font-en);
}
.chip-btn:hover { border-color: var(--c-primary); color: var(--c-primary); background: var(--c-primary-tint); }

.recipe-results { display: flex; flex-direction: column; gap: 12px; }
.recipe-card {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px;
  background: linear-gradient(180deg, #fff 0%, var(--c-bg) 100%);
}
.recipe-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.recipe-names { min-width: 0; }
.recipe-query {
  font-size: 0.78rem;
  color: var(--c-text-soft);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.recipe-en { font-size: 0.98rem; font-weight: 700; color: var(--c-text); margin-top: 2px; }
.recipe-id { font-size: 0.82rem; color: var(--c-text-soft); margin-top: 2px; }
.recipe-emoji { font-size: 1.9rem; line-height: 1; }

.recipe-yue {
  font-family: var(--font-cn);
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--c-primary);
  line-height: 1.35;
  margin: 12px 0 2px;
}
.recipe-jyut { font-size: 0.88rem; color: var(--c-secondary-ink); font-weight: 600; }

.recipe-phrase {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--c-primary-tint);
  border-left: 3px solid var(--c-primary);
}
.recipe-phrase-label { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; color: var(--c-primary); }
.recipe-phrase-yue { font-family: var(--font-cn); font-size: 1.15rem; font-weight: 600; color: var(--c-text); margin-top: 4px; line-height: 1.5; }
.recipe-phrase-en { font-size: 0.8rem; color: var(--c-text-soft); margin-top: 2px; }

.audio-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.audio-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--c-primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 46px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-en);
}
.audio-btn:hover { background: var(--c-primary-dark); }
.audio-btn.secondary { background: var(--c-secondary-ink); }
.audio-btn.secondary:hover { background: #14594f; }
.audio-btn.speaking { animation: t-pulse 0.8s ease-in-out infinite; }
@keyframes t-pulse { 50% { opacity: 0.65; } }

.tts-warning {
  margin-top: 10px;
  font-size: 0.78rem;
  color: #8a4b00;
  background: #fff5e6;
  border: 1px solid #f2d9a8;
  border-radius: 8px;
  padding: 9px 11px;
  line-height: 1.5;
}
.empty-state {
  text-align: center;
  padding: 26px 14px;
  color: var(--c-text-soft);
  font-size: 0.9rem;
  line-height: 1.6;
}
.empty-state .big { font-size: 2rem; display: block; margin-bottom: 8px; }

/* ===========================================================================
   TOOL 2 — Holiday & Leave Tracker
   =========================================================================== */
.leave-settings {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  background: var(--c-bg);
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
  margin-bottom: 18px;
}
.leave-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.cal-head strong { font-size: 1.02rem; color: var(--c-text); }
.cal-nav {
  width: 44px; height: 44px;
  border: 1.5px solid var(--c-border);
  background: var(--c-surface);
  border-radius: 10px;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--c-primary);
  cursor: pointer;
}
.cal-nav:hover { border-color: var(--c-primary); background: var(--c-primary-tint); }

.cal-weekdays,
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-weekdays { margin-bottom: 6px; }
.cal-weekdays span {
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--c-text-soft);
  text-transform: uppercase;
}
.cal-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--c-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--c-text);
  cursor: pointer;
  padding: 0;
  font-family: var(--font-en);
}
.cal-cell.blank { background: transparent; cursor: default; }
.cal-cell:hover:not(.blank) { border-color: var(--c-primary); }
.cal-cell.is-holiday { background: #e1f5ee; color: var(--c-secondary-ink); }
.cal-cell.is-rest { background: #eef1f6; color: var(--c-text-soft); }
.cal-cell.is-leave { background: #fde8ea; color: var(--c-primary-dark); }
.cal-cell.is-today { border: 2px solid var(--c-primary); }
.cal-cell .cal-mark { font-size: 0.62rem; line-height: 1; margin-top: 2px; }
.cal-cell .cal-hol-name {
  font-size: 0.52rem;
  line-height: 1.1;
  text-align: center;
  color: var(--c-secondary-ink);
  padding: 0 1px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  list-style: none;
  margin-top: 14px;
  font-size: 0.75rem;
  color: var(--c-text-soft);
}
.cal-legend li { display: flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.dot-holiday { background: #e1f5ee; border: 1px solid var(--c-secondary-ink); }
.dot-rest { background: #eef1f6; border: 1px solid #c9cfda; }
.dot-leave { background: #fde8ea; border: 1px solid var(--c-primary); }
.dot-today { background: #fff; border: 2px solid var(--c-primary); }

.holiday-list { margin-top: 16px; }
.holiday-list h3 { font-size: 0.9rem; font-weight: 800; margin-bottom: 8px; color: var(--c-text); }
.holiday-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--c-border);
  font-size: 0.82rem;
}
.holiday-row .hdate { font-weight: 800; color: var(--c-secondary-ink); white-space: nowrap; min-width: 92px; }
.holiday-row .hname { color: var(--c-text); }
.holiday-row .hzh { color: var(--c-text-soft); font-family: var(--font-cn); }

/* ===========================================================================
   TOOL 3 — Contract & Visa Countdown
   =========================================================================== */
/* Mobile-first: ONE column. Four full-width fields stack cleanly, and no
   native date control ever has to fight a sibling for ~150px. Two columns
   only come back at >=560px, where each field gets ~300px (see below). */
.contract-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 18px;
}
.contract-form .btn-ghost { grid-column: 1 / -1; }
.contract-empty {
  text-align: center;
  padding: 30px 16px;
  color: var(--c-text-soft);
  font-size: 0.9rem;
  background: var(--c-bg);
  border-radius: var(--radius);
  border: 1px dashed var(--c-border);
}

.countdown-cards { display: grid; grid-template-columns: 1fr; gap: 10px; }
.cd-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
}
.cd-card.urgent { border-color: var(--c-primary); background: var(--c-primary-tint); }
.cd-card.warn { border-color: var(--c-accent); background: #fff8ef; }
.cd-ic { font-size: 1.7rem; flex-shrink: 0; }
.cd-body { flex: 1; min-width: 0; }
.cd-label { font-size: 0.78rem; font-weight: 700; color: var(--c-text-soft); text-transform: uppercase; letter-spacing: 0.03em; }
.cd-date { font-size: 0.85rem; color: var(--c-text); margin-top: 2px; }
.cd-days { font-size: 1.6rem; font-weight: 800; color: var(--c-primary); line-height: 1.1; white-space: nowrap; }
.cd-days small { display: block; font-size: 0.7rem; font-weight: 600; color: var(--c-text-soft); text-align: right; }
.cd-card.warn .cd-days { color: #a8641a; }
.cd-card.ok .cd-days { color: var(--c-secondary-ink); }

.reminders { margin-top: 18px; }
.reminders h3 { font-size: 0.92rem; font-weight: 800; margin-bottom: 10px; color: var(--c-text); }
.rem-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--c-border);
  margin-bottom: 8px;
  font-size: 0.84rem;
  line-height: 1.5;
}
.rem-row.due { border-color: var(--c-primary); background: var(--c-primary-tint); }
.rem-row .rem-ic { font-size: 1.1rem; }
.rem-row .rem-title { font-weight: 700; color: var(--c-text); }
.rem-row .rem-when { color: var(--c-text-soft); font-size: 0.78rem; }

.notify-banner {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #fff8ef;
  border: 1px solid #f2d9a8;
  font-size: 0.84rem;
  color: #6b4a00;
  line-height: 1.5;
}
.notify-banner button {
  margin-top: 8px;
  background: var(--c-accent);
  color: #3a2600;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
  min-height: 40px;
  font-size: 0.82rem;
}

/* ===========================================================================
   TOOL 4 — Emergency Directory
   =========================================================================== */
.emergency-list { display: flex; flex-direction: column; gap: 12px; }
.em-group-title {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-secondary-ink);
  margin: 6px 0 2px;
  padding-left: 2px;
}
.em-card {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  background: var(--c-surface);
}
.em-card.emergency { border-color: var(--c-primary); background: var(--c-primary-tint); }
.em-ic { font-size: 1.6rem; flex-shrink: 0; width: 40px; text-align: center; }
.em-info { flex: 1; min-width: 160px; }
.em-name { font-size: 0.95rem; font-weight: 800; color: var(--c-text); }
.em-desc { font-size: 0.8rem; color: var(--c-text-soft); line-height: 1.45; margin-top: 2px; }
.em-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.em-call {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--c-primary);
  color: #fff;
  text-decoration: none;
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 46px;
  font-weight: 800;
  font-size: 0.92rem;
  white-space: nowrap;
}
.em-call:hover { background: var(--c-primary-dark); }
.em-call.teal { background: var(--c-secondary-ink); }
.em-call.teal:hover { background: #14594f; }
.em-web {
  display: inline-flex;
  align-items: center;
  color: var(--c-secondary-ink);
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: underline;
  padding: 8px 4px;
}

/* ---- Bottom nav: anchors inherit .nav-btn styling ---- */
.bottom-nav a.nav-btn { text-decoration: none; }
.bottom-nav a.nav-btn:hover { color: var(--c-primary); }
.bottom-nav a.nav-btn .nav-icon svg { width: 24px; height: 24px; }

/* ---- Responsive ---- */
@media (max-width: 380px) {
  .tool-tab { font-size: 0.7rem; }
  .cal-cell .cal-hol-name { display: none; }
}
@media (min-width: 560px) {
  .countdown-cards { grid-template-columns: 1fr 1fr; }
  /* Two columns are safe once each field has ~300px. Reserve two lines for
     every label so the "Visa expiry (optional — ...)" copy, which wraps to
     three lines, cannot push its input lower than the one beside it. */
  .contract-form { grid-template-columns: 1fr 1fr; }
  .contract-form .t-field > span { min-height: 2.6em; }
}
