/* ============================================================
   売上ダッシュボード - スタイルシート
   Corporate Trust Design
   ============================================================ */

:root {
  --primary: #0056b3;
  --primary-light: #e6f0fa;
  --primary-dark: #003d80;
  --secondary: #6c757d;
  --success: #28a745;
  --danger: #dc3545;
  --warning: #ffc107;
  --info: #17a2b8;
  --surface: #ffffff;
  --background: #f4f6f9;
  --text-main: #212529;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --radius: 4px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --sidebar-width: 260px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  background-color: var(--background);
  color: var(--text-main);
  display: flex;
  min-height: 100vh;
}

/* ---- Hamburger ---- */
.hamburger-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-main);
  transition: background 0.2s;
}
.hamburger-btn:hover { background: #e9ecef; }
.hamburger-btn svg { width: 24px; height: 24px; }

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---- Sidebar Overlay ---- */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  background-color: #1a202c;
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.3s ease;
}

/* PC: sidebar closed */
body.sidebar-closed .sidebar { transform: translateX(-100%); }
body.sidebar-closed .main { margin-left: 0; max-width: 100vw; }

.logo-area {
  height: 60px;
  background-color: #12161f;
  display: flex;
  align-items: center;
  padding: 0 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-size: 1rem;
}

.nav-menu { padding: 12px 0; flex: 1; }

.nav-group-title {
  padding: 10px 20px;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.4);
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  font-size: 0.88rem;
  cursor: pointer;
}

.nav-item:hover, .nav-item.active {
  background-color: rgba(255,255,255,0.1);
  color: #fff;
}
.nav-item.active { border-left-color: var(--primary); }

.nav-icon {
  width: 18px; height: 18px; margin-right: 10px;
  fill: currentColor; flex-shrink: 0;
}

/* ---- Main ---- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  min-width: 0;
  max-width: calc(100vw - var(--sidebar-width));
  transition: margin-left 0.3s ease, max-width 0.3s ease;
}

.header {
  height: 60px;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-title { font-size: 1.15rem; font-weight: 600; }

.header-right { display: flex; align-items: center; gap: 16px; }

.header-date { font-size: 0.85rem; color: var(--text-muted); }

.content-area {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
}

.page { min-width: 0; }

/* ---- KPI Cards ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.stat-card { display: flex; flex-direction: column; }

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.stat-value {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.stat-trend {
  font-size: 0.78rem;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.trend-up, td .trend-up { color: var(--success); font-weight: 600; }
.trend-down, td .trend-down { color: var(--danger); font-weight: 600; }
.trend-flat, td .trend-flat { color: var(--text-muted); }

/* ---- Charts Grid ---- */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}
.charts-grid > * { min-width: 0; }
.stats-grid > * { min-width: 0; }

.chart-container {
  position: relative;
  width: 100%;
  overflow: hidden;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ---- Progress / Gauge ---- */
.gauge-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
}

.progress-bar-container {
  width: 100%;
  background: #e9ecef;
  border-radius: 8px;
  height: 24px;
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 8px;
  transition: width 0.6s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
}

.progress-green { background: linear-gradient(90deg, #28a745, #34ce57); }
.progress-yellow { background: linear-gradient(90deg, #ffc107, #ffdb4d); color: #333; }
.progress-red { background: linear-gradient(90deg, #dc3545, #ff6b6b); }
.progress-blue { background: linear-gradient(90deg, #0056b3, #3399ff); }

/* ---- Table ---- */
.table-container {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 20px;
}

.table-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.table-title { font-weight: 600; font-size: 0.95rem; }

.table-scroll {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background-color: #f8f9fa;
}

.show-more-container {
  padding: 10px 16px;
  text-align: center;
  border-top: 1px solid var(--border);
}

.table-container { min-width: 0; }

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  padding: 10px 16px;
  background-color: #f8f9fa;
  color: var(--text-muted);
  font-size: 0.73rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 10px 16px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tr:last-child td { border-bottom: none; }
tr:hover { background-color: #f8f9fa; }

.text-right { text-align: right; }
.text-center { text-align: center; }

/* ---- Badge ---- */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
}

.badge-success { background: #e8f5e9; color: #2e7d32; }
.badge-warning { background: #fff8e1; color: #f57f17; }
.badge-danger { background: #ffebee; color: #c62828; }
.badge-info { background: #e3f2fd; color: #1565c0; }
.badge-secondary { background: #f5f5f5; color: #616161; }

.badge-rank-a { background: #e8f5e9; color: #2e7d32; }
.badge-rank-b { background: #e3f2fd; color: #1565c0; }
.badge-rank-c { background: #f5f5f5; color: #616161; }

/* ---- Buttons ---- */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e9ecef; color: var(--text-main); }
.btn-secondary:hover { background: #dee2e6; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 0.78rem; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-main);
}
.btn-outline:hover { background: #f8f9fa; }

/* ---- Form ---- */
.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.88rem;
  color: var(--text-main);
  background: #fff;
  transition: border-color 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0,86,179,0.15);
}

select.form-control { cursor: pointer; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

/* ---- Modal ---- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  justify-content: center;
  align-items: flex-start;
  padding-top: 80px;
}
.modal-overlay.show { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  width: 90%;
  max-width: 640px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title { font-weight: 600; font-size: 1rem; }

.modal-close {
  background: none; border: none;
  font-size: 1.3rem; cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
}

.modal-body { padding: 20px; }
.modal-body p { white-space: pre-line; line-height: 1.7; }

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---- Filters ---- */
.filters {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filters .form-group {
  flex: 1 1 130px;
  min-width: 100px;
  max-width: 200px;
  margin-bottom: 0;
}

.filters .form-control {
  width: 100% !important;
  min-width: 0;
}

.filter-item {
  margin-bottom: 0;
}

.filter-btn {
  flex: 0 0 auto;
  padding-top: 18px;
}

/* ---- Alert Items ---- */
.alert-item {
  padding: 12px 16px;
  border-left: 4px solid var(--danger);
  background: #fff5f5;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: 8px;
  font-size: 0.85rem;
}

.alert-item.info {
  border-left-color: var(--info);
  background: #f0f9ff;
}

.alert-item .alert-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.alert-item .alert-detail {
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ---- Forecast Card ---- */
.forecast-scenarios {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.scenario-card {
  padding: 12px;
  border-radius: var(--radius);
  text-align: center;
}

.scenario-card.optimistic { background: #e8f5e9; }
.scenario-card.realistic { background: #e3f2fd; }
.scenario-card.pessimistic { background: #fff3e0; }

.scenario-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.scenario-value {
  font-size: 1.1rem;
  font-weight: 700;
}

/* ---- Ranking ---- */
.rank-1 { color: #FFD700; font-weight: 700; }
.rank-2 { color: #C0C0C0; font-weight: 700; }
.rank-3 { color: #CD7F32; font-weight: 700; }

/* ---- Loading ---- */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  color: var(--text-muted);
  white-space: nowrap;
  font-size: 0.85rem;
}

.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 10px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 12px 20px;
  margin-bottom: 8px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 0.3s ease;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ---- Page sections ---- */
.page { display: none; }
.page.active { display: block; }

/* ---- Responsive ---- */
@media (max-width: 1400px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .filters { gap: 8px; }
  .filters .form-group { flex: 1 1 120px; min-width: 0; }
  .filters .form-control { width: 100%; min-width: 0; }
}

@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.4rem; }
}

@media (max-width: 1000px) {
  :root { --sidebar-width: 200px; }
  .sidebar { width: 200px; }
  .main { margin-left: 200px; max-width: calc(100vw - 200px); }
  .logo-area { font-size: 0.85rem; padding: 0 12px; }
  .nav-item { padding: 8px 12px; font-size: 0.82rem; }
  .nav-icon { width: 16px; height: 16px; margin-right: 8px; }
  .content-area { padding: 16px; }
}

@media (max-width: 768px) {
  /* Sidebar: transform方式（display:noneではなく） */
  .sidebar {
    transform: translateX(-100%);
  }
  .main { margin-left: 0; max-width: 100vw; }

  /* Sidebar open state */
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-overlay { display: block; }

  /* Header fixed */
  .header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
  }
  .content-area {
    padding: 12px;
    padding-top: 72px; /* 60px header + 12px */
  }

  /* Table vertical scroll */
  .table-scroll {
    max-height: 50vh;
  }

  /* KPI cards: 2列、見切れ防止 */
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .stat-card { padding: 14px; min-width: 0; }
  .stat-value { font-size: clamp(0.85rem, 4vw, 1.1rem); word-break: break-all; }
  .stat-label { font-size: 0.72rem; }
  .stat-sub { font-size: 0.68rem; }
  .stat-trend { font-size: 0.7rem; }

  .form-row { grid-template-columns: 1fr; }
  .forecast-scenarios { grid-template-columns: 1fr; }
  .header { padding: 0 12px; }

  /* Filters: 縦伸び防止、コンパクト */
  .filters {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .filters .form-group {
    width: 100%;
    max-width: 100%;
    flex: 0 0 auto;
  }
  .filters .form-group label { margin-bottom: 2px; }
  .filter-btn { padding-top: 4px; }
}
