/* =============================================
   KIN ORACLE — App Stylesheet
   ============================================= */

:root {
  --color-bg:        #fafaf8;
  --color-surface:   #ffffff;
  --color-border:    rgba(0,0,0,0.08);
  --color-ink:       #1a1714;
  --color-ink-muted: #6b6560;
  --color-ink-light: #a09890;
  --color-gold:      #b8965a;
  --color-gold-light:#d4b07a;
  --color-gold-pale: #f5edd8;
  --color-sidebar:   #1a1714;
  --color-danger:    #c0392b;

  --font-serif: 'Cormorant Garamond', 'Noto Serif JP', Georgia, serif;
  --font-sans:  'Noto Sans JP', 'Hiragino Kaku Gothic ProN', sans-serif;
  --font-en:    'Inter', 'Helvetica Neue', system-ui, -apple-system, 'Noto Sans JP', sans-serif;
  --font-num:   'Inter', 'Helvetica Neue', system-ui, -apple-system, sans-serif;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
  --sidebar-w: 220px;
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--color-ink);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  padding: 2rem;
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 3rem 2.5rem;
  width: 100%;
  max-width: 420px;
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}
.login-logo__symbol {
  display: block;
  font-family: var(--font-en);
  font-size: 1.4rem;
  color: var(--color-gold);
  margin-bottom: 0.25rem;
}
.login-logo__name {
  font-family: var(--font-en);
  font-size: 1.5rem;
  letter-spacing: 0.18em;
  color: var(--color-ink);
}

.login-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 1.75rem;
}
.login-tab {
  flex: 1;
  padding: 0.6rem;
  font-size: 0.88rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  color: var(--color-ink-muted);
  transition: all 0.2s;
  margin-bottom: -1px;
}
.login-tab.active {
  color: var(--color-gold);
  border-bottom-color: var(--color-gold);
  font-weight: 500;
}

.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-form label {
  font-size: 0.82rem;
  color: var(--color-ink-muted);
  display: block;
  margin-bottom: 0.3rem;
}
.login-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-ink);
  transition: border-color 0.2s;
}
.login-form input:focus {
  outline: none;
  border-color: var(--color-gold);
}
.login-form .btn-submit {
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, var(--color-gold), var(--color-gold-light));
  color: #fff;
  border: none;
  border-radius: var(--radius-full);
  font-size: 0.95rem;
  font-family: var(--font-sans);
  letter-spacing: 0.06em;
  cursor: pointer;
  margin-top: 0.5rem;
  transition: opacity 0.2s;
}
.login-form .btn-submit:hover { opacity: 0.88; }
.login-error {
  font-size: 0.82rem;
  color: var(--color-danger);
  text-align: center;
  min-height: 1.2em;
}
.login-note {
  font-size: 0.78rem;
  color: var(--color-ink-light);
  text-align: center;
  margin-top: 1.25rem;
  line-height: 1.6;
}

/* ── App layout (sidebar + main) ── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--color-sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar__logo {
  padding: 1.75rem 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar__logo-symbol {
  display: block;
  font-family: var(--font-en);
  font-size: 0.9rem;
  color: var(--color-gold);
  margin-bottom: 0.15rem;
}
.sidebar__logo-name {
  font-family: var(--font-en);
  font-size: 1rem;
  letter-spacing: 0.15em;
}

.sidebar__nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}
.sidebar__section-label {
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  padding: 0.75rem 1.5rem 0.3rem;
}
.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 1.5rem;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 0.88rem;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.sidebar__link:hover {
  color: #fff;
  background: rgba(255,255,255,0.05);
}
.sidebar__link.active {
  color: var(--color-gold-light);
  border-left-color: var(--color-gold);
  background: rgba(184,150,90,0.1);
}
.sidebar__link-icon { font-size: 1rem; width: 1.2rem; text-align: center; }

.sidebar__footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar__logout {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: rgba(255,255,255,0.45);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem 0;
  width: 100%;
  transition: color 0.15s;
}
.sidebar__logout:hover { color: rgba(255,255,255,0.8); }
.sidebar__lp-link {
  display: block;
  font-size: 0.78rem;
  color: var(--color-gold);
  text-decoration: none;
  padding: 0.4rem 0;
  margin-bottom: 0.25rem;
  opacity: 0.85;
  transition: opacity 0.15s;
}
.sidebar__lp-link:hover { opacity: 1; }

.app-main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.app-header__title {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 400;
  letter-spacing: 0.04em;
}
.app-header__user {
  font-size: 0.82rem;
  color: var(--color-ink-muted);
}

.app-content {
  padding: 2rem;
  max-width: 960px;
  width: 100%;
}

/* ── Cards & Forms ── */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
}
.card__title {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 400;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-ink);
  letter-spacing: 0.03em;
}

.form-row {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group label {
  font-size: 0.8rem;
  color: var(--color-ink-muted);
  letter-spacing: 0.02em;
}
.form-group input, .form-group select {
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-ink);
  transition: border-color 0.2s;
  min-width: 80px;
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--color-gold);
}
.form-group input[type="number"] { width: 90px; }
.form-group input[type="text"] { width: 140px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 1.5rem;
  border-radius: var(--radius-full);
  font-size: 0.88rem;
  font-family: var(--font-sans);
  letter-spacing: 0.04em;
  cursor: pointer;
  border: none;
  transition: opacity 0.2s, transform 0.1s;
  text-decoration: none;
}
.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.98); }
.btn--gold {
  background: linear-gradient(135deg, var(--color-gold), var(--color-gold-light));
  color: #fff;
}
.btn--outline {
  background: transparent;
  border: 1.5px solid var(--color-gold);
  color: var(--color-gold);
}
.btn--danger {
  background: var(--color-danger);
  color: #fff;
}
.btn--sm { padding: 0.45rem 1rem; font-size: 0.8rem; }

/* ── Result table ── */
.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin-top: 1rem;
}
.result-table th {
  background: var(--color-bg);
  color: var(--color-ink-muted);
  font-weight: 400;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  padding: 0.6rem 0.85rem;
  text-align: left;
  border-bottom: 2px solid var(--color-border);
}
.result-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.result-table tr:last-child td { border-bottom: none; }
.result-table tr:hover td { background: var(--color-bg); }

/* KIN badge */
.kin-badge {
  display: inline-block;
  font-family: var(--font-en);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-gold);
  letter-spacing: 0.04em;
}

/* Seal color chips */
.seal-chip {
  display: inline-block;
  padding: 0.18em 0.65em;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 500;
}
.seal-red    { background: #fde8e8; color: #c0392b; }
.seal-white  { background: #f0f0f0; color: #555; border: 1px solid #ddd; }
.seal-blue   { background: #e8f0fd; color: #2c5fad; }
.seal-yellow { background: #fdf8e1; color: #9c7a0a; }

/* Solid seal background (for cells and table rows) */
.seal-bg-red    { background: #f8b7b7 !important; color: #4a1010 !important; }
.seal-bg-white  { background: #ffffff !important; color: #333 !important; border: 1px solid #d0d0d0 !important; }
.seal-bg-blue   { background: #b6cef9 !important; color: #0e2a5c !important; }
.seal-bg-yellow { background: #fde68a !important; color: #5c4310 !important; }
.kuro-row td    { background: #1a1714 !important; color: #f0e0b8 !important; }
/* KIN番号セルのみ黒背景・白文字（年表鑑定用） */
.kuro-kin-cell  { background: #1a1714 !important; color: #ffffff !important; font-weight: 700; }
.kuro-row td .seal-bg-red,
.kuro-row td .seal-bg-white,
.kuro-row td .seal-bg-blue,
.kuro-row td .seal-bg-yellow { color: #4a1010 !important; }

/* === PDF page rendering (fixed A4 px dimensions, html2canvas target) === */
.pdf-page {
  background: #fff;
  color: #1a1714;
  font-family: 'Noto Sans JP', sans-serif;
  box-sizing: border-box;
  padding: 10px 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.pdf-page--landscape { width: 1123px; height: 794px; }
.pdf-page--portrait  { width: 794px;  height: 1123px; }
.pdf-page__header {
  display: flex; align-items: baseline; justify-content: space-between;
  border-bottom: 2px solid #b8965a;
  padding-bottom: 3px; margin-bottom: 5px;
}
.pdf-page__title { font-size: 16px; font-weight: 500; }
.pdf-page__brand { font-family: 'Cormorant Garamond', serif; color: #b8965a; font-size: 13px; letter-spacing: 0.1em; }
.pdf-page__footer { margin-top: auto; padding-top: 4px; font-size: 9px; color: #888; display: flex; justify-content: space-between; }
.pdf-num { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 600; }

/* ===== Kankei PDF grid (3 col x 2 row, fixed cell size) ===== */
.pdf-kankei-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 5px;
}
.pdf-kankei-grid--half { /* top half only — bottom row stays empty */ }
.pdf-kankei-grid--half > * { grid-row: 1; }
.pdf-kankei-grid > .res-card {
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  margin: 0;
  padding: 4px 5px 10px 5px;
}
.pdf-kankei-grid .res-info--mirror {
  grid-template-columns: auto 1fr;
  padding: 0.16rem 0.32rem;
  font-size: 0.56rem;
  line-height: 1.25;
  gap: 0.08rem 0.32rem;
}

/* === Compact cross cells to fit 2 rows on A4 landscape === */
.pdf-kankei-grid .cross {
  grid-template-rows: repeat(3, 30px);
  height: 96px;
  gap: 3px;
}
.pdf-kankei-grid .cross.cross--no-guide {
  grid-template-rows: repeat(2, 30px);
  height: 63px;
}
.pdf-kankei-grid .cross__cell { font-size: 0.6rem; padding: 0.1rem 0.05rem; line-height: 1.15; }
.pdf-kankei-grid .cross__cell--center { font-size: 0.7rem; line-height: 1.15; }
.pdf-kankei-grid .cross__role { font-size: 0.48rem; }
.pdf-kankei-grid .cross-wrap { gap: 3px; }
.pdf-kankei-grid .cross-block__label { margin-bottom: 1px; font-size: 0.55rem; }
.pdf-kankei-grid .cross-block { margin-bottom: 0; }
.pdf-kankei-grid .res-card__top { margin-bottom: 3px; }
.pdf-kankei-grid .res-mid { margin-bottom: 3px; gap: 4px; grid-template-columns: 0.85fr 1fr; }
.pdf-kankei-grid .res-info { padding: 0.18rem 0.3rem; font-size: 0.56rem; line-height: 1.3; }
.pdf-kankei-grid .res-bd { padding: 0.1rem 0.3rem; gap: 0.04rem; }
.pdf-kankei-grid .res-age { padding: 0.1rem 0.3rem; min-width: 4.5rem; }
.pdf-kankei-grid .stat-table { font-size: 0.62rem; }
.pdf-kankei-grid .stat-table th, .pdf-kankei-grid .stat-table td { padding: 2px 3px; }

/* ===== Soshiki / Nenpyo PDF table styling ===== */
.pdf-table { width: 100%; border-collapse: collapse; font-size: 11px; font-family: 'Noto Sans JP', sans-serif; table-layout: fixed; }
.pdf-table th { background: #1a1714; color: #f0e0b8; font-weight: 500; padding: 5px 4px; border: 1px solid #1a1714; text-align: center; font-size: 10px; height: 22px; box-sizing: border-box; }
.pdf-table td { padding: 4px 4px; border: 1px solid #d4d4d4; text-align: center; vertical-align: middle; background: #fff; font-size: 10.5px; height: 24px; box-sizing: border-box; line-height: 1.2; overflow: hidden; }
.pdf-table td.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 600; font-size: 12px; }
.pdf-table tr.kuro-row td { background: #1a1714 !important; color: #f0e0b8 !important; }

.pdf-summary-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.pdf-summary-table th { background: #1a1714; color: #f0e0b8; padding: 6px; border: 1px solid #1a1714; font-weight: 500; font-size: 10px; }
.pdf-summary-table td { padding: 7px; border: 1px solid #d4d4d4; text-align: center; font-weight: 500; font-size: 12px; background:#fff; }
.pdf-summary-table td.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; }

.pdf-page__page-num { font-size: 10px; color: #888; }

/* 極性・拡張 label */
.kyokusei-badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.15em 0.55em;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.kyokusei-badge--kyokusei { background: #fde8e8; color: #c0392b; }
.kyokusei-badge--kakucho  { background: #e8f0fd; color: #2c5fad; }
.kyokusei-badge--both     { background: #f3e8fd; color: #7c3fbd; }

/* Person row (関係性/組織) */
.person-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
}
.person-row:last-child { border-bottom: none; }
.person-num {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: var(--color-gold-pale);
  color: var(--color-gold);
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: var(--font-en);
  font-weight: 600;
}
.person-row .form-group input { min-width: 0; }

/* Dashboard grid */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.dash-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: box-shadow 0.2s, transform 0.15s;
  cursor: pointer;
}
.dash-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.dash-card__icon { font-size: 1.6rem; }
.dash-card__title {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 400;
}
.dash-card__desc {
  font-size: 0.78rem;
  color: var(--color-ink-muted);
  line-height: 1.5;
}

/* PDF action bar */
.action-bar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--color-border);
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 3rem;
  color: var(--color-ink-muted);
  font-size: 0.88rem;
}

/* ── Hamburger button (hidden on desktop) ── */
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.35rem;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.hamburger:hover { background: var(--color-border); }
.hamburger__line {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--color-ink);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

/* ── Sidebar overlay ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.is-open { display: block; }

/* ── Responsive ── */
@media (max-width: 768px) {
  /* Show hamburger */
  .hamburger { display: flex; }

  /* Sidebar: hidden off-screen, slides in */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 240px;
    height: 100%;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 200;
  }
  .sidebar.is-open { transform: translateX(0); }

  /* Main fills full width */
  .app-main { margin-left: 0; }

  /* Header */
  .app-header { padding: 0.75rem 1rem; }
  .app-header__title { font-size: 1rem; }
  .app-header__user { font-size: 0.72rem; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Content */
  .app-content { padding: 1rem; }

  /* Forms */
  .form-row { flex-direction: column; }
  .form-group { width: 100% !important; }

  /* Cards */
  .card { padding: 1rem; border-radius: var(--radius-md); }
  .card__title { font-size: 0.88rem; }

  /* Tables: horizontal scroll */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 600px; }

  /* Buttons */
  .btn { font-size: 0.82rem; padding: 0.5rem 1rem; }
}

@media (max-width: 480px) {
  html, body { font-size: 14px; }
  .app-header__user { display: none; }
  .app-content { padding: 0.75rem; }
}


/* PDF save note */
.pdf-note {
  font-size: 0.75rem;
  color: #888;
  margin: 0.4rem 0 0;
  line-height: 1.5;
}
