/* ===================================================
   労務安全DXシステム - グローバルスタイル
   宮田建設工業株式会社
   =================================================== */

/* --- CSS Variables (Design System) --- */
:root {
  --primary: #1e3a5f;
  --primary-light: #2d5282;
  --primary-dark: #152b47;
  --accent: #f97316;
  --accent-light: #fb923c;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --tier1: #10b981;
  --tier2: #0d9488;
  --tier3: #0891b2;
  --tier4: #7c3aed;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ===================================================
   LOGIN SCREEN
   =================================================== */
.login-screen {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary) 0%, #2d5282 50%, #1a365d 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo .company-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.3;
}
.login-logo .system-name {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.login-logo .logo-icon {
  width: 64px;
  height: 64px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}
.login-logo .logo-icon i { color: #fff; font-size: 28px; }
.role-select-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-align: center;
}
.role-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}
.role-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
}
.role-card:hover { border-color: var(--primary); background: #f0f6ff; }
.role-card.selected { border-color: var(--primary); background: #e8f0fe; }
.role-card .role-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.role-card.role-owner .role-icon { background: #dbeafe; color: var(--primary); }
.role-card.role-vendor .role-icon { background: #d1fae5; color: var(--success); }
.role-card.role-admin .role-icon { background: #fef3c7; color: var(--warning); }
.role-card .role-info .role-name { font-weight: 700; font-size: 15px; }
.role-card .role-info .role-desc { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  transition: background 0.2s;
}
.login-btn:hover { background: var(--primary-light); }
.login-btn:disabled { background: var(--text-muted); cursor: not-allowed; }
.api-key-section {
  margin-top: 20px;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.api-key-section label { font-size: 12px; font-weight: 600; color: var(--text-secondary); display: block; margin-bottom: 6px; }
.api-key-section input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
}
.api-key-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ===================================================
   LAYOUT - OWNER DASHBOARD
   =================================================== */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.app-header {
  background: var(--primary);
  color: #fff;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.header-left { display: flex; align-items: center; gap: 16px; }
.header-logo { display: flex; align-items: center; gap: 10px; }
.header-logo i { font-size: 22px; color: var(--accent); }
.header-logo .company { font-weight: 700; font-size: 16px; line-height: 1.2; }
.header-logo .system { font-size: 11px; opacity: 0.8; }
.header-divider { width: 1px; height: 30px; background: rgba(255,255,255,0.2); }
.header-project { font-size: 13px; opacity: 0.9; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 18px;
  padding: 6px;
  border-radius: 6px;
  transition: all 0.2s;
  position: relative;
}
.header-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.notification-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  background: var(--danger);
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.header-user { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.header-user .avatar {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}
.logout-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  transition: all 0.2s;
}
.logout-btn:hover { background: rgba(255,255,255,0.2); }

/* Main Content */
.app-main {
  display: flex;
  flex: 1;
}
.app-sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  flex-shrink: 0;
}
.nav-section { margin-bottom: 8px; }
.nav-section-title {
  padding: 8px 20px 4px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.nav-item i { width: 18px; text-align: center; font-size: 15px; }
.nav-item:hover { background: var(--bg); color: var(--primary); }
.nav-item.active { background: #e8f0fe; color: var(--primary); border-left-color: var(--primary); font-weight: 600; }
.app-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
}

/* ===================================================
   DASHBOARD COMPONENTS
   =================================================== */

/* Project Context Bar */
.project-context {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.project-context .project-name { font-size: 18px; font-weight: 700; color: var(--primary); }
.project-context .project-meta { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.project-context .project-status { display: flex; align-items: center; gap: 12px; }
.progress-bar-wrap { width: 160px; }
.progress-label { font-size: 11px; color: var(--text-secondary); margin-bottom: 4px; display: flex; justify-content: space-between; }
.progress-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.3s; }

/* Stats Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}
.stat-card.total::before { background: var(--primary); }
.stat-card.complete::before { background: var(--success); }
.stat-card.defect::before { background: var(--warning); }
.stat-card.pending::before { background: var(--danger); }
.stat-card .stat-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.stat-card .stat-value { font-size: 32px; font-weight: 700; line-height: 1; }
.stat-card.total .stat-value { color: var(--primary); }
.stat-card.complete .stat-value { color: var(--success); }
.stat-card.defect .stat-value { color: var(--warning); }
.stat-card.pending .stat-value { color: var(--danger); }
.stat-card .stat-icon {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 24px;
  opacity: 0.2;
}
.stat-card .stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* Tabs */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  gap: 0;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
  border: 1px solid var(--border);
}
.tab-btn {
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab-btn i { font-size: 13px; }
.tab-btn:hover { color: var(--primary); background: var(--bg); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--surface); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* スマホ専用表示制御 */
.sp-only { display: none; }
@media (max-width: 768px) {
  .sp-only { display: block; }
  .pc-only { display: none !important; }
  /* アクションバーをスマホで縦並び */
  .action-bar { padding: 10px 12px; gap: 8px; }
  .action-bar-left { flex-direction: column; align-items: stretch; gap: 6px; width: 100%; }
  .action-bar-right { justify-content: flex-end; }
  .search-box { min-width: 0; width: 100%; }
  .filter-select { font-size: 12px; padding: 5px 8px; }
}

/* Action Bar */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.action-bar-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.action-bar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  min-width: 200px;
}
.search-box i { color: var(--text-muted); font-size: 13px; }
.search-box input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  width: 100%;
}
.filter-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text-primary);
  outline: none;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
  cursor: pointer;
  white-space: nowrap;
}
.btn i { font-size: 12px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-light); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-outline {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.btn-outline-primary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline-primary:hover { background: var(--primary); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: #f1f5f9; color: #475569; }
.badge-primary { background: #dbeafe; color: var(--primary); }

/* Tier Badges */
.tier-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.tier-0 { background: var(--primary); }
.tier-1 { background: var(--tier1); }
.tier-2 { background: var(--tier2); }
.tier-3 { background: var(--tier3); }
.tier-4 { background: var(--tier4); }

/* Table */
.data-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead { background: var(--bg); }
.data-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}
.data-table tbody tr:hover { background: #f8f9ff; }
.data-table tbody tr.selected { background: #e8f0fe; }
.company-cell { display: flex; align-items: center; gap: 8px; }
.tier-indent { display: flex; align-items: center; gap: 4px; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
}
.card-title { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.card-body { padding: 20px; }

/* Defect Panel */
.defect-panel {
  background: #fff8f0;
  border: 1px solid #fed7aa;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.defect-panel .panel-header {
  padding: 12px 16px;
  background: #ffedd5;
  border-bottom: 1px solid #fed7aa;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.defect-panel .panel-title { font-size: 13px; font-weight: 700; color: #c2410c; display: flex; align-items: center; gap: 6px; }
.defect-list { padding: 8px 0; }
.defect-item {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #fed7aa;
  font-size: 13px;
  gap: 12px;
}
.defect-item:last-child { border-bottom: none; }
.defect-info { flex: 1; }
.defect-company { font-weight: 600; color: var(--text-primary); }
.defect-detail { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ===================================================
   VENDOR DETAIL PANEL (SLIDE-IN)
   =================================================== */
.side-panel {
  position: fixed;
  top: 60px;
  right: 0;
  width: 420px;
  height: calc(100vh - 60px);
  background: var(--surface);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  z-index: 90;
  box-shadow: -4px 0 20px rgba(0,0,0,0.1);
}
.side-panel.open { transform: translateX(0); }
.side-panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.side-panel-title { font-size: 16px; font-weight: 700; }
.close-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-secondary);
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s;
}
.close-btn:hover { background: var(--bg); color: var(--text-primary); }
.side-panel-body { padding: 20px; }

/* Document List */
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  gap: 12px;
}
.doc-item .doc-info { display: flex; align-items: center; gap: 10px; flex: 1; }
.doc-item .doc-icon { font-size: 18px; }
.doc-item .doc-name { font-size: 13px; font-weight: 600; }
.doc-item .doc-date { font-size: 11px; color: var(--text-muted); }
.doc-actions { display: flex; gap: 6px; }

/* Timeline */
.timeline { position: relative; }
.timeline::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 20px;
  width: 2px;
  background: var(--border);
}
.timeline-item {
  display: flex;
  gap: 12px;
  padding: 0 0 16px 0;
  position: relative;
}
.timeline-dot {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  z-index: 1;
}
.timeline-dot.system { background: #dbeafe; color: var(--primary); }
.timeline-dot.owner { background: #fef3c7; color: var(--warning); }
.timeline-dot.vendor { background: #d1fae5; color: var(--success); }
.timeline-content { flex: 1; }
.timeline-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.timeline-actor { font-size: 13px; font-weight: 600; }
.timeline-time { font-size: 11px; color: var(--text-muted); }
.timeline-text { font-size: 13px; color: var(--text-secondary); }

/* Message Input */
.message-input-wrap {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.message-input-wrap textarea {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  resize: none;
  font-size: 13px;
  line-height: 1.4;
}
.message-input-wrap textarea:focus { outline: none; border-color: var(--primary); }

/* ===================================================
   CONSTRUCTION HIERARCHY CHART
   =================================================== */
.hierarchy-chart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  position: relative;
}
.chart-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.chart-toolbar h3 { font-size: 14px; font-weight: 700; }
.zoom-controls { display: flex; align-items: center; gap: 6px; }
.zoom-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}
.zoom-btn:hover { background: var(--bg); border-color: var(--primary); }
.zoom-level { font-size: 12px; color: var(--text-secondary); min-width: 40px; text-align: center; }
.chart-canvas-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 32px;
  min-height: 500px;
  position: relative;
}
.chart-canvas {
  transform-origin: top left;
  transition: transform 0.2s;
}

/* Tree Nodes */
.tree-root { display: flex; flex-direction: column; align-items: center; }
.tree-level { display: flex; gap: 32px; justify-content: center; align-items: flex-start; position: relative; }
.tree-level-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 8px;
  padding: 3px 8px;
  border-radius: 3px;
  align-self: center;
}
.tree-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}
.tree-connector-v {
  width: 2px;
  height: 24px;
  background: var(--border);
}
.tree-connector-h {
  height: 2px;
  background: var(--border);
  position: absolute;
  top: 0;
}
.company-box {
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 160px;
  max-width: 200px;
  text-align: center;
  position: relative;
  box-shadow: var(--shadow-sm);
  border: 2px solid;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.company-box:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.company-box.tier-owner { background: #dbeafe; border-color: var(--primary); }
.company-box.tier-1 { background: #d1fae5; border-color: var(--tier1); }
.company-box.tier-2 { background: #ccfbf1; border-color: var(--tier2); }
.company-box.tier-3 { background: #cffafe; border-color: var(--tier3); }
.company-box.tier-4 { background: #ede9fe; border-color: var(--tier4); }
.company-box .cb-name { font-size: 13px; font-weight: 700; line-height: 1.3; }
.company-box .cb-work { font-size: 11px; color: var(--text-secondary); margin-top: 3px; }
.company-box .cb-status {
  position: absolute;
  top: -8px;
  right: -8px;
  font-size: 16px;
  line-height: 1;
}
.company-box .cb-permit { font-size: 10px; color: var(--text-muted); margin-top: 4px; }

/* Children Container */
.tree-children {
  display: flex;
  gap: 24px;
  position: relative;
  padding-top: 24px;
  justify-content: center;
}
.tree-children::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 2px;
  height: 24px;
  background: var(--border);
  transform: translateX(-50%);
}

/* ===================================================
   VENDOR PORTAL (MOBILE UI)
   =================================================== */
.vendor-portal {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
}
.mobile-frame {
  width: 100%;
  max-width: 390px;
  min-height: 700px;
  background: var(--surface);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  position: relative;
  display: flex;
  flex-direction: column;
}
.mobile-header {
  background: var(--primary);
  color: #fff;
  padding: 16px 20px 12px;
}
.mobile-header .project-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 8px;
}
.mobile-header .project-title { font-size: 16px; font-weight: 700; line-height: 1.3; }
.mobile-header .project-sub { font-size: 12px; opacity: 0.8; margin-top: 2px; }

/* Step Progress */
.step-indicator {
  padding: 12px 20px;
  background: var(--primary);
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.step-dots { display: flex; align-items: center; justify-content: center; gap: 8px; }
.step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  transition: all 0.3s;
  background: rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.6);
  position: relative;
}
.step-dot.completed { background: var(--success); color: #fff; }
.step-dot.active { background: var(--accent); color: #fff; }
.step-connector {
  flex: 1;
  height: 2px;
  background: rgba(255,255,255,0.2);
  max-width: 40px;
}
.step-connector.completed { background: var(--success); }
.step-label { text-align: center; font-size: 11px; color: rgba(255,255,255,0.7); margin-top: 6px; }

/* Mobile Scroll Body */
.mobile-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--bg);
}
.mobile-footer {
  padding: 16px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}
.mobile-footer .btn { flex: 1; justify-content: center; padding: 12px; font-size: 14px; }

/* Forms */
.form-section { margin-bottom: 20px; }
.form-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text-primary);
  transition: border-color 0.2s;
  outline: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,58,95,0.1); }
.form-control.error { border-color: var(--danger); }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 11px; color: var(--danger); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Upload Area */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg);
  position: relative;
}
.upload-area:hover, .upload-area.drag-over { border-color: var(--primary); background: #f0f6ff; }
.upload-area input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.upload-area .upload-icon { font-size: 32px; color: var(--text-muted); margin-bottom: 8px; }
.upload-area .upload-text { font-size: 14px; color: var(--text-secondary); font-weight: 600; }
.upload-area .upload-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.upload-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 10px;
}
.upload-preview img { width: 48px; height: 48px; object-fit: cover; border-radius: 4px; }
.upload-preview .file-info .file-name { font-size: 13px; font-weight: 600; }
.upload-preview .file-info .file-size { font-size: 11px; color: var(--text-muted); }

/* AI Processing State */
.ai-processing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  gap: 12px;
  text-align: center;
}
.ai-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.ai-processing .ai-text { font-size: 14px; color: var(--text-secondary); font-weight: 600; }
.ai-processing .ai-sub { font-size: 12px; color: var(--text-muted); }
.ai-result-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}
.ai-result-badge.success { background: #d1fae5; color: #065f46; }
.ai-result-badge.warning { background: #fef3c7; color: #92400e; }

/* Worker List */
.worker-list { display: flex; flex-direction: column; gap: 8px; }
.worker-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.worker-info .worker-name { font-size: 14px; font-weight: 700; }
.worker-info .worker-role { font-size: 11px; color: var(--text-secondary); }
.worker-info .worker-certs { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.worker-cert { background: #dbeafe; color: var(--primary); padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; }
.worker-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-secondary);
}
.icon-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.icon-btn.danger:hover { background: var(--danger); border-color: var(--danger); }

/* Submit Checklist */
.checklist { display: flex; flex-direction: column; gap: 8px; }
.checklist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.checklist-item.ok { border-color: var(--success); background: #f0fdf4; }
.checklist-item.warn { border-color: var(--warning); background: #fffbeb; }
.checklist-item.fail { border-color: var(--danger); background: #fef2f2; }
.checklist-icon { font-size: 18px; flex-shrink: 0; }
.checklist-text .check-title { font-size: 13px; font-weight: 600; }
.checklist-text .check-detail { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

/* ===================================================
   PRINT PREVIEW
   =================================================== */
.print-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 20px;
}
.print-modal-inner {
  background: var(--bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 1100px;
  overflow: hidden;
}
.print-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--primary);
  color: #fff;
  gap: 12px;
}
.print-toolbar h3 { font-size: 15px; font-weight: 700; }
.print-toolbar .toolbar-btns { display: flex; gap: 8px; }
.print-page {
  background: #fff;
  margin: 20px auto;
  box-shadow: var(--shadow-lg);
  position: relative;
}
.print-page.a3-landscape { width: 1122px; min-height: 794px; padding: 28px; }
.print-page.a4-portrait { width: 794px; min-height: 1123px; padding: 28px; }
.print-page-title {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  border: 2px solid #000;
  padding: 8px;
  margin-bottom: 12px;
}
.print-info-row {
  display: flex;
  gap: 0;
  border: 1px solid #000;
  margin-bottom: 12px;
}
.print-info-cell {
  flex: 1;
  padding: 6px 12px;
  border-right: 1px solid #000;
  font-size: 12px;
}
.print-info-cell:last-child { border-right: none; }
.print-info-cell .label { font-size: 10px; color: #666; margin-bottom: 2px; }
.print-info-cell .value { font-weight: 600; }
.print-tree { display: flex; flex-direction: column; align-items: center; gap: 0; }
.print-company-box {
  border: 2px solid;
  padding: 8px 12px;
  min-width: 140px;
  text-align: center;
  font-size: 11px;
  background: #fff;
}
.print-company-box.tier-owner { border-color: var(--primary); background: #dbeafe; }
.print-company-box.tier-1 { border-color: var(--tier1); background: #d1fae5; }
.print-company-box.tier-2 { border-color: var(--tier2); background: #ccfbf1; }
.print-company-box.tier-3 { border-color: var(--tier3); background: #cffafe; }
.print-company-box.tier-4 { border-color: var(--tier4); background: #ede9fe; }
.print-company-box .pcb-name { font-weight: 700; font-size: 12px; margin-bottom: 4px; }
.print-company-box .pcb-row { display: flex; justify-content: space-between; font-size: 10px; color: #444; line-height: 1.6; }

/* ===================================================
   MODAL
   =================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ===================================================
   TOAST NOTIFICATIONS
   =================================================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  min-width: 260px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
.toast.info { background: var(--primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(100%); } }

/* ===================================================
   MISC UTILITIES
   =================================================== */
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.text-sm { font-size: 12px; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.font-bold { font-weight: 700; }
.text-center { text-align: center; }
.w-full { width: 100%; }
.section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
  display: inline-block;
}
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state i { font-size: 48px; margin-bottom: 12px; display: block; }
.empty-state p { font-size: 14px; }

/* Info Section */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.info-item .info-label { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; font-weight: 600; text-transform: uppercase; }
.info-item .info-value { font-size: 14px; font-weight: 600; color: var(--text-primary); }

/* Divider */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* Checkbox */
.checkbox-group { display: flex; flex-direction: column; gap: 8px; }
.checkbox-item { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-item input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.checkbox-item label { font-size: 13px; cursor: pointer; }

/* Radio Group */
.radio-group { display: flex; gap: 12px; flex-wrap: wrap; }
.radio-item { display: flex; align-items: center; gap: 6px; }
.radio-item input[type="radio"] { accent-color: var(--primary); }
.radio-item label { font-size: 13px; cursor: pointer; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 12px; }
.page-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:hover:not(.active) { background: var(--bg); }

/* KY Report */
.ky-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.ky-card .ky-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.ky-card .ky-title { font-size: 14px; font-weight: 700; }
.ky-card .ky-date { font-size: 12px; color: var(--text-muted); }
.ky-item { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.ky-item:last-child { border-bottom: none; }
.ky-num { font-weight: 700; color: var(--accent); min-width: 20px; }

/* Certificate Expiry */
.cert-table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cert-row {
  display: grid;
  grid-template-columns: 2fr 2fr 2fr 1fr 1fr;
  padding: 10px 16px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.cert-row.header { background: var(--bg); font-size: 11px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; }
.cert-row:last-child { border-bottom: none; }
.cert-row.expiring { background: #fffbeb; }
.cert-row.expired { background: #fef2f2; }

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

/* タブバー：スマホで横スクロール可能に */
.tab-bar {
  overflow-x: auto !important;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  flex-wrap: nowrap !important;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .app-sidebar { display: none; }
  .side-panel { width: 100%; right: 0; left: 0; }
}

@media (max-width: 768px) {
  /* ヘッダー */
  .app-header { padding: 0 12px; height: 52px; }
  .header-logo .company { font-size: 13px; }
  .header-logo .system { display: none; }
  .header-divider { display: none; }
  .header-project { display: none; }
  .header-user span { display: none; }
  .logout-btn { padding: 4px 8px; font-size: 11px; }
  .logout-btn i { margin-right: 0 !important; }
  .logout-btn::after { content: ''; }

  /* メインコンテンツ */
  .app-content {
    padding: 10px;
    max-height: calc(100vh - 52px);
  }

  /* 統計カード */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
  .stat-card { padding: 12px; }
  .stat-card .stat-value { font-size: 24px; }
  .stat-card .stat-sub { display: none; }

  /* プロジェクトコンテキスト */
  .project-context { padding: 10px 12px; gap: 8px; }
  .project-context .project-name { font-size: 14px; }
  .project-context .project-meta { font-size: 11px; }
  .progress-bar-wrap { width: 120px; }
  .project-context .project-status { flex-wrap: wrap; gap: 6px; }
  .project-context .btn-sm { padding: 4px 8px; font-size: 11px; }

  /* タブバー */
  .tab-btn { padding: 10px 12px; font-size: 11px; gap: 4px; }
  .tab-btn i { font-size: 12px; }

  /* テーブル */
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 7px 8px; }

  /* 不備カード */
  .defect-item { flex-wrap: wrap; }
  .defect-item > div:last-child { width: 100%; justify-content: flex-end; }

  /* 業者詳細パネル */
  .side-panel {
    top: 52px;
    height: calc(100vh - 52px);
    width: 100%;
  }

  /* 施工体系図コンテナ */
  #hierarchy-chart-container {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    min-height: 320px;
  }
  .hierarchy-chart {
    overflow: visible;
  }
  .chart-canvas-wrap {
    padding: 8px;
    min-height: 300px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  .chart-toolbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }
  .chart-toolbar h3 { font-size: 12px; }
  .zoom-btn { width: 32px; height: 32px; font-size: 16px; }
  .zoom-level { font-size: 11px; min-width: 34px; }

  /* KYカード */
  .ky-card { padding: 12px; }
  .ky-header { flex-wrap: wrap; gap: 6px; }

  /* 資格期限テーブル */
  .cert-row { grid-template-columns: 1fr 1fr 80px; font-size: 12px; }
  .cert-row .col-vendor { display: none; }

  /* タイムライン */
  .timeline-item { gap: 8px; }
  .timeline-content { padding: 10px 12px; }

  /* モーダル */
  .modal { width: calc(100vw - 24px); max-width: 100%; margin: 12px; }
  .modal-body { padding: 16px; }

  /* アクションバー */
  .action-bar { flex-wrap: wrap; gap: 8px; }
  .action-bar .btn { font-size: 12px; padding: 6px 10px; }

  /* フォームセンター */
  .forms-grid { grid-template-columns: 1fr !important; }

  /* 業者一覧テーブル列非表示 */
  .data-table .col-hide-mobile { display: none; }

  /* 空ステート */
  .empty-state { padding: 32px 16px; }
  .empty-state i { font-size: 40px; }
}

/* Print Styles */
@media print {
  .app-header, .app-sidebar, .print-toolbar, .no-print { display: none !important; }
  .print-page { margin: 0; box-shadow: none; }
  body { background: #fff; }
}

/* ===================================================
   ADMIN PANEL
   =================================================== */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.admin-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); }
.admin-card i { font-size: 32px; color: var(--primary); margin-bottom: 10px; display: block; }
.admin-card .admin-card-title { font-size: 14px; font-weight: 700; }
.admin-card .admin-card-desc { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===================================================
   CUSTOM SCROLLBAR
   =================================================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===================================================
   ANIMATIONS
   =================================================== */
.fade-in { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.slide-up { animation: slideUp 0.3s ease; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
