/* ============================================================
   Sanare Action Hub — app.css
   ============================================================ */

/* ── CSS Variables ── */
:root {
  --sah-primary:      #2F63E6;
  --sah-primary-dark: #1A4DC8;
  --sah-primary-light:#EBF0FD;
  --sah-bg:           #F8FAFC;
  --sah-card:         #FFFFFF;
  --sah-text:         #111827;
  --sah-text-sub:     #6B7280;
  --sah-border:       #E5E7EB;
  --sah-success:      #10B981;
  --sah-warning:      #F59E0B;
  --sah-danger:       #EF4444;
  --sah-info:         #3B82F6;
  --sah-sidebar-bg:   #1E3A8A;
  --sah-sidebar-width:240px;
  --sah-topbar-h:     60px;
  --sah-radius:       12px;
  --sah-radius-sm:    8px;
  --sah-shadow:       0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --sah-shadow-md:    0 4px 16px rgba(0,0,0,0.10);
  --sah-font:         'DM Sans', 'Noto Sans JP', sans-serif;
  --sah-transition:   0.18s ease;
}

/* ── Reset / Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sah-font);
  background: var(--sah-bg);
  color: var(--sah-text);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--sah-primary); text-decoration: none; }
a:hover { opacity: 0.8; }
img { max-width: 100%; height: auto; display: block; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ── App Layout ── */
.sah-app-wrapper {
  display: flex;
  min-height: 100vh;
  background: var(--sah-bg);
}

/* ── Sidebar ── */
.sah-sidebar {
  width: var(--sah-sidebar-width);
  background: var(--sah-sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 200;
  transition: transform var(--sah-transition);
  overflow-y: auto;
}
.sah-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sah-sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.sah-sidebar-logo-icon {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
}
.sah-sidebar-close {
  display: none;
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  padding: 4px;
}
.sah-sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sah-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--sah-radius-sm);
  color: rgba(255,255,255,0.7);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--sah-transition), color var(--sah-transition);
  text-decoration: none;
}
.sah-nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
  opacity: 1;
}
.sah-nav-item.is-active {
  background: rgba(255,255,255,0.15);
  color: #fff;
}
.sah-nav-icon { flex-shrink: 0; display: flex; align-items: center; }
.sah-sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sah-sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sah-sidebar-avatar img {
  border-radius: 50%;
  width: 32px; height: 32px;
}
.sah-sidebar-user-name {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sah-sidebar-logout {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.5);
  text-decoration: none;
}
.sah-sidebar-logout:hover { color: rgba(255,255,255,0.8); opacity: 1; }
.sah-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 190;
}

/* ── Main Area ── */
.sah-main-area {
  margin-left: var(--sah-sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ── */
.sah-topbar {
  height: var(--sah-topbar-h);
  background: var(--sah-card);
  border-bottom: 1px solid var(--sah-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.sah-topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.sah-topbar-menu {
  display: none;
  background: none;
  border: none;
  color: var(--sah-text);
  padding: 4px;
  border-radius: 6px;
}
.sah-topbar-title h1 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--sah-text);
  line-height: 1.2;
}
.sah-topbar-date {
  font-size: 0.75rem;
  color: var(--sah-text-sub);
}
.sah-topbar-right { display: flex; align-items: center; gap: 8px; }
.sah-topbar-ai-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--sah-primary-light);
  color: var(--sah-primary);
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
}
.sah-topbar-ai-btn:hover { background: var(--sah-primary); color: #fff; opacity: 1; }

/* ── Content Area ── */
.sah-content-area {
  flex: 1;
  padding: 24px 20px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

/* ── Cards ── */
.sah-card {
  background: var(--sah-card);
  border: 1px solid var(--sah-border);
  border-radius: var(--sah-radius);
  padding: 20px;
  box-shadow: var(--sah-shadow);
}
.sah-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.sah-card-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--sah-text);
}
.sah-card-subtitle {
  font-size: 0.78rem;
  color: var(--sah-text-sub);
  margin-top: 2px;
}

/* ── Grid ── */
.sah-grid { display: grid; gap: 16px; }
.sah-grid-2 { grid-template-columns: repeat(2, 1fr); }
.sah-grid-3 { grid-template-columns: repeat(3, 1fr); }
.sah-grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ── Stat Cards ── */
.sah-stat-card {
  background: var(--sah-card);
  border: 1px solid var(--sah-border);
  border-radius: var(--sah-radius);
  padding: 20px;
  box-shadow: var(--sah-shadow);
}
.sah-stat-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--sah-text-sub);
  margin-bottom: 8px;
}
.sah-stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--sah-text);
  line-height: 1;
  margin-bottom: 6px;
}
.sah-stat-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
}
.sah-badge-primary { background: var(--sah-primary-light); color: var(--sah-primary); }
.sah-badge-danger   { background: #FEE2E2; color: var(--sah-danger); }
.sah-badge-warning  { background: #FEF3C7; color: #D97706; }
.sah-badge-success  { background: #D1FAE5; color: #059669; }
.sah-badge-info     { background: #DBEAFE; color: var(--sah-info); }
.sah-badge-neutral  { background: #F3F4F6; color: var(--sah-text-sub); }

/* ── Buttons ── */
.sah-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--sah-radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background var(--sah-transition), opacity var(--sah-transition);
  text-decoration: none;
  white-space: nowrap;
}
.sah-btn-primary { background: var(--sah-primary); color: #fff; }
.sah-btn-primary:hover { background: var(--sah-primary-dark); opacity: 1; color: #fff; }
.sah-btn-secondary { background: var(--sah-primary-light); color: var(--sah-primary); }
.sah-btn-secondary:hover { background: #d0ddf9; opacity: 1; }
.sah-btn-ghost { background: transparent; color: var(--sah-text-sub); border: 1px solid var(--sah-border); }
.sah-btn-ghost:hover { background: var(--sah-bg); opacity: 1; }
.sah-btn-danger { background: var(--sah-danger); color: #fff; }
.sah-btn-danger:hover { background: #dc2626; opacity: 1; }
.sah-btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.sah-btn-lg { padding: 12px 28px; font-size: 1rem; }
.sah-btn-icon { padding: 7px; }

/* ── Forms ── */
.sah-form-group { margin-bottom: 16px; }
.sah-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--sah-text);
  margin-bottom: 6px;
}
.sah-input, .sah-select, .sah-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--sah-border);
  border-radius: var(--sah-radius-sm);
  font-size: 0.875rem;
  color: var(--sah-text);
  background: var(--sah-card);
  transition: border-color var(--sah-transition);
  outline: none;
}
.sah-input:focus, .sah-select:focus, .sah-textarea:focus {
  border-color: var(--sah-primary);
  box-shadow: 0 0 0 3px rgba(47,99,230,0.1);
}
.sah-textarea { resize: vertical; min-height: 80px; }
.sah-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

/* ── Task Items ── */
.sah-task-list { display: flex; flex-direction: column; gap: 8px; }
.sah-task-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  background: var(--sah-card);
  border: 1px solid var(--sah-border);
  border-radius: var(--sah-radius-sm);
  box-shadow: var(--sah-shadow);
  transition: box-shadow var(--sah-transition);
}
.sah-task-item:hover { box-shadow: var(--sah-shadow-md); }
.sah-task-item.is-done { opacity: 0.6; }
.sah-task-item.is-done .sah-task-title { text-decoration: line-through; }
.sah-task-check {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--sah-border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: all var(--sah-transition);
  margin-top: 1px;
  background: none;
}
.sah-task-check.checked { background: var(--sah-success); border-color: var(--sah-success); }
.sah-task-check.checked::after {
  content: '';
  width: 6px; height: 10px;
  border: 2px solid #fff;
  border-top: none; border-left: none;
  transform: rotate(45deg) translateY(-1px);
}
.sah-task-body { flex: 1; min-width: 0; }
.sah-task-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--sah-text);
  margin-bottom: 4px;
}
.sah-task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.sah-task-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* Priority colors */
.sah-priority-low    { border-left: 3px solid #10B981; }
.sah-priority-medium { border-left: 3px solid #F59E0B; }
.sah-priority-high   { border-left: 3px solid #EF4444; }
.sah-priority-urgent { border-left: 3px solid #7C3AED; }

/* ── Modal ── */
.sah-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.sah-modal-overlay.is-open { display: flex; }
.sah-modal {
  background: var(--sah-card);
  border-radius: var(--sah-radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--sah-shadow-md);
  padding: 24px;
}
.sah-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.sah-modal-title { font-size: 1rem; font-weight: 700; }
.sah-modal-close {
  background: none;
  border: none;
  color: var(--sah-text-sub);
  padding: 4px;
  cursor: pointer;
  border-radius: 6px;
}
.sah-modal-close:hover { background: var(--sah-bg); }
.sah-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--sah-border);
}

/* ── Progress Bar ── */
.sah-progress { background: var(--sah-border); border-radius: 4px; height: 6px; overflow: hidden; }
.sah-progress-bar { height: 100%; background: var(--sah-primary); border-radius: 4px; transition: width 0.4s ease; }

/* ── Tabs ── */
.sah-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--sah-border); margin-bottom: 20px; }
.sah-tab {
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--sah-text-sub);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--sah-transition);
}
.sah-tab.is-active { color: var(--sah-primary); border-bottom-color: var(--sah-primary); }
.sah-tab-panel { display: none; }
.sah-tab-panel.is-active { display: block; }

/* ── Empty State ── */
.sah-empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--sah-text-sub);
}
.sah-empty-icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.4; }
.sah-empty-text { font-size: 0.9rem; }

/* ── Section header ── */
.sah-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.sah-section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--sah-text);
}

/* ── Toast ── */
.sah-toast-wrap {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sah-toast {
  background: var(--sah-text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--sah-radius-sm);
  font-size: 0.85rem;
  box-shadow: var(--sah-shadow-md);
  animation: sahToastIn 0.25s ease;
}
.sah-toast.success { background: var(--sah-success); }
.sah-toast.error   { background: var(--sah-danger); }
@keyframes sahToastIn { from { opacity:0; transform: translateY(12px); } to { opacity:1; transform: translateY(0); } }

/* ── Spinner ── */
.sah-spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--sah-border);
  border-top-color: var(--sah-primary);
  border-radius: 50%;
  animation: sahSpin 0.6s linear infinite;
  display: inline-block;
}
@keyframes sahSpin { to { transform: rotate(360deg); } }

/* ── LP (フロントページ) ── */
.sah-lp { min-height: 100vh; background: linear-gradient(135deg, #1E3A8A 0%, #2F63E6 100%); display: flex; align-items: center; }
.sah-lp-hero-inner { max-width: 600px; margin: 0 auto; padding: 60px 24px; text-align: center; }
.sah-lp-logo { display: inline-flex; align-items: center; gap: 10px; color: #fff; font-size: 1.1rem; font-weight: 700; margin-bottom: 32px; }
.sah-lp h1 { font-size: 2rem; font-weight: 700; color: #fff; line-height: 1.4; margin-bottom: 16px; }
.sah-lp p { color: rgba(255,255,255,0.8); font-size: 1rem; margin-bottom: 36px; }
.sah-lp-cta { display: flex; justify-content: center; }

/* ── Calendar ── */
.sah-cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sah-cal-title { font-size: 1rem; font-weight: 700; }
.sah-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.sah-cal-day-label { text-align: center; font-size: 0.72rem; font-weight: 600; color: var(--sah-text-sub); padding: 6px 0; }
.sah-cal-day {
  min-height: 72px;
  background: var(--sah-card);
  border: 1px solid var(--sah-border);
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  transition: background var(--sah-transition);
}
.sah-cal-day:hover { background: var(--sah-primary-light); }
.sah-cal-day.is-today { border-color: var(--sah-primary); background: var(--sah-primary-light); }
.sah-cal-day.other-month { opacity: 0.4; }
.sah-cal-day-num { font-size: 0.78rem; font-weight: 600; margin-bottom: 4px; }
.sah-cal-event { font-size: 0.68rem; background: var(--sah-primary); color: #fff; border-radius: 3px; padding: 1px 4px; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── AI Chat ── */
.sah-ai-wrap { display: flex; flex-direction: column; height: calc(100vh - var(--sah-topbar-h) - 48px); }
.sah-ai-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.sah-ai-msg { display: flex; gap: 10px; }
.sah-ai-msg.user { flex-direction: row-reverse; }
.sah-ai-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; flex-shrink: 0; }
.sah-ai-avatar.ai  { background: var(--sah-primary); color: #fff; }
.sah-ai-avatar.usr { background: var(--sah-text); color: #fff; }
.sah-ai-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.6;
}
.sah-ai-msg.ai  .sah-ai-bubble { background: var(--sah-card); border: 1px solid var(--sah-border); border-top-left-radius: 4px; }
.sah-ai-msg.user .sah-ai-bubble { background: var(--sah-primary); color: #fff; border-top-right-radius: 4px; }
.sah-ai-input-area {
  padding: 16px;
  background: var(--sah-card);
  border-top: 1px solid var(--sah-border);
}
.sah-ai-input-row { display: flex; gap: 8px; }
.sah-ai-input-row .sah-input { flex: 1; }

/* ── Responsive ── */
@media (max-width: 768px) {
  :root { --sah-sidebar-width: 260px; }

  .sah-sidebar {
    transform: translateX(-100%);
  }
  .sah-sidebar.is-open {
    transform: translateX(0);
  }
  .sah-sidebar-close { display: flex; }
  .sah-sidebar-overlay.is-open { display: block; }

  .sah-main-area { margin-left: 0; }

  .sah-topbar-menu { display: flex; }

  .sah-content-area { padding: 16px 14px; }

  .sah-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .sah-grid-3 { grid-template-columns: repeat(2, 1fr); }
  .sah-grid-2 { grid-template-columns: 1fr; }

  .sah-lp h1 { font-size: 1.5rem; }

  .sah-cal-day { min-height: 52px; }
  .sah-cal-event { display: none; }
}

@media (max-width: 480px) {
  .sah-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .sah-grid-3 { grid-template-columns: 1fr; }
  .sah-modal { padding: 18px; }
}
