/* ==========================================================================
   HAMSTER ベーススタイル (style.css)
   ==========================================================================
   GAS版の css-core.html から移植・Firebase UI向けに最適化。
   テーマ: インディゴ系 #6366F1、ライト背景。

   色意味（画面別アクセント）:
   - ギャラリー: 緑
   - 画像DB: ピンク
   - 動画: 青
   - 台本: オレンジ
   - 利用履歴: 紫
   ========================================================================== */

/* ---------------------------------------------------------------------------
   CSSカスタムプロパティ（デザイントークン）
   --------------------------------------------------------------------------- */
:root {
  /* プライマリカラー（インディゴ系 - HAMSTERブランド） */
  --color-primary: #6366F1;
  --color-primary-dark: #4338CA;
  --color-primary-light: #818CF8;
  --color-primary-bg: #EEF2FF;

  /* 画面別アクセント */
  --color-gallery: #10B981;
  --color-imagedb: #EC4899;
  --color-video: #0EA5E9;
  --color-script: #F97316;
  --color-usage: #8B5CF6;

  /* ニュートラル */
  --color-bg: #F7F8FF;
  --color-surface: #FFFFFF;
  --color-surface-hover: #F1F5F9;
  --color-text: #172033;
  --color-text-muted: #5E6A82;
  --color-border: #DCE3F2;
  --color-shadow: rgba(30, 41, 59, 0.1);

  /* セマンティック */
  --color-success: #10B981;
  --color-error: #EF4444;
  --color-warning: #F59E0B;
  --color-info: #0EA5E9;

  /* サイズ */
  --header-height: 56px;
  --sidebar-width: 260px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  /* フォント */
  --font-sans: Inter, "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

/* ---------------------------------------------------------------------------
   リセット
   --------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--color-primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }
button { cursor: pointer; font-family: inherit; }

/* ---------------------------------------------------------------------------
   ユーティリティクラス
   --------------------------------------------------------------------------- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }

/* ---------------------------------------------------------------------------
   画面切替
   --------------------------------------------------------------------------- */
.screen {
  min-height: 100vh;
}

.screen-content {
  display: none;
}

.screen-content.active {
  display: block;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------------------------------------------------------------------
   ボタン
   --------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  color: #fff;
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.btn-primary:hover {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
}

.btn-text {
  color: var(--color-text-muted);
  background: transparent;
}

.btn-text:hover {
  color: var(--color-text);
  background: var(--color-surface-hover);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 20px;
}

.btn-icon:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.btn-large {
  padding: 12px 32px;
  font-size: 16px;
  border-radius: var(--radius-md);
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
}

.btn-danger {
  color: #fff;
  background: var(--color-error);
}

.btn-danger:hover {
  background: #DC2626;
}

/* ---------------------------------------------------------------------------
   フォーム
   --------------------------------------------------------------------------- */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-bg);
}

/* ---------------------------------------------------------------------------
   ローディングオーバーレイ
   --------------------------------------------------------------------------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  z-index: 9999;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  margin-top: 12px;
  font-size: 14px;
  color: var(--color-text-muted);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------------------------------------------------------------------------
   認証画面
   --------------------------------------------------------------------------- */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(99, 102, 241, 0.12), transparent 30rem),
    radial-gradient(circle at bottom right, rgba(14, 165, 233, 0.08), transparent 30rem);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 48px 40px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 48px var(--color-shadow);
  text-align: center;
}

.auth-logo {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--color-primary), var(--color-video));
  border-radius: 16px;
  font-size: 24px;
  font-weight: 800;
}

.auth-card h1 {
  margin-bottom: 4px;
  font-size: 24px;
  letter-spacing: -0.02em;
}

.auth-subtitle {
  margin-bottom: 16px;
  color: var(--color-text-muted);
  font-size: 14px;
}

.auth-description {
  margin-bottom: 32px;
  color: var(--color-text-muted);
  font-size: 13px;
  line-height: 1.7;
}

.auth-error {
  margin-top: 16px;
  padding: 10px 14px;
  color: #B91C1C;
  background: #FEF2F2;
  border: 1px solid #FECACA;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* ---------------------------------------------------------------------------
   アプリヘッダー
   --------------------------------------------------------------------------- */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-title {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.04em;
  color: var(--color-primary);
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-email {
  font-size: 13px;
  color: var(--color-text-muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   タブナビゲーション
   --------------------------------------------------------------------------- */
.tab-nav {
  display: flex;
  gap: 2px;
  background: var(--color-surface-hover);
  border-radius: var(--radius-md);
  padding: 3px;
}

.tab-btn {
  padding: 6px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}

.tab-btn:hover {
  color: var(--color-text);
}

.tab-btn.active {
  color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ---------------------------------------------------------------------------
   ハンバーガーアイコン
   --------------------------------------------------------------------------- */
.hamburger-icon {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--color-text);
  position: relative;
  transition: background 0.2s;
}

.hamburger-icon::before,
.hamburger-icon::after {
  content: '';
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--color-text);
  transition: transform 0.2s;
}

.hamburger-icon::before { top: -6px; }
.hamburger-icon::after { top: 6px; }

#btn-hamburger.open .hamburger-icon {
  background: transparent;
}

#btn-hamburger.open .hamburger-icon::before {
  transform: translateY(6px) rotate(45deg);
}

#btn-hamburger.open .hamburger-icon::after {
  transform: translateY(-6px) rotate(-45deg);
}

/* ---------------------------------------------------------------------------
   サイドバー
   --------------------------------------------------------------------------- */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  padding: 16px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  z-index: 90;
}

.sidebar.open {
  transform: translateX(0);
}

@media (min-width: 900px) {
  .sidebar {
    transform: translateX(0);
  }
  .main-content {
    margin-left: var(--sidebar-width);
  }
}

.sidebar-section {
  margin-bottom: 20px;
}

.sidebar-title {
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
}

.project-list {
  list-style: none;
  margin-bottom: 12px;
}

.project-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.project-item:hover {
  background: var(--color-primary-bg);
}

.project-item.active {
  background: var(--color-primary-bg);
  color: var(--color-primary-dark);
  font-weight: 600;
}

.project-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-count {
  font-size: 11px;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.project-empty {
  padding: 12px;
  color: var(--color-text-muted);
  font-size: 13px;
  text-align: center;
}

.filter-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

/* ---------------------------------------------------------------------------
   メインコンテンツエリア
   --------------------------------------------------------------------------- */
.main-content {
  margin-top: var(--header-height);
  padding: 24px;
  min-height: calc(100vh - var(--header-height));
}

/* ---------------------------------------------------------------------------
   空状態 / スケルトン
   --------------------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  text-align: center;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-message {
  color: var(--color-text-muted);
  font-size: 15px;
}

/* スケルトンローディング */
.skeleton-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.skeleton-line {
  height: 14px;
  background: linear-gradient(90deg, var(--color-surface-hover) 25%, #E2E8F0 50%, var(--color-surface-hover) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: 4px;
  margin-bottom: 8px;
}

.skeleton-thumb { height: 120px; }
.skeleton-text.short { width: 60%; }

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------------------------------------------------------------------------
   モーダル
   --------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  z-index: 1000;
  animation: fadeIn 0.15s;
}

.modal {
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 64px rgba(0,0,0,0.15);
}

.modal h3 {
  margin-bottom: 20px;
  font-size: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}

/* ---------------------------------------------------------------------------
   トースト通知
   --------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 280px;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  font-size: 14px;
  pointer-events: auto;
  animation: toast-in 0.3s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}

.toast-success {
  color: #047857;
  background: #DCFCE7;
  border: 1px solid #BBF7D0;
}

.toast-error {
  color: #B91C1C;
  background: #FEF2F2;
  border: 1px solid #FECACA;
}

.toast-warning {
  color: #B45309;
  background: #FFFBEB;
  border: 1px solid #FDE68A;
}

.toast-info {
  color: #0369A1;
  background: #E0F2FE;
  border: 1px solid #BAE6FD;
}

.toast-close {
  margin-left: auto;
  padding: 2px 6px;
  border: none;
  background: transparent;
  font-size: 18px;
  opacity: 0.5;
  cursor: pointer;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

/* ---------------------------------------------------------------------------
   ホーム画面
   --------------------------------------------------------------------------- */
.home-hero {
  text-align: center;
  padding: 48px 24px 32px;
  position: relative;
  overflow: hidden;
}

.home-hamster-bg {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 120px;
  opacity: 0.06;
  pointer-events: none;
  user-select: none;
}

.home-hero h2 {
  font-size: 32px;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.home-desc {
  color: var(--color-text-muted);
  font-size: 15px;
  line-height: 1.8;
  max-width: 600px;
  margin: 0 auto;
}

.home-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  padding: 0 16px 32px;
  max-width: 1200px;
  margin: 0 auto;
}

.home-card {
  padding: 24px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.2s;
}

.home-card:hover {
  border-color: var(--color-primary-light);
  box-shadow: 0 8px 24px var(--color-shadow);
  transform: translateY(-2px);
}

.card-icon {
  font-size: 32px;
  margin-bottom: 12px;
}

.home-card h3 {
  font-size: 16px;
  margin-bottom: 6px;
}

.home-card p {
  font-size: 13px;
  color: var(--color-text-muted);
  line-height: 1.6;
}

/* ---------------------------------------------------------------------------
   ワークスペース（台本→絵コンテ画面）
   --------------------------------------------------------------------------- */
.workspace-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 20px;
}

.ws-tab {
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}

.ws-tab:hover {
  color: var(--color-text);
}

.ws-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.workspace-content {
  min-height: 400px;
}

/* ---------------------------------------------------------------------------
   ギャラリー / 画像DB / 動画 共通
   --------------------------------------------------------------------------- */
.gallery-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.gallery-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.gallery-grid,
.video-grid,
.imagedb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.placeholder-text {
  grid-column: 1 / -1;
  padding: 40px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 15px;
}

/* ---------------------------------------------------------------------------
   利用履歴画面
   --------------------------------------------------------------------------- */
.usage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.usage-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.usage-month-selector {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 16px;
  font-weight: 600;
}

.usage-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.usage-summary-card {
  padding: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.usage-summary-card .label {
  font-size: 12px;
  color: var(--color-text-muted);
}

.usage-summary-card .value {
  font-size: 20px;
  font-weight: 700;
}

.usage-table-container {
  overflow-x: auto;
}

.usage-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.usage-table th {
  padding: 12px 14px;
  font-size: 12px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-align: left;
  background: var(--color-surface-hover);
  white-space: nowrap;
}

.usage-table td {
  padding: 10px 14px;
  font-size: 13px;
  border-top: 1px solid var(--color-border);
}

/* ---------------------------------------------------------------------------
   particle fireworks アニメーション
   --------------------------------------------------------------------------- */
@keyframes particle-fly {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--tx), var(--ty)) scale(0);
  }
}

/* ---------------------------------------------------------------------------
   レスポンシブ
   --------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .home-cards {
    grid-template-columns: 1fr;
  }

  .gallery-grid,
  .video-grid,
  .imagedb-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
  }

  .usage-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .tab-nav {
    overflow-x: auto;
    max-width: calc(100vw - 200px);
  }
}

@media (min-width: 1600px) {
  .home-cards {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media print {
  .app-header, .sidebar, .loading-overlay, .toast-container {
    display: none !important;
  }
  .main-content {
    margin-left: 0;
    margin-top: 0;
  }
}
