/*
 TaxAI UI Final Finish Ver.98.2
 目的:
 - 左メニュー重複の見た目抑制
 - 色崩れ修復
 - レイアウト崩れ抑制
 - 文字色・見出し可読性改善
*/

/* ===== Base readability ===== */
:root {
  --taxai-bg: #f5f7fb;
  --taxai-surface: #ffffff;
  --taxai-surface-2: #f8fafc;
  --taxai-text: #0f172a;
  --taxai-muted: #475569;
  --taxai-soft: #64748b;
  --taxai-border: #dbe3ef;
  --taxai-primary: #2563eb;
  --taxai-primary-2: #1d4ed8;
  --taxai-danger: #dc2626;
  --taxai-warning: #b45309;
  --taxai-success: #15803d;
  --taxai-sidebar-w: 280px;
}

html,
body {
  background: var(--taxai-bg) !important;
  color: var(--taxai-text) !important;
  min-height: 100%;
}

body,
button,
input,
select,
textarea {
  color: var(--taxai-text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--taxai-primary);
}

a:hover {
  color: var(--taxai-primary-2);
}

/* ===== Text contrast fix ===== */
h1, h2, h3, h4, h5, h6,
.page-title,
.taxai-page-title,
.taxai-title,
.card-title,
.section-title,
.dashboard-title,
.os-title,
.ai-title {
  color: var(--taxai-text) !important;
  text-shadow: none !important;
  opacity: 1 !important;
}

p,
small,
span,
div,
td,
th,
label,
.form-label,
.text-muted,
.taxai-muted,
.description,
.card-description,
.page-description,
.taxai-page-description,
.ai-description {
  text-shadow: none !important;
}

.text-muted,
.taxai-muted,
.description,
.card-description,
.page-description,
.taxai-page-description,
.ai-description,
.help-text {
  color: var(--taxai-muted) !important;
  opacity: 1 !important;
}

/* 読めない白文字・薄文字の救済。ただしサイドバー内は除外 */
main .text-white,
.taxai-main .text-white,
.taxai-content .text-white,
.content-wrapper .text-white,
.container .text-white,
.container-fluid .text-white {
  color: var(--taxai-text) !important;
}

/* 濃色背景カード内の白文字は維持 */
.bg-primary .text-white,
.bg-dark .text-white,
.bg-danger .text-white,
.bg-success .text-white,
.bg-warning .text-white,
.taxai-sidebar .text-white,
.sidebar .text-white,
aside .text-white {
  color: #ffffff !important;
}

/* ===== Layout stabilization ===== */
.taxai-app,
.taxai-shell,
.admin-wrapper,
.app-wrapper {
  min-height: 100vh;
  background: var(--taxai-bg) !important;
}

.taxai-main,
.main-content,
.content-wrapper,
.admin-content,
.page-content {
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

main,
.taxai-content,
.content,
.container-fluid {
  max-width: 100%;
}

.card,
.taxai-card,
.panel,
.box,
.table-wrapper,
.form-wrapper,
.dashboard-card,
.kpi-card {
  background: var(--taxai-surface) !important;
  color: var(--taxai-text) !important;
  border: 1px solid var(--taxai-border) !important;
  border-radius: 16px !important;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06) !important;
}

.card-header,
.taxai-card-header,
.panel-heading,
.box-header {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%) !important;
  color: var(--taxai-text) !important;
  border-bottom: 1px solid var(--taxai-border) !important;
}

/* ===== Tables ===== */
table {
  color: var(--taxai-text) !important;
}

thead,
.table thead,
.table-light {
  background: var(--taxai-surface-2) !important;
  color: var(--taxai-text) !important;
}

th {
  color: #1e293b !important;
  font-weight: 700 !important;
}

td {
  color: #334155 !important;
}

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

.table-responsive {
  border-radius: 14px;
  overflow-x: auto;
}

/* ===== Forms ===== */
input,
select,
textarea,
.form-control,
.form-select {
  background: #ffffff !important;
  color: var(--taxai-text) !important;
  border: 1px solid #cbd5e1 !important;
  border-radius: 10px !important;
}

input::placeholder,
textarea::placeholder {
  color: #94a3b8 !important;
}

input:focus,
select:focus,
textarea:focus,
.form-control:focus,
.form-select:focus {
  border-color: var(--taxai-primary) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .14) !important;
}

/* ===== Buttons ===== */
.btn,
button,
.taxai-btn {
  border-radius: 10px !important;
  font-weight: 700;
}

.btn-primary,
.taxai-btn-primary {
  background: var(--taxai-primary) !important;
  border-color: var(--taxai-primary) !important;
  color: #ffffff !important;
}

.btn-outline-primary {
  color: var(--taxai-primary) !important;
  border-color: var(--taxai-primary) !important;
}

.btn-outline-primary:hover {
  background: var(--taxai-primary) !important;
  color: #ffffff !important;
}

/* ===== Sidebar duplicate visual guard ===== */
.taxai-sidebar,
.sidebar,
aside[class*="sidebar"],
nav[class*="sidebar"] {
  box-sizing: border-box;
}

/* 同じ階層に複数サイドバーが出た場合、2個目以降を隠す */
.taxai-sidebar ~ .taxai-sidebar,
.sidebar ~ .sidebar,
aside[class*="sidebar"] ~ aside[class*="sidebar"],
nav[class*="sidebar"] ~ nav[class*="sidebar"] {
  display: none !important;
}

/* 固定サイドバーが複数重なる場合の暴走抑制 */
.taxai-sidebar,
aside.taxai-sidebar,
.sidebar.taxai-sidebar {
  width: var(--taxai-sidebar-w) !important;
  max-width: var(--taxai-sidebar-w) !important;
  flex: 0 0 var(--taxai-sidebar-w) !important;
}

/* サイドバー本文は濃色背景で統一 */
.taxai-sidebar,
.sidebar-primary,
.admin-sidebar {
  background: #0f172a !important;
  color: #e5e7eb !important;
}

.taxai-sidebar a,
.sidebar-primary a,
.admin-sidebar a {
  color: #e5e7eb !important;
}

.taxai-sidebar a:hover,
.sidebar-primary a:hover,
.admin-sidebar a:hover {
  background: rgba(255,255,255,.08) !important;
  color: #ffffff !important;
}

/* ===== Bad gradient / low contrast guard ===== */
.taxai-hero,
.page-hero,
.dashboard-hero,
.os-hero {
  color: var(--taxai-text) !important;
}

.taxai-hero *,
.page-hero *,
.dashboard-hero *,
.os-hero * {
  opacity: 1 !important;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  :root {
    --taxai-sidebar-w: 248px;
  }

  .taxai-main,
  .main-content,
  .content-wrapper,
  .admin-content {
    margin-left: 0 !important;
    width: 100% !important;
  }

  .card,
  .taxai-card,
  .dashboard-card,
  .kpi-card {
    border-radius: 14px !important;
  }
}

@media (max-width: 768px) {
  .container,
  .container-fluid,
  .taxai-content,
  .page-content {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  h1,
  .page-title,
  .taxai-page-title {
    font-size: 1.45rem !important;
    line-height: 1.35 !important;
  }

  .table-responsive {
    width: 100%;
  }
}
