/* ============================================
   AILEX - Responsive Stylesheet
   ============================================ */

:root {
  --primary: #0f172a;
  --primary-mid: #1e3a5f;
  --primary-light: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #dc2626;
  --bg: #f1f5f9;
  --bg-alt: #e2e8f0;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --text-lighter: #94a3b8;
  --border: #e2e8f0;
  --border-dark: #cbd5e1;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --green-text: #166534;
  --blue-bg: #dbeafe;
  --blue-text: #1e40af;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --red-text: #991b1b;
  --yellow-bg: #fef9c3;
  --yellow-text: #854d0e;
  --info-bg: #e0f2fe;
  --info-text: #0c4a6e;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --transition: 0.2s ease;
}

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

html { font-size: 16px; scroll-behavior: smooth; overflow-x: hidden; }

body {
  font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-light); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-hover); }

/* ─── Header ──────────────────────────── */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-mid) 100%);
  color: white;
  padding: 0 1.5rem;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 54px;
  gap: 0.8rem;
}
.logo {
  text-decoration: none;
  color: white;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.logo-text { font-size: 1.3rem; font-weight: 700; letter-spacing: 3px; }
.logo-sub { font-size: 0.65rem; opacity: 0.6; letter-spacing: 1px; text-transform: uppercase; }
.nav { display: flex; align-items: center; gap: 0.3rem; flex-wrap: nowrap; }
.nav a {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 0.82rem;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.nav a:hover { background: rgba(255,255,255,0.12); color: white; }
.nav-show-mobile { display: none !important; }

/* ─── Hamburger ─────────────────────── */
.nav-hamburger {
  display: none; background: none; border: none; cursor: pointer;
  padding: 6px; flex-direction: column; gap: 4px; z-index: 201;
}
.nav-hamburger span {
  display: block; width: 20px; height: 2px;
  background: rgba(255,255,255,0.9); border-radius: 2px;
  transition: all 0.2s;
}
.nav-hamburger-active span:nth-child(1) { transform: rotate(45deg) translate(4px,4px); }
.nav-hamburger-active span:nth-child(2) { opacity: 0; }
.nav-hamburger-active span:nth-child(3) { transform: rotate(-45deg) translate(4px,-4px); }

/* ─── Nav Dropdown ────────────────────── */
.nav-dropdown {
  position: relative;
  padding-bottom: 8px;
  margin-bottom: -8px;
}
.nav-dropdown-btn {
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,0.85); font-size: 0.82rem;
  padding: 0.4rem 0.7rem; border-radius: var(--radius-sm);
  font-family: inherit; transition: all var(--transition);
}
.nav-dropdown-btn:hover { background: rgba(255,255,255,0.12); color: white; }
.nav-dropdown-menu {
  display: none; position: absolute; top: 100%; left: 0;
  background: white; border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.18); min-width: 180px;
  padding: 6px 0; z-index: 200;
}
.nav-dropdown-menu-right { left: auto; right: 0; }
.nav-dropdown-menu a {
  display: block; padding: 0.55rem 1rem; font-size: 0.82rem;
  color: var(--text) !important; background: none !important;
  border-radius: 0 !important; white-space: nowrap;
}
.nav-dropdown-menu a:hover {
  background: var(--bg-light) !important; color: var(--primary) !important;
}
.nav-dropdown-divider {
  height: 1px; background: var(--border-color); margin: 4px 0;
}
.nav-logout-link { color: #dc3545 !important; }
.nav-logout-link:hover { background: #fff5f5 !important; color: #dc3545 !important; }
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu,
.nav-dropdown-show { display: block; }
.nav-dropdown-user { margin-left: 0.3rem; }
.nav-dropdown-user .nav-user-link { padding: 0.2rem; }
.header-login-btn {
  flex-shrink: 0; margin-left: auto;
  padding: 0.4rem 1.2rem !important; font-size: 0.82rem !important;
  white-space: nowrap; width: auto !important; max-width: 120px;
}

/* ─── Unified Search Bar ─────────────── */
.ai-spin{display:inline-block;width:16px;height:16px;border:2px solid rgba(109,40,217,0.3);border-top-color:#6d28d9;border-radius:50%;animation:aispin .8s linear infinite;vertical-align:middle;margin-right:.3rem}
@keyframes aispin{to{transform:rotate(360deg)}}
.unified-search-bar { margin-bottom: 1rem; }
.unified-search-row { display: flex; gap: 0.5rem; align-items: center; }
.unified-search-input-wrap {
  flex: 1; display: flex;
  border: 1.5px solid #c7d2fe; border-radius: 10px;
  overflow: hidden; background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.unified-search-input-wrap:focus-within {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.unified-search-input-wrap input {
  flex: 1; border: none; outline: none;
  padding: 0.55rem 0.8rem; font-size: 0.84rem;
  font-family: inherit; background: transparent;
  min-width: 0;
}
.unified-search-input-wrap button {
  padding: 0.55rem 1rem; border: none;
  background: linear-gradient(135deg, var(--primary-light), #6366f1);
  color: #fff; font-size: 0.78rem; font-weight: 600;
  cursor: pointer; font-family: inherit;
  white-space: nowrap; transition: opacity 0.2s;
}
.unified-search-input-wrap button:hover { opacity: 0.9; }
.unified-filter-toggle {
  padding: 0.45rem 0.8rem; border: 1px solid var(--border-color);
  border-radius: 8px; background: #fff; color: var(--text-light);
  font-size: 0.78rem; cursor: pointer; font-family: inherit;
  white-space: nowrap; transition: all 0.2s;
}
.unified-filter-toggle:hover { background: var(--bg-light); color: var(--text); }
.unified-filter-panel {
  display: none; margin-top: 0.5rem;
  padding: 0.6rem 0.8rem; background: #fafbfd;
  border: 1px solid #e5e7eb; border-radius: 8px;
}
.unified-filter-panel.filter-open { display: block; }

/* ─── Search Box (Toolbar) ────────────── */
.search-form {
  display: flex; gap: 8px; align-items: center;
}
.search-input {
  flex: 1; max-width: 320px;
  padding: 0.5rem 0.8rem 0.5rem 2.2rem;
  border: 1.5px solid var(--border-color);
  border-radius: 8px; font-size: 0.88rem;
  font-family: inherit; background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23999' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.656a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 0.7rem center;
}
.search-input:focus {
  outline: none; border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}
.search-input::placeholder { color: #aaa; }
.search-btn {
  padding: 0.5rem 1rem; font-size: 0.82rem;
  background: var(--primary); color: white; border: none;
  border-radius: 8px; cursor: pointer; font-family: inherit;
  font-weight: 500; transition: background 0.15s;
}
.search-btn:hover { background: var(--primary-mid); }

.user-info {
  font-size: 0.78rem;
  opacity: 0.7;
  padding: 0.4rem 0.5rem;
}

/* ─── Buttons ─────────────────────────── */
.btn-primary, .btn-primary-sm {
  background: var(--primary-light);
  color: white;
  padding: 0.55rem 1.5rem;
  border-radius: var(--radius);
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-size: 0.88rem;
  font-family: inherit;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all var(--transition);
  box-shadow: 0 1px 2px rgba(37,99,235,0.3);
}
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 2px 4px rgba(37,99,235,0.4); color: white; }
.btn-primary-sm { padding: 0.35rem 1rem; font-size: 0.8rem; }

.btn-outline, .btn-outline-sm {
  border: 1.5px solid var(--border-dark);
  color: var(--text);
  padding: 0.5rem 1.4rem;
  border-radius: var(--radius);
  text-decoration: none;
  background: white;
  cursor: pointer;
  font-size: 0.88rem;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all var(--transition);
}
.btn-outline:hover { border-color: var(--primary-light); color: var(--primary-light); background: #f8fafc; }
.btn-outline-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.85);
  border-color: rgba(255,255,255,0.3);
  background: transparent;
}
.btn-outline-sm:hover { border-color: rgba(255,255,255,0.6); color: white; background: rgba(255,255,255,0.1); }

.btn-outline-xs {
  padding: 0.25rem 0.6rem;
  font-size: 0.72rem;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  background: white;
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition);
}
.btn-outline-xs:hover { border-color: var(--primary-light); color: var(--primary-light); }

.btn-danger-text { color: var(--red); border-color: #fca5a5; }
.btn-danger-text:hover { background: var(--red-bg); border-color: var(--red); color: var(--red); }

.btn-lg { padding: 0.75rem 2.2rem; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; text-align: center; }

/* ─── Main Content ────────────────────── */
.main {
  flex: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
  overflow-x: hidden;
}

.text-light { color: var(--text-light); }

/* ─── Hero ────────────────────────────── */
.hero {
  text-align: center;
  padding: 4rem 1rem 2.5rem;
}
.hero h1 {
  font-size: 3rem;
  letter-spacing: 6px;
  color: var(--primary);
  font-weight: 700;
}
.hero-subtitle {
  font-size: 1rem;
  color: var(--text-lighter);
  margin: 0.3rem 0;
  letter-spacing: 2px;
}
.hero-desc {
  max-width: 520px;
  margin: 1.2rem auto;
  color: var(--text-light);
  font-size: 0.92rem;
  line-height: 1.9;
}
.hero-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 2rem;
}

/* ─── Features ────────────────────────── */
.features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.2rem;
  padding: 1rem 0 2rem;
}
.feature {
  background: var(--card-bg);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-top: 3px solid var(--primary-light);
  transition: transform var(--transition), box-shadow var(--transition);
}
.feature:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.feature h3 { margin-bottom: 0.5rem; color: var(--primary); font-size: 0.95rem; }
.feature p { font-size: 0.82rem; color: var(--text-light); line-height: 1.7; }

/* ─── Cards ───────────────────────────── */
.card {
  background: var(--card-bg);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary-light);
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card h3 { margin-bottom: 0.5rem; font-size: 1rem; color: var(--primary); }
.card p { color: var(--text-light); margin-bottom: 0.75rem; font-size: 0.85rem; }

/* ─── Stats ───────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--card-bg);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  transition: transform 0.15s, box-shadow 0.15s;
  cursor: pointer;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.stat-number { font-size: 2.2rem; font-weight: 700; color: var(--primary-light); }
.stat-label { font-size: 0.78rem; color: var(--text-light); margin-top: 0.2rem; }

/* ─── Dashboard ───────────────────────── */
.dashboard h2, .page-header h2 { margin-bottom: 1.2rem; font-size: 1.3rem; }
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.2rem;
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.2rem;
  margin-bottom: 1.5rem;
}

/* ─── Page Header ─────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

/* ─── Sections ────────────────────────── */
.section { margin-top: 2.5rem; }
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

/* ─── Auth / Login ────────────────────── */
.auth-container { display: flex; justify-content: center; padding: 3rem 1rem; }
.auth-card {
  background: var(--card-bg);
  padding: 2.5rem 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
}
.auth-card h2 { text-align: center; margin-bottom: 1.5rem; font-size: 1.3rem; }
.auth-footer { text-align: center; margin-top: 1.5rem; font-size: 0.8rem; color: var(--text-light); }

/* ─── Forms ───────────────────────────── */
.form-page { max-width: 700px; margin: 0 auto; }
.form-card {
  background: var(--card-bg);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.form-group { margin-bottom: 1.1rem; }
.form-group label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  background: white;
  transition: border-color var(--transition), box-shadow var(--transition);
  color: var(--text);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-group textarea { resize: vertical; min-height: 120px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.8rem; }
.form-help { font-size: 0.73rem; color: var(--text-lighter); margin-top: 0.3rem; }
.required { color: var(--accent); }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.88rem;
}
.checkbox-label input { width: auto; }

/* ─── Upload ──────────────────────────── */
.upload-form {
  background: var(--card-bg);
  padding: 1rem 1.2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  border: 2px dashed var(--border);
}
.upload-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}
.upload-row input[type="file"] { flex: 1; min-width: 180px; font-size: 0.85rem; }
.upload-row select {
  width: 150px;
  padding: 0.45rem 0.6rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: inherit;
}

/* ─── Tables ──────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.table th, .table td {
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.84rem;
}
.table th {
  background: #f8fafc;
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--text-light);
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
}
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: none; }
.table a { font-weight: 500; }

/* Mobile table scroll */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
.table-wrap .table { min-width: 600px; }

/* ─── Badges ──────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.18rem 0.65rem;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--bg-alt);
  color: var(--text-light);
  white-space: nowrap;
}
.badge-green { background: var(--green-bg); color: var(--green-text); }
.badge-blue { background: var(--blue-bg); color: var(--blue-text); }
.badge-gray { background: var(--bg-alt); color: var(--text-light); }
.badge-red { background: var(--red-bg); color: var(--red-text); }

/* ─── Alerts ──────────────────────────── */
.alert {
  padding: 0.8rem 1.2rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.85rem;
  line-height: 1.7;
}
.alert-error { background: var(--red-bg); color: var(--red-text); border: 1px solid #fca5a5; }
.alert-success { background: var(--green-bg); color: var(--green-text); border: 1px solid #86efac; }
.alert-warning { background: var(--yellow-bg); color: var(--yellow-text); border: 1px solid #fde68a; }
.alert-info { background: var(--info-bg); color: var(--info-text); border: 1px solid #7dd3fc; }

/* ─── Generation Cards ────────────────── */
.gen-card {
  background: var(--card-bg);
  padding: 1.3rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  border-left: 4px solid var(--green);
}
.gen-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.73rem;
  color: var(--text-lighter);
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}
.gen-prompt { font-size: 0.8rem; color: var(--text-light); margin-bottom: 0.6rem; }
.gen-text { font-size: 0.85rem; line-height: 1.9; }
.gen-text-lined { font-size: 0.85rem; line-height: 1.8; margin-top: 0.5rem; }
.gen-line { display: flex; align-items: flex-start; gap: 0.3rem; padding: 1px 0; }
.gen-line-text { flex: 1; }
.gen-line-empty { height: 0.8em; }
.gen-line-src {
  flex-shrink: 0;
  font-size: 0.72rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  padding: 0 3px;
  cursor: help;
  color: #2563eb;
  line-height: 1.6;
}
.gen-sources {
  font-size: 0.8rem;
  margin-bottom: 0.6rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}
.gen-source-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: #f0f7ff;
  color: var(--blue-text);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  border: 1px solid #d0e3ff;
}
.gen-ref-urls {
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.82rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.gen-ref-tag {
  display: inline-flex;
  align-items: center;
  background: #f0fdf4;
  color: #15803d;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  border: 1px solid #bbf7d0;
  text-decoration: none;
  transition: all 0.2s;
}
.gen-ref-tag:hover { background: #dcfce7; border-color: #86efac; }
.btn-danger-sm {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  padding: 0.25rem 0.7rem;
  border-radius: 6px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-danger-sm:hover { background: #fee2e2; }

/* ─── Copy button ────────────────────────── */
.btn-copy-sm {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-copy-sm:hover { background: var(--blue-bg); color: var(--blue-text); }

/* ─── Generation Modal ───────────────────── */
.gen-modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.gen-modal {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 820px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.gen-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.gen-modal-header h3 { margin: 0; font-size: 1rem; }
.gen-modal-close {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: #f1f5f9; color: #64748b; font-size: 1.2rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s ease;
}
.gen-modal-close:hover { background: #fee2e2; color: #dc2626; }
.gen-modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
  font-size: 0.9rem;
  line-height: 1.9;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.gen-copy-notice {
  padding: 0.6rem 1.5rem;
  background: #dcfce7;
  color: #166534;
  font-size: 0.85rem;
  text-align: center;
  border-radius: 0 0 12px 12px;
  flex-shrink: 0;
}

/* ─── Setup ───────────────────────────── */
.setup-page { display: flex; justify-content: center; padding: 2rem 1rem; }
.setup-steps { margin-top: 1rem; }
.setup-steps ol { padding-left: 1.5rem; margin: 0.5rem 0 1rem; }
.setup-steps li { margin-bottom: 0.4rem; font-size: 0.85rem; }
.setup-steps code {
  background: var(--bg-alt);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: 'SFMono-Regular', Consolas, monospace;
}

/* ─── Error / Empty ───────────────────── */
.error-page { text-align: center; padding: 5rem 1rem; }
.error-page h1 { font-size: 4rem; color: var(--text-lighter); font-weight: 700; }
.error-page p { margin: 1rem 0 2rem; color: var(--text-light); }
.empty-state {
  text-align: center;
  padding: 2.5rem;
  color: var(--text-light);
  font-size: 0.9rem;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ─── Documents Page ──────────────────── */
.doc-filter-bar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
  padding: 0.8rem 1rem;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.doc-search-input {
  flex: 1;
  min-width: 160px;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}
.doc-filter-select {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  background: #fff;
  max-width: 200px;
}
/* Case section grouping */
.doc-case-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  overflow: hidden;
}
.doc-case-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.doc-case-header a {
  text-decoration: none;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.doc-case-title { font-weight: 600; font-size: 0.88rem; }
.doc-case-num { font-size: 0.75rem; color: var(--text-lighter); }
/* Card-style rows */
.doc-card-list { padding: 0.3rem 0; }
.doc-card-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid #f0f2f5;
  transition: background 0.15s;
}
.doc-card-row:last-child { border-bottom: none; }
.doc-card-row:hover { background: #f8fafc; }
.doc-card-icon { font-size: 1rem; flex-shrink: 0; width: 24px; text-align: center; }
.doc-card-main { flex: 1; min-width: 0; }
.doc-card-name {
  display: block;
  font-size: 0.84rem;
  color: var(--primary-light);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-card-name:hover { text-decoration: underline; }
.doc-card-meta {
  display: flex;
  gap: 0.6rem;
  font-size: 0.72rem;
  color: var(--text-lighter);
  margin-top: 1px;
}
.doc-card-type-form { flex-shrink: 0; margin: 0; }
.doc-card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  align-items: center;
}
.doc-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 0.78rem;
  text-decoration: none;
  transition: all 0.15s;
  color: var(--text-light);
}
.doc-action-dl:hover { background: #eff6ff; border-color: var(--primary-light); color: var(--primary-light); }
.doc-action-del { color: #dc2626; }
.doc-action-del:hover { background: #fef2f2; border-color: #dc2626; }
/* Summary */
.doc-summary {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding: 0.6rem 1rem;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.82rem;
  color: var(--text-light);
}
.doc-summary-item { display: flex; align-items: center; gap: 0.3rem; }
.doc-type-select {
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.76rem;
  background: #fff;
  cursor: pointer;
  color: var(--text);
  max-width: 100px;
}
.doc-type-select:hover { border-color: var(--primary-light); }
/* Import page doc rows */
.import-doc-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid #f0f2f5;
  margin-bottom: 4px;
  transition: background 0.15s;
}
.import-doc-row:hover { background: #f8fafc; }
.import-doc-row.doc-main { background: #fffbeb; border-color: #fcd34d; }
.import-doc-info { flex: 1; min-width: 0; }
.import-doc-name {
  display: block;
  font-size: 0.84rem;
  color: var(--primary-light);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.import-doc-name:hover { text-decoration: underline; }
.import-summary-textarea {
  width: 100%;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.6;
  resize: vertical;
}
/* Responsive: documents */
@media (max-width: 640px) {
  .doc-filter-bar { flex-direction: column; }
  .doc-search-input, .doc-filter-select { width: 100%; max-width: 100%; }
  .doc-card-row { flex-wrap: wrap; gap: 0.4rem; padding: 0.6rem 0.7rem; }
  .doc-card-main { flex-basis: calc(100% - 36px); }
  .doc-card-type-form { order: 4; }
  .doc-card-actions { order: 5; margin-left: auto; }
  .doc-card-meta { flex-wrap: wrap; }
  .doc-case-header { flex-direction: column; align-items: flex-start; gap: 0.2rem; }
  .import-doc-row { flex-wrap: wrap; }
  .import-doc-info { flex-basis: calc(100% - 36px); }
}

/* ─── Footer ──────────────────────────── */
.footer {
  background: var(--primary);
  color: rgba(255,255,255,0.7);
  padding: 1.2rem 2rem;
  text-align: center;
  font-size: 0.78rem;
  margin-top: auto;
}
.footer a { color: rgba(255,255,255,0.85); }
.footer a:hover { color: white; }

/* ─── Action cells ────────────────────── */
.actions-cell { white-space: nowrap; }

/* ─── Upload Zone (drag & drop) ───── */
.upload-zone {
  border: 2px dashed var(--border-dark);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: #f8fafc;
  position: relative;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary-light);
  background: #eff6ff;
}
.upload-zone.has-file { border-color: var(--green); background: #f0fdf4; }
.upload-zone input[type="file"] {
  position: absolute; top:0; left:0; width:100%; height:100%; opacity:0; cursor: pointer;
}
.upload-zone-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.upload-zone-text { font-size: 0.9rem; color: var(--text-light); line-height: 1.7; }
.upload-zone-hint {
  display: none; margin-top: 0.8rem; font-size: 0.88rem; font-weight: 600; color: var(--green);
}

/* Import Results - Case View */
.import-success-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 1.5rem;
  box-shadow: var(--shadow-md); border-left: 4px solid var(--green);
}
.case-info-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.8rem; margin-top: 1rem;
}
.case-info-item {
  background: #f8fafc; border-radius: 8px; padding: 0.7rem 1rem;
}
.case-info-label {
  display: block; font-size: 0.72rem; color: var(--text-lighter);
  text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 0.2rem;
}
.case-info-value { font-size: 0.9rem; font-weight: 600; color: var(--text); }
.doc-row {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border); font-size: 0.84rem;
}
.doc-row:last-child { border-bottom: none; }
.doc-row.doc-main { background: #eff6ff; border-radius: 6px; border-bottom: none; margin-bottom: 2px; }
.doc-icon { font-size: 0.9rem; flex-shrink: 0; }
.doc-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: 0.72rem; color: var(--text-lighter); white-space: nowrap; }

/* Spinner */
.spinner {
  display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white; border-radius: 50%; animation: spin 0.6s linear infinite; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Delete Buttons ─────────────────── */
.btn-danger-sm {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0.35rem 0.8rem; font-size: 0.78rem; font-weight: 600;
  background: var(--red); color: #fff; border: none; border-radius: 6px;
  cursor: pointer; transition: all var(--transition);
}
.btn-danger-sm:hover { background: #b91c1c; }
.btn-icon-danger {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid #fca5a5;
  background: transparent; color: var(--red); font-size: 0.9rem; font-weight: 700;
  cursor: pointer; transition: all var(--transition); line-height: 1;
}
.btn-icon-danger:hover { background: var(--red); color: #fff; border-color: var(--red); }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 640px) { .edit-grid { grid-template-columns: 1fr; } }

/* ─── Toggle Switch ──────────────────── */
.toggle-switch {
  position: relative; display: inline-block; width: 38px; height: 22px; cursor: pointer;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: #cbd5e1; border-radius: 22px;
  transition: background 0.25s;
}
.toggle-slider::before {
  content: ''; position: absolute; left: 3px; top: 3px;
  width: 16px; height: 16px; background: #fff; border-radius: 50%;
  transition: transform 0.25s; box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ─── Reference URL Management ───────── */
.ref-url-add-form {
  display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center;
}
.ref-url-add-form input, .ref-url-add-form select {
  padding: 0.45rem 0.7rem; border: 1px solid var(--border); border-radius: 6px;
  font-size: 0.84rem; font-family: inherit;
}
.ref-url-input { flex: 1; min-width: 200px; }
.ref-url-list {
  background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border);
  overflow: hidden;
}
.ref-url-header {
  padding: 0.5rem 1rem; background: #f8fafc; border-bottom: 1px solid var(--border);
  font-size: 0.8rem; color: var(--text-light);
}
.ref-url-row {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border); font-size: 0.84rem;
  transition: opacity 0.2s, background 0.2s;
}
.ref-url-row:last-child { border-bottom: none; }
.ref-url-row.ref-url-disabled { opacity: 0.45; background: #f9fafb; }
.ref-url-cat { font-size: 1rem; flex-shrink: 0; }
.ref-url-info { flex: 1; min-width: 0; }
.ref-url-link {
  display: block; color: var(--primary); text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ref-url-link:hover { text-decoration: underline; }
.ref-url-link-off { color: var(--text-light); }
.ref-url-meta { display: flex; gap: 0.3rem; margin-top: 0.15rem; align-items: center; }
.ref-url-domain { font-size: 0.72rem; color: #94a3b8; }

/* ============================================
   RESPONSIVE
   ============================================ */

/* Tablet */
@media (max-width: 900px) {
  .features { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .form-row { grid-template-columns: 1fr 1fr; }
}

/* Mobile */
@media (max-width: 640px) {
  html { font-size: 15px; }

  .header { padding: 0 1rem; }
  .header-inner {
    flex-direction: row;
    align-items: center;
    padding: 0.5rem 0;
    gap: 0.5rem;
    position: relative;
  }
  .logo { flex-shrink: 0; }
  .logo-sub { display: none; }

  /* Hamburger visible on mobile */
  .nav-hamburger { display: flex; margin-left: auto; }

  /* Nav becomes vertical dropdown panel */
  .nav {
    display: none;
    position: absolute; top: 100%; right: 0; left: 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-mid) 100%);
    flex-direction: column; align-items: stretch;
    flex-wrap: wrap;
    padding: 0.5rem; gap: 2px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.25);
    border-radius: 0 0 8px 8px;
    z-index: 200;
  }
  .nav.nav-open { display: flex; }
  .nav > a, .nav > .nav-dropdown {
    display: block; width: 100%;
  }
  .nav > a {
    font-size: 0.88rem; padding: 0.6rem 1rem;
    border-radius: 6px; text-align: left;
  }
  .nav-hide-mobile { display: none !important; }
  .nav-show-mobile { display: block !important; }

  /* Dropdown: disable hover, use click only on mobile */
  .nav-dropdown { position: static; padding-bottom: 0; margin-bottom: 0; }
  .nav-dropdown:hover .nav-dropdown-menu,
  .nav-dropdown:focus-within .nav-dropdown-menu { display: none; }
  .nav-dropdown .nav-dropdown-menu.nav-dropdown-show { display: block; }
  .nav-dropdown-btn {
    font-size: 0.88rem; padding: 0.6rem 1rem;
    width: 100%; text-align: left; border-radius: 6px;
  }
  .nav-dropdown-menu {
    position: static; box-shadow: none;
    background: rgba(255,255,255,0.08);
    border-radius: 6px; margin: 0; padding: 2px 0;
  }
  .nav-dropdown-menu a {
    color: rgba(255,255,255,0.85) !important;
    padding: 0.5rem 1rem 0.5rem 1.8rem !important;
    font-size: 0.84rem !important;
  }
  .nav-dropdown-menu a:hover {
    background: rgba(255,255,255,0.12) !important;
    color: white !important;
  }
  .nav-dropdown-divider { background: rgba(255,255,255,0.15); }
  .nav-logout-link { color: #fca5a5 !important; }

  /* User dropdown on mobile */
  .nav-dropdown-user { margin-left: 0; }
  .nav-dropdown-user .nav-user-link { padding: 0.4rem 1rem; }
  .nav-dropdown-menu-right { left: 0; right: 0; }

  /* Login button for non-logged-in mobile */
  .header-login-btn {
    display: inline-flex !important;
    width: auto !important;
    max-width: 120px !important;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    margin-left: auto !important;
    padding: 0.35rem 1rem !important;
    font-size: 0.78rem !important;
  }

  .user-info { display: none; }
  .search-input { max-width: 100%; font-size: 0.82rem; }

  /* Unified search responsive */
  .unified-search-row { flex-direction: column; }
  .unified-filter-toggle { align-self: flex-start; }
  .unified-search-input-wrap input { font-size: 0.8rem; padding: 0.5rem 0.6rem; }

  .main { padding: 1rem; }

  .hero { padding: 2.5rem 0.5rem 1.5rem; }
  .hero h1 { font-size: 2rem; letter-spacing: 4px; }
  .hero-subtitle { font-size: 0.85rem; }
  .hero-desc { font-size: 0.85rem; }
  .hero-actions { flex-direction: column; align-items: stretch; }

  .features { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }

  .form-row { grid-template-columns: 1fr; }
  .form-card { padding: 1.2rem; }
  .auth-card { padding: 1.5rem 1.2rem; }

  .upload-row { flex-direction: column; align-items: stretch; }
  .upload-row select { width: 100%; }
  .upload-row input[type="file"] { min-width: 0; }

  .page-header { flex-direction: column; gap: 0.8rem; }
  .page-header .btn-primary,
  .page-header .btn-outline { width: 100%; justify-content: center; }
  /* Issue 5: 「一覧に戻る」ボタンをモバイルで見やすく */
  .page-header .btn-outline {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
  }

  .gen-meta { flex-direction: column; gap: 0.2rem; }

  /* Issue 3: 事件詳細ページ モバイル対応 */
  .gen-card {
    padding: 1rem 0.8rem;
    word-break: break-word;
    overflow-wrap: break-word;
  }
  .gen-card .btn-icon-danger {
    position: absolute; top: 0.5rem; right: 0.5rem;
  }
  .gen-text-lined {
    font-size: 0.82rem;
    overflow-x: hidden;
    word-break: break-word;
  }
  .gen-line {
    flex-direction: column;
    gap: 0.1rem;
  }
  .gen-line-text {
    min-width: 0;
    word-break: break-word;
  }
  .gen-prompt {
    font-size: 0.78rem;
    word-break: break-word;
  }
  .gen-sources {
    flex-direction: column;
    align-items: flex-start;
  }
  .gen-source-tag {
    font-size: 0.72rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .gen-card > div[style*="display:flex"] {
    flex-direction: column;
  }

  /* 文書テーブル: モバイルでカード化 */
  .case-detail .table-wrap .table { min-width: 500px; }

  .section-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }

  .footer { padding: 1rem; }

  /* Table horizontal scroll on mobile */
  .table { font-size: 0.78rem; }
  .table th, .table td { padding: 0.5rem 0.6rem; }

  /* 全テーブルを横スクロール可能に */
  .main .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* dashboard: stats-grid 2列, dashboard-grid 1列 */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
  .stat-card { padding: 0.8rem 0.6rem; }

  /* dashboard: inline flex要素のwrap強化 */
  .main div[style*="display:flex"] { flex-wrap: wrap !important; }

  /* schedules / conflicts / consultations: カード化 */
  .card, .gen-card { overflow-wrap: break-word; word-break: break-word; }

  /* form要素のモバイル対応 */
  input[type="text"], input[type="email"], input[type="password"],
  input[type="date"], input[type="time"], input[type="number"],
  select, textarea {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* admin/users: テーブル横スクロール */
  .admin-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Issue 4: 請求書ステータスカード モバイル対応 */
  .invoice-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .invoice-stat-card {
    min-width: 0;
    max-width: none;
    padding: 0.5rem 0.3rem;
    font-size: 0.72rem;
  }
  .invoice-stat-icon { font-size: 1rem; }
  .invoice-stat-value { font-size: 0.85rem; }
  .invoice-stat-label { font-size: 0.62rem; }
  .invoice-stat-amount { font-size: 0.65rem; }

  /* 請求書テーブル: モバイルで横スクロール対応 */
  .invoice-table-wrap .table { min-width: 720px; }

  /* Issue 6: AI障害情報表示 モバイル対応 */
  .ai-status-card {
    min-width: 0 !important;
    max-width: none !important;
    flex: 1 1 100% !important;
  }
  .ai-balance-card {
    min-width: 0 !important;
    max-width: none !important;
    flex: 1 1 100% !important;
  }
}

/* Small mobile */
@media (max-width: 380px) {
  html { font-size: 14px; }
  .hero h1 { font-size: 1.7rem; }
  .nav > a { font-size: 0.82rem; }
  .nav-dropdown-btn { font-size: 0.82rem; }
}

/* ─── Chat Page ──────────────────────── */
.chat-wrapper {
  display: flex;
  height: calc(100vh - 130px);
  margin: -1.5rem;
  background: var(--bg);
  overflow: hidden;
  max-width: none;
}
.chat-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
}
.chat-sidebar-header h3 { margin: 0; font-size: 0.95rem; }
.chat-new-btn { font-size: 0.75rem; white-space: nowrap; }
.chat-sidebar-quota {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.chat-quota-bar {
  height: 4px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 4px;
}
.chat-quota-fill {
  height: 100%;
  background: var(--primary-light);
  border-radius: 4px;
  transition: width 0.3s;
}
.chat-quota-text { font-size: 0.7rem; color: var(--text-lighter); }
.chat-session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.3rem 0;
}
.chat-session-item {
  display: block;
  padding: 0.6rem 1rem;
  text-decoration: none;
  color: var(--text);
  border-left: 3px solid transparent;
  transition: all 0.15s;
}
.chat-session-item:hover { background: #f0f4ff; }
.chat-session-item.active {
  background: #eff6ff;
  border-left-color: var(--primary-light);
}
.chat-session-preview {
  font-size: 0.82rem;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-session-meta {
  display: flex;
  gap: 0.6rem;
  font-size: 0.7rem;
  color: var(--text-lighter);
  margin-top: 2px;
}
.chat-sidebar-empty {
  padding: 1.5rem 1rem;
  font-size: 0.82rem;
  color: var(--text-lighter);
  text-align: center;
}
/* Main chat area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-topbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  min-height: 44px;
}
.chat-sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 1rem;
}
.chat-topbar-title {
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Messages */
.chat-case-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.45rem 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.chat-case-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}
.chat-case-selector select:focus {
  border-color: var(--primary);
}
.chat-case-info {
  align-items: center;
  gap: 0.5rem;
}
/* ── AI生成文書コンテキストバナー ── */
.gen-context-banner {
  padding: 0.5rem 1rem;
  background: linear-gradient(135deg, #eff6ff, #e0edff);
  border-bottom: 1px solid #bfdbfe;
  transition: opacity 0.3s;
}
.gen-context-banner-inner {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.gen-context-banner-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}
.gen-context-banner-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.gen-context-banner-text strong {
  font-size: 0.78rem;
  color: #1e40af;
}
.gen-context-preview {
  font-size: 0.72rem;
  color: #3b82f6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gen-context-banner-close {
  flex-shrink: 0;
  background: rgba(255,255,255,0.7);
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  width: 26px; height: 26px;
  font-size: 0.8rem;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.gen-context-banner-close:hover {
  background: #fff;
  color: #dc2626;
  border-color: #fca5a5;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.chat-msg {
  display: flex;
  gap: 0.6rem;
  max-width: 85%;
  animation: chatFadeIn 0.25s ease;
}
@keyframes chatFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.chat-msg-user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg-ai { align-self: flex-start; }
.chat-msg-system { align-self: center; max-width: 90%; }
.chat-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  background: #f1f5f9;
}
.chat-msg-user .chat-msg-avatar { background: #dbeafe; }
.chat-msg-body { min-width: 0; }
.chat-msg-content {
  padding: 0.65rem 0.9rem;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.65;
  word-break: break-word;
}
.chat-msg-user .chat-msg-content {
  background: var(--primary-light);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg-ai .chat-msg-content {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-msg-ai .chat-msg-content code {
  background: #f1f5f9;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.82rem;
}
.chat-msg-ai .chat-msg-content pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 0.8rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5rem 0;
  font-size: 0.8rem;
}
.chat-msg-ai .chat-msg-content pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}
.chat-msg-system .chat-msg-content {
  background: #fef3c7;
  border-radius: 8px;
  font-size: 0.82rem;
  text-align: center;
}
.chat-msg-time {
  font-size: 0.68rem;
  color: var(--text-lighter);
  margin-top: 2px;
  padding: 0 0.4rem;
}
.chat-msg-user .chat-msg-time { text-align: right; }
.chat-typing { color: var(--text-lighter); font-style: italic; }
.typing-dots::after {
  content: '';
  animation: typingDots 1.5s infinite;
}
@keyframes typingDots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}
/* Input area */
.chat-input-area {
  padding: 0.8rem 1.5rem;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
}
.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.4rem 0.5rem;
  transition: border-color 0.2s;
}
.chat-input-wrap:focus-within { border-color: var(--primary-light); box-shadow: 0 0 0 2px rgba(37,99,235,0.1); }
.chat-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 0.4rem 0.5rem;
  font-size: 0.88rem;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  background: transparent;
  font-family: inherit;
}
.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: var(--primary-light);
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.chat-send-btn:hover { background: var(--primary); }
.chat-send-btn:disabled { background: #94a3b8; cursor: not-allowed; }
.chat-input-hint {
  font-size: 0.7rem;
  color: var(--text-lighter);
  margin-top: 0.3rem;
  padding: 0 0.3rem;
}
.chat-limit-banner {
  padding: 1rem;
  background: #fef3c7;
  border-top: 1px solid #fcd34d;
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.7;
}
/* Welcome screen */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  padding: 2rem 1rem;
  gap: 0.6rem;
}
.chat-welcome-icon { font-size: 3rem; }
.chat-welcome h3 { margin: 0; font-size: 1.2rem; }
.chat-welcome p { color: var(--text-light); font-size: 0.88rem; line-height: 1.7; margin: 0; }
.chat-welcome-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1rem;
  max-width: 600px;
}
.chat-example-btn {
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text);
  transition: all 0.15s;
  text-align: left;
}
.chat-example-btn:hover { border-color: var(--primary-light); background: #f0f4ff; }
.chat-welcome-disclaimer {
  margin-top: 1rem;
  font-size: 0.75rem;
  color: var(--text-lighter);
  max-width: 500px;
}
/* Follow-up suggestions */
.chat-suggestions-wrap {
  padding: 0.4rem 0 0.8rem;
  animation: sugFadeIn 0.3s ease-out;
}
.chat-suggestions-label {
  font-size: 0.72rem;
  color: var(--text-lighter);
  margin-bottom: 0.4rem;
  padding-left: 3rem;
}
.chat-suggestions-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding-left: 3rem;
}
.chat-suggestion-btn {
  padding: 0.35rem 0.7rem;
  border: 1px solid #c7d2fe;
  border-radius: 16px;
  background: linear-gradient(135deg, #eef2ff, #f0f9ff);
  cursor: pointer;
  font-size: 0.76rem;
  color: #3730a3;
  transition: all 0.15s;
  white-space: nowrap;
}
.chat-suggestion-btn:hover {
  border-color: #818cf8;
  background: linear-gradient(135deg, #e0e7ff, #dbeafe);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(99,102,241,0.15);
}
@keyframes sugFadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
/* Dashboard chat hero card */
.chat-hero-card {
  border-left: 3px solid #10b981;
  background: linear-gradient(135deg, #ecfdf5 0%, #fff 100%);
}
.dash-practice-card {
  border-left: 3px solid #10b981;
  background: linear-gradient(135deg, #ecfdf5 0%, #fff 100%);
}

/* ─── Usage/Subscription Page ────────── */
.usage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.usage-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
}
.usage-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.usage-card-icon { font-size: 1.2rem; }
.usage-card-label { font-size: 0.82rem; font-weight: 500; color: var(--text-light); }
.usage-card-main {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
}
.usage-card-number { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.usage-card-unit { font-size: 0.8rem; color: var(--text-lighter); }
.usage-bar {
  height: 6px;
  background: #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.usage-bar-fill {
  height: 100%;
  background: var(--primary-light);
  border-radius: 6px;
  transition: width 0.5s ease;
}
.usage-bar-warn { background: #f59e0b; }
.usage-card-detail {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-lighter);
  flex-wrap: wrap;
}
.usage-card-summary {
  background: linear-gradient(135deg, #f0f4ff 0%, #fff 100%);
  border-left: 3px solid var(--primary-light);
}

/* ─── Chat Responsive ────────────────── */
/* Chat sidebar overlay (mobile) */
.chat-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 199;
  -webkit-tap-highlight-color: transparent;
}
/* Chat sidebar close button (mobile) */
.chat-sidebar-close {
  display: none;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  width: 36px; height: 36px;
  font-size: 1.1rem;
  color: #475569;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.chat-sidebar-close:hover { background: #e2e8f0; color: #1e293b; }

@media (max-width: 768px) {
  .chat-wrapper { margin: -1rem -0.5rem; height: calc(100vh - 120px); }
  .chat-sidebar {
    position: fixed;
    left: -300px;
    top: 0;
    bottom: 0;
    z-index: 200;
    width: 280px;
    transition: left 0.3s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .chat-sidebar.open { left: 0; }
  .chat-sidebar-toggle { display: block; }
  .chat-sidebar-overlay.open { display: block; }
  .chat-sidebar-close { display: flex; }
  .chat-messages { padding: 0.8rem; }
  .chat-msg { max-width: 92%; }
  .chat-input-area { padding: 0.6rem 0.8rem; }
  .chat-welcome-examples { flex-direction: column; }
  .chat-example-btn { text-align: center; }
}

/* ─── Chat Sidebar Refs ──────────────── */
.chat-sidebar-refs {
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
}
.chat-refs-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 0.3rem;
}
.chat-ref-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 2px 4px;
  font-size: 0.72rem;
  color: var(--text);
  text-decoration: none;
  border-radius: 4px;
  transition: background 0.15s;
  overflow: hidden;
}
.chat-ref-item:hover { background: #f0f4ff; }
.chat-ref-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-ref-more {
  display: block;
  font-size: 0.7rem;
  color: var(--primary-light);
  text-decoration: none;
  padding: 2px 4px;
  margin-top: 2px;
}
.chat-quota-warn { background: #f59e0b !important; }

/* ─── Factcheck Button & Modal ────────── */
.chat-msg-wrap {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.3rem;
}
.chat-msg-wrap-user { align-items: flex-end; }
.chat-msg-wrap-ai { align-items: flex-start; }
.fc-btn-wrap {
  display: flex;
  padding-left: 2.6rem;
  margin-top: 3px;
  margin-bottom: 4px;
}
.fc-btn-yellow {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border: none;
  border-radius: 14px;
  padding: 4px 14px;
  font-size: 0.74rem;
  font-weight: 600;
  color: #78350f;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(245,158,11,0.35);
}
.fc-btn-yellow:hover {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  box-shadow: 0 3px 10px rgba(245,158,11,0.5);
  transform: translateY(-1px);
}
.fc-btn-yellow:disabled { opacity: 0.5; cursor: wait; transform: none; box-shadow: none; }
.fc-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.fc-modal-content {
  background: #fff;
  border-radius: 12px;
  width: 90%;
  max-width: 680px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.fc-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.fc-modal-header h3 { margin: 0; font-size: 1rem; }
.fc-modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-lighter);
  padding: 0 4px;
  line-height: 1;
}
.fc-modal-close:hover { color: var(--text); }
.fc-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.2rem;
  font-size: 0.88rem;
  line-height: 1.75;
}
.fc-modal-body code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 0.82rem; }
.fc-modal-body pre { background: #1e293b; color: #e2e8f0; padding: 0.8rem; border-radius: 8px; overflow-x: auto; font-size: 0.8rem; }
.fc-modal-body pre code { background: transparent; padding: 0; color: inherit; }
.fc-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.2rem;
  border-top: 1px solid var(--border);
}
.fc-result { word-break: break-word; }
.fc-citations {
  margin-top: 1rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
}

/* ─── Plan Badge ─────────────────────── */
.plan-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.plan-free { background: #e5e7eb; color: #6b7280; }
.plan-pro { background: linear-gradient(135deg,#3b82f6,#8b5cf6); color: #fff; }

/* ─── Plan Select in Users ───────────── */
.plan-select {
  padding: 2px 6px;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}
.plan-select:focus { border-color: var(--primary-light); }

/* ─── Nav Avatar ─────────────────────── */
.nav-user-link {
  display: flex !important;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: rgba(255,255,255,0.9);
}
.nav-user-link:hover { color: #fff; }
.nav-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.3);
}
.nav-avatar-placeholder {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  border: 2px solid rgba(255,255,255,0.3);
}
.nav-user-name {
  font-size: 0.82rem;
  font-weight: 500;
}

/* ─── Chat Avatar Image ──────────────── */
.chat-msg-avatar-img {
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

/* ─── Settings: Avatar Upload ────────── */
.avatar-upload-area {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  margin-bottom: 0.5rem;
}
.avatar-preview {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: #f3f4f6;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  border: 3px solid var(--border);
  flex-shrink: 0;
}
.avatar-preview img {
  width: 100%; height: 100%; object-fit: cover;
}
.avatar-initial {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary-light);
}

/* ─── Settings: Invite Form ──────────── */
.settings-invite-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.settings-invite-input {
  flex: 1;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
}
.settings-invite-input:focus {
  border-color: var(--primary-light);
  outline: none;
}

/* ─── Dashboard: Section Title ───────── */
.dash-section-title {
  margin: 1.8rem 0 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--border);
}

/* ─── Dashboard: Settings List ───────── */
.dash-settings-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.dash-settings-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.9rem 1.2rem;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.dash-settings-row:last-child { border-bottom: none; }
.dash-settings-row:hover { background: #f8fafc; }
.dash-settings-row-static { cursor: default; }
.dash-settings-row-static:hover { background: #fff; }
.dash-settings-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}
.dash-settings-info { flex: 1; min-width: 0; }
.dash-settings-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.3;
}
.dash-settings-desc {
  display: block;
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 0.1rem;
}
.dash-settings-arrow {
  font-size: 0.85rem;
  color: var(--text-lighter);
  flex-shrink: 0;
}

/* ─── Chat: Auto-linked URLs ─────────── */
.chat-autolink {
  color: #2563eb;
  word-break: break-all;
  text-decoration: none;
}
.chat-autolink:hover { text-decoration: underline; }

/* ─── Chat Title Editable ────────────── */
.chat-title-editable {
  cursor: pointer;
  border-bottom: 1px dashed rgba(255,255,255,0.4);
  transition: border-color 0.2s;
}
.chat-title-editable:hover { border-bottom-color: #fff; }

/* ─── Factcheck Citation Links ───────── */
.fc-cite-link {
  color: #2563eb;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.fc-cite-link:hover { text-decoration: underline; color: #1d4ed8; }
.fc-citations ol {
  padding-left: 1.5rem;
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
}
.fc-citations ol li { margin-bottom: 0.2rem; }
.fc-citations ol li a { color: #2563eb; word-break: break-all; }

/* ─── Import Mode Tabs ───────────────── */
.import-mode-tabs { display:flex; gap:0.5rem; }
.import-mode-tab {
  flex:1; display:flex; align-items:center; justify-content:center; gap:0.4rem;
  padding:0.7rem 1rem; border:2px solid var(--border); border-radius:8px;
  cursor:pointer; font-size:0.88rem; font-weight:500; transition:all 0.2s;
  background:#fff; color:var(--text-light);
}
.import-mode-tab input { display:none; }
.import-mode-tab:hover { border-color:var(--primary-light); }
.import-mode-tab.active {
  border-color:var(--primary-light); background:rgba(37,99,235,0.06);
  color:var(--primary-light); font-weight:600;
}

/* ── パスワード強度メーター ── */
.pw-strength { margin-top:0.4rem; }
.pw-strength-bar {
  height:6px; background:#e5e7eb; border-radius:3px; overflow:hidden;
}
.pw-strength-fill {
  height:100%; width:0; border-radius:3px;
  transition: width 0.3s ease, background 0.3s ease;
}
.pw-strength-fill.pw-weak { background:#ef4444; }
.pw-strength-fill.pw-medium { background:#f59e0b; }
.pw-strength-fill.pw-strong { background:#22c55e; }
.pw-strength-label {
  display:block; font-size:0.72rem; margin-top:0.2rem; font-weight:600;
}
.pw-strength-label.pw-weak { color:#ef4444; }
.pw-strength-label.pw-medium { color:#d97706; }
.pw-strength-label.pw-strong { color:#16a34a; }

/* ── Legal Document Pages ── */
.legal-doc h3 { font-size:0.92rem; margin:1.8rem 0 0.6rem; padding-bottom:0.3rem; border-bottom:1px solid var(--border-color); }
.legal-doc h3:first-child { margin-top:0; }
.legal-doc p { font-size:0.86rem; line-height:1.7; margin:0.4rem 0; color:var(--text-main); }
.legal-doc p strong { color:var(--text-main); }

/* ── PII Masking Banner (Top Page) ── */
.masking-banner {
  background: linear-gradient(180deg, #faf0d8 0%, #f0f5fc 100%);
  border-top: 3px solid #c4953a;
  padding: 1.8rem 1.5rem 1.5rem;
  margin: 0 -1.5rem;
}
.masking-banner-inner {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  max-width: 800px;
  margin: 0 auto 1.2rem;
}
.masking-badge {
  flex-shrink: 0;
  background: var(--primary);
  color: #fff;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
}
.masking-banner-text h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #0b1a33;
  margin-bottom: 0.4rem;
  line-height: 1.5;
}
.masking-banner-text p {
  font-size: 0.82rem;
  color: #40405c;
  line-height: 1.7;
}
.masking-banner-text strong { color: #0b1a33; }
.masking-demo-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 0 auto 1.2rem;
  max-width: 600px;
}
.masking-demo-box {
  flex: 1;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  font-family: 'SFMono-Regular', 'Consolas', 'Menlo', monospace;
  font-size: 0.78rem;
  line-height: 1.8;
}
.masking-demo-box.before {
  background: rgba(185,28,28,0.06);
  border: 1px solid rgba(185,28,28,0.15);
}
.masking-demo-box.after {
  background: rgba(22,163,74,0.06);
  border: 1px solid rgba(22,163,74,0.15);
}
.masking-demo-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 0.3rem;
}
.masking-demo-box.before .masking-demo-label { color: #b91c1c; }
.masking-demo-box.after .masking-demo-label { color: #16a34a; }
.pii-orig {
  color: #b91c1c;
  background: rgba(185,28,28,0.08);
  padding: 0 4px;
  border-radius: 3px;
}
.pii-masked {
  color: #16a34a;
  background: rgba(22,163,74,0.08);
  padding: 0 4px;
  border-radius: 3px;
  font-weight: 600;
}
.masking-demo-arrow {
  font-size: 1.5rem;
  color: var(--primary);
  font-weight: 700;
  flex-shrink: 0;
}
.masking-trust-points {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  max-width: 700px;
  margin: 0 auto;
}
.trust-point {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: #40405c;
  line-height: 1.4;
}
.trust-icon {
  font-size: 1.3rem;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.7);
  border-radius: 6px;
  flex-shrink: 0;
}
@media (max-width: 640px) {
  .masking-banner { padding: 1.2rem 1rem; margin: 0 -1rem; }
  .masking-banner-inner { flex-direction: column; align-items: center; text-align: center; }
  .masking-demo-row { flex-direction: column; }
  .masking-demo-arrow { transform: rotate(90deg); }
  .masking-trust-points { gap: 0.8rem; }
  .trust-point { font-size: 0.7rem; }
}

/* ================================================================
   v6b: コンフリクトチェック + スケジュール管理
   ================================================================ */

/* -- Conflict Check -- */
.conflict-result-ok {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.8rem 1.2rem; border-radius: 8px;
  background: var(--green-bg); border: 1px solid #86efac;
  margin-bottom: 1rem;
}
.conflict-result-ok strong { color: var(--green-text); font-size: 0.88rem; }
.conflict-result-warn {
  display: flex; align-items: flex-start; gap: 0.8rem;
  padding: 0.8rem 1.2rem; border-radius: 8px;
  background: #fffbeb; border: 1px solid #fcd34d;
  margin-bottom: 0.5rem;
}
.conflict-result-warn strong { color: #92400e; font-size: 0.88rem; }
.conflict-result-warn p { color: #78350f; margin: 0; }
.conflict-result-danger {
  display: flex; align-items: flex-start; gap: 0.8rem;
  padding: 0.8rem 1.2rem; border-radius: 8px;
  background: var(--red-bg); border: 1px solid #fca5a5;
  margin-bottom: 0.5rem;
}
.conflict-result-danger strong { color: var(--red-text); font-size: 0.88rem; }
.conflict-result-danger p { color: var(--red-text); margin: 0; }
.conflict-match-item {
  padding: 0.4rem 0.8rem; margin: 0.25rem 0;
  border-radius: 6px; font-size: 0.82rem;
}
.conflict-match-danger { background: #fef2f2; border-left: 3px solid var(--red); }
.conflict-match-warning { background: #fffbeb; border-left: 3px solid #f59e0b; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
.badge-orange { background: #ffedd5; color: #c2410c; }

/* -- Schedule Management -- */
.schedule-reminders {
  display: flex; align-items: flex-start; gap: 0.8rem;
  padding: 0.8rem 1.2rem; border-radius: 8px;
  background: #fffbeb; border: 1px solid #fcd34d;
  margin-bottom: 1.2rem;
}
.schedule-reminders strong { color: #92400e; font-size: 0.88rem; }
.schedule-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 0.8rem; margin-bottom: 1rem;
}
.schedule-view-tabs { display: flex; gap: 4px; }
.schedule-tab {
  display: inline-block; padding: 0.4rem 1rem;
  border-radius: 6px; font-size: 0.82rem; font-weight: 500;
  background: var(--bg-alt); color: var(--text-light);
  text-decoration: none; transition: all var(--transition);
}
.schedule-tab:hover { background: #e2e8f0; color: var(--text); }
.schedule-tab.active { background: var(--primary-light); color: white; }
.schedule-month-nav {
  display: flex; align-items: center; justify-content: center;
  gap: 1.5rem; margin-bottom: 1rem;
}

/* Calendar Grid */
.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 1px; background: var(--border-color);
  border: 1px solid var(--border-color); border-radius: 8px;
  overflow: hidden;
}
.cal-header {
  background: var(--primary); color: white;
  padding: 0.5rem; text-align: center;
  font-size: 0.75rem; font-weight: 600;
}
.cal-cell {
  background: white; min-height: 80px; padding: 4px;
  position: relative; vertical-align: top;
}
.cal-empty { background: #fafafa; }
.cal-today { background: #eff6ff; }
.cal-day {
  font-size: 0.78rem; font-weight: 600; color: var(--text-light);
  margin-bottom: 2px;
}
.cal-today .cal-day { color: var(--primary-light); font-weight: 700; }
.cal-event {
  display: block; padding: 1px 4px; border-radius: 3px;
  font-size: 0.65rem; margin-bottom: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-decoration: none; color: white;
}
.cal-event-hearing { background: #3b82f6; }
.cal-event-deadline { background: #ef4444; }
.cal-event-meeting { background: #22c55e; }
.cal-event-filing { background: #8b5cf6; }
.cal-event-other { background: #94a3b8; }
.cal-event-done { opacity: 0.4; text-decoration: line-through; }
.cal-time { font-weight: 600; margin-right: 2px; }
.cal-more { font-size: 0.6rem; color: var(--text-light); }

/* Schedule List */
.schedule-list { margin-bottom: 1rem; }
.schedule-list-compact .schedule-item { padding: 0.5rem 0.8rem; }
.schedule-date-header {
  padding: 0.4rem 0.8rem; margin-top: 0.8rem;
  font-size: 0.82rem; font-weight: 600; color: var(--text-light);
  border-bottom: 1px solid var(--border-color);
}
.schedule-date-header:first-child { margin-top: 0; }
.schedule-today { color: var(--primary-light); border-bottom-color: var(--primary-light); }
.schedule-past { color: #94a3b8; }
.schedule-item {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 0.7rem 0.8rem; border-bottom: 1px solid #f1f5f9;
  transition: background var(--transition);
}
.schedule-item:hover { background: #f8fafc; }
.schedule-done { opacity: 0.55; }
.schedule-overdue { border-left: 3px solid var(--red); background: #fef2f2; }
.schedule-item-left { display: flex; align-items: flex-start; gap: 0.6rem; flex: 1; }
.schedule-check {
  background: none; border: none; font-size: 1.1rem;
  cursor: pointer; padding: 0; line-height: 1;
  color: var(--text-light); transition: color var(--transition);
}
.schedule-check:hover { color: var(--primary-light); }
.schedule-item-title { font-size: 0.85rem; font-weight: 500; line-height: 1.5; }
.schedule-item-meta { font-size: 0.75rem; color: #64748b; margin-top: 0.15rem; }
.schedule-item-desc { font-size: 0.75rem; color: #94a3b8; margin-top: 0.15rem; }
.schedule-item-actions { display: flex; gap: 4px; flex-shrink: 0; align-items: flex-start; }
.line-through { text-decoration: line-through; }

/* Dashboard Schedule Widget */
.dash-schedule-widget {
  background: white; border-radius: var(--radius);
  border: 1px solid var(--border-color); padding: 0.6rem;
  box-shadow: var(--shadow);
}
.dash-schedule-item {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.5rem 0.6rem; border-radius: 6px;
  text-decoration: none; color: inherit;
  transition: background var(--transition);
}
.dash-schedule-item:hover { background: #f8fafc; }
.dash-schedule-today { background: #eff6ff; }
.dash-schedule-date {
  display: flex; flex-direction: column; align-items: center;
  min-width: 44px; flex-shrink: 0;
}
.dash-schedule-month { font-size: 0.6rem; color: #94a3b8; font-weight: 500; }
.dash-schedule-day { font-size: 1.3rem; font-weight: 700; color: var(--primary); line-height: 1.1; }
.dash-schedule-info {
  display: flex; flex-direction: column; gap: 1px;
  min-width: 0; flex: 1;
}
.dash-schedule-left {
  display: flex; align-items: center; gap: 0.8rem;
  flex: 1; min-width: 0;
}
.dash-schedule-title {
  font-size: 0.82rem; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}

/* Responsive */
@media (max-width: 640px) {
  .schedule-toolbar { flex-direction: column; align-items: stretch; }
  .calendar-grid { font-size: 0.7rem; }
  .cal-cell { min-height: 54px; padding: 2px; }
  .cal-event { font-size: 0.55rem; }
  .schedule-item { flex-direction: column; gap: 0.5rem; }
  .schedule-item-actions { align-self: flex-end; }
  .conflict-result-ok, .conflict-result-warn, .conflict-result-danger { flex-direction: column; gap: 0.4rem; }
}

/* v6b-2: コンフリクト自動検出 追加CSS */
.conflict-auto-section {
  background: white; border-radius: var(--radius);
  border: 1px solid var(--border-color); padding: 1.2rem;
  box-shadow: var(--shadow); margin-bottom: 1.5rem;
}
.conflict-auto-alert {
  margin: 1rem 0 1.5rem; padding: 0; border-radius: var(--radius);
  border: 1px solid #fca5a5; background: #fff8f8;
  overflow: hidden;
}
.conflict-auto-alert-header {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.8rem 1rem;
  background: linear-gradient(135deg, #fef2f2, #fff8f0);
  border-bottom: 1px solid #fde4e4;
}
.conflict-auto-alert-header strong { font-size: 0.88rem; color: #991b1b; }
.conflict-auto-alert-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.45rem 1rem; border-bottom: 1px solid #fef2f2;
  font-size: 0.82rem;
}
.conflict-auto-alert-item:last-child { border-bottom: none; }
.conflict-auto-alert-danger { background: #fef2f2; }
.conflict-auto-alert-warning { background: #fffbeb; }
.conflict-confirm-box {
  margin: 0.8rem 0 1rem; padding: 0.8rem 1rem;
  background: #fffbeb; border: 1px solid #fcd34d;
  border-radius: 8px;
}
.conflict-server-block { margin-bottom: 1.2rem; }

/* v6b-3: スケジュール自動抽出UI */
.extract-result-box {
  background: #fafbfc; border: 1px solid var(--border-color);
  border-radius: var(--radius); margin: 0.5rem 0 1rem;
  overflow: hidden;
}
.extract-result-header {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.8rem 1rem; background: linear-gradient(135deg, #eef6ff, #f0fdf4);
  border-bottom: 1px solid var(--border-color);
}
.extract-group { padding: 0.4rem 0; }
.extract-group-label {
  font-size: 0.78rem; font-weight: 700; color: #475569;
  padding: 0.4rem 1rem; background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
}
.extract-group-collapsed .extract-group-label { cursor: pointer; }
.extract-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.35rem 1rem; cursor: pointer; font-size: 0.82rem;
  border-bottom: 1px solid #f1f5f9; transition: background 0.15s;
}
.extract-item:hover { background: #f0f9ff; }
.extract-item input[type="checkbox"] { flex-shrink: 0; margin: 0; }
.extract-date { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 90px; }
.extract-time { color: #6366f1; font-size: 0.78rem; min-width: 42px; }
.extract-title { flex: 1; }
.extract-source { font-size: 0.7rem; color: #94a3b8; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.extract-context {
  font-size: 0.72rem; color: #64748b; padding: 0.15rem 1rem 0.4rem 2.8rem;
  line-height: 1.5; background: #fafbfc; border-bottom: 1px solid #f1f5f9;
}
.extract-actions {
  display: flex; align-items: center; gap: 8px;
  padding: 0.7rem 1rem; background: white;
  border-top: 1px solid var(--border-color);
}
.extract-actions .btn-outline-sm,
.main .btn-outline-sm {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0.35rem 0.7rem; font-size: 0.78rem;
  color: var(--primary); background: white;
  border: 1px solid var(--primary); border-radius: 6px;
  cursor: pointer; transition: all 0.15s;
}
.extract-actions .btn-outline-sm:hover,
.main .btn-outline-sm:hover { background: #eef2ff; }

/* ══════════════════════════════════════
   v6b-billing: 請求書管理・報酬記録CSS
   ══════════════════════════════════════ */

/* ── 請求書ステータスカード ── */
.invoice-stats {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 1.2rem; justify-content: center;
}
.invoice-stat-card {
  flex: 1; min-width: 100px; max-width: 160px;
  padding: 0.6rem 0.8rem; border-radius: var(--radius);
  border: 1px solid var(--border-color); background: white;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-decoration: none; color: var(--text); transition: all 0.15s;
  font-size: 0.78rem;
}
.invoice-stat-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(79,70,229,0.08); }
.invoice-stat-active { border-color: var(--primary); background: #eef2ff; }
.invoice-stat-icon { font-size: 1.2rem; }
.invoice-stat-value { font-weight: 700; font-size: 1rem; }
.invoice-stat-label { color: var(--text-lighter); font-size: 0.7rem; }
.invoice-stat-amount { font-variant-numeric: tabular-nums; color: var(--text-light); font-size: 0.72rem; }

/* ── 報酬サマリー ── */
.billing-summary {
  display: flex; align-items: center; gap: 1rem; padding: 0.8rem 1rem;
  background: linear-gradient(135deg, #fef3c7, #fffbeb);
  border: 1px solid #f59e0b; border-radius: var(--radius); margin-bottom: 1rem;
}
.billing-summary-item { display: flex; flex-direction: column; }
.billing-summary-label { font-size: 0.72rem; color: #92400e; }
.billing-summary-value { font-size: 1.3rem; font-weight: 700; color: #92400e; font-variant-numeric: tabular-nums; }
.billing-summary-sub { font-size: 0.72rem; color: #b45309; }

/* ── 請求書作成フォーム: 明細 ── */
.invoice-items-section {
  margin-top: 1rem; border: 1px solid var(--border-color);
  border-radius: var(--radius); overflow: hidden;
}
.invoice-items-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 0.8rem; background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
}
.invoice-items-table { margin: 0; }
.invoice-items-table th { font-size: 0.72rem; padding: 0.4rem 0.5rem; }
.invoice-items-table td { padding: 0.35rem 0.4rem; }
.invoice-items-table input, .invoice-items-table select {
  border: 1px solid #e2e8f0; border-radius: 4px; padding: 4px 6px;
}

/* ── 合計表示 ── */
.invoice-totals {
  padding: 0.6rem 0.8rem; background: #f8fafc;
  border-top: 1px solid var(--border-color);
}
.invoice-total-row {
  display: flex; justify-content: flex-end; gap: 2rem;
  padding: 0.2rem 0; font-size: 0.85rem;
}
.invoice-total-row span:first-child { color: #64748b; min-width: 160px; text-align: right; }
.invoice-total-row span:last-child { min-width: 120px; text-align: right; font-variant-numeric: tabular-nums; }
.invoice-total-grand {
  font-weight: 700; font-size: 1.05rem; padding-top: 0.4rem;
  margin-top: 0.3rem; border-top: 2px solid var(--border-color);
}
.invoice-total-grand span:first-child { color: var(--text); }

/* ── 請求書詳細プレビュー ── */
.invoice-preview {
  background: white; border: 1px solid var(--border-color);
  border-radius: var(--radius); padding: 1.5rem; margin-top: 0.8rem;
}
.invoice-preview-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding-bottom: 0.8rem; border-bottom: 2px solid #333;
  margin-bottom: 1rem;
}
.invoice-preview-parties {
  display: flex; justify-content: space-between; gap: 2rem;
  margin-bottom: 1rem;
}
.invoice-party-to, .invoice-party-from { flex: 1; }
.invoice-party-from { text-align: right; }
.invoice-party-label { font-size: 0.7rem; color: #94a3b8; margin-bottom: 2px; }
.invoice-party-name { font-size: 1.05rem; font-weight: 700; margin-bottom: 4px; }

/* ── 未請求報酬取り込み ── */
.unbilled-row { cursor: pointer; }
.unbilled-row:hover { background: #f0f9ff; }

/* ── テーブル共通調整 ── */
.table-wrap { overflow-x: auto; }
.empty-state-card {
  padding: 2rem; text-align: center; color: #64748b;
  background: #f8fafc; border: 1px dashed var(--border-color);
  border-radius: var(--radius);
}

/* ── ツールバー ── */
.toolbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ── レスポンシブ ── */
@media (max-width: 768px) {
  .invoice-stats { gap: 4px; }
  .invoice-stat-card { min-width: 80px; max-width: none; flex: 1; padding: 0.4rem; }
  .invoice-preview-parties { flex-direction: column; gap: 1rem; }
  .invoice-party-from { text-align: left; }
  .billing-summary { flex-direction: column; }
}

/* ── ダッシュボード: 請求統計カード ── */
.dash-stat-card {
  display: flex; flex-direction: column; padding: 0.6rem 0.8rem;
  background: white; border: 1px solid var(--border-color); border-radius: var(--radius);
  text-decoration: none; color: inherit; transition: all 0.15s;
  max-width: 280px;
}
.dash-stat-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); transform: translateY(-1px); }
