/* ================================================
   ナレッジ保管庫 - スタイルシート
   ================================================ */

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --secondary: #8b5cf6;
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', 'Yu Gothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== Layout ===== */
.app-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 16px 84px;
}

@media (min-width: 768px) {
  .app-container { padding-bottom: 40px; }
}

/* ===== Header ===== */
.app-header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo {
  font-size: 17px;
  font-weight: 800;
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
}

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

.user-badge {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* ===== Desktop Nav ===== */
.desktop-nav { display: none; }

@media (min-width: 768px) {
  .desktop-nav {
    display: flex;
    gap: 2px;
  }
  .desktop-nav a {
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    transition: all 0.15s;
    white-space: nowrap;
  }
  .desktop-nav a.active,
  .desktop-nav a:hover {
    color: var(--primary);
    background: #eef2ff;
  }
}

/* ===== Bottom Nav (Mobile) ===== */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 10px;
  gap: 3px;
  transition: color 0.15s;
}

.bottom-nav a.active,
.bottom-nav a:hover { color: var(--primary); }

.bottom-nav svg { width: 22px; height: 22px; }

@media (min-width: 768px) { .bottom-nav { display: none; } }

/* ===== Page Title ===== */
.page-title {
  font-size: 20px;
  font-weight: 800;
  margin: 22px 0 14px;
  color: var(--text);
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.1s;
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
  flex: 1;
}

.card-preview {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.5;
}

.card-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* ===== Type Badge ===== */
.type-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-threads  { background: #fef3c7; color: #b45309; }
.badge-note_free { background: #d1fae5; color: #065f46; }
.badge-note_paid { background: #fce7f3; color: #9d174d; }
.badge-other    { background: #f1f5f9; color: #475569; }

/* ===== Tags ===== */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: #ede9fe;
  color: var(--secondary);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  font-family: inherit;
}

.btn-primary  { background: var(--primary); color: white; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-secondary { background: white; color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger   { background: #fef2f2; color: var(--error); border: 1px solid #fecaca; }
.btn-danger:hover   { background: var(--error); color: white; }
.btn-ai       { background: linear-gradient(135deg, #6366f1, #8b5cf6); color: white; }
.btn-ai:hover { opacity: 0.88; }
.btn-success  { background: var(--success); color: white; }
.btn-success:hover { opacity: 0.88; }

.btn-sm   { padding: 6px 14px; font-size: 13px; }
.btn-block { width: 100%; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Forms ===== */
.form-group  { margin-bottom: 16px; }

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

.form-label .req { color: var(--error); margin-left: 3px; }

.form-control {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}

textarea.form-control { resize: vertical; min-height: 110px; }

.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ===== Type Selector ===== */
.type-selector {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.type-option {
  padding: 12px 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  background: white;
}

.type-option:hover { border-color: var(--primary); background: #f5f3ff; }
.type-option.selected { border-color: var(--primary); background: #eef2ff; }

.type-option .type-icon { font-size: 22px; margin-bottom: 4px; }
.type-option .type-name { font-size: 12px; font-weight: 700; color: var(--text); }

/* ===== Tag Selector ===== */
.tag-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.tag-opt {
  padding: 5px 12px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  background: white;
  color: var(--text-muted);
}

.tag-opt:hover { border-color: var(--secondary); color: var(--secondary); }
.tag-opt.selected { background: var(--secondary); border-color: var(--secondary); color: white; }

/* ===== Search & Filters ===== */
.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-row .form-control { flex: 1; }

.filter-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.filter-chip {
  padding: 5px 13px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  background: white;
  color: var(--text-muted);
  transition: all 0.15s;
}

.filter-chip:hover,
.filter-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,15,35,0.6);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  backdrop-filter: blur(2px);
}

@media (min-width: 768px) {
  .modal-overlay {
    align-items: center;
    padding: 20px;
  }
}

.modal {
  background: white;
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  padding: 20px 18px;
  animation: slideUp 0.2s ease;
}

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

@media (min-width: 768px) {
  .modal {
    border-radius: var(--radius);
    max-width: 680px;
    margin: 0 auto;
    animation: fadeIn 0.15s ease;
  }
  @keyframes fadeIn {
    from { opacity: 0; transform: scale(0.97); }
    to   { opacity: 1; transform: scale(1); }
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-title { font-size: 17px; font-weight: 800; }

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 6px;
  border-radius: 6px;
  line-height: 1;
}

.modal-close:hover { background: var(--bg); }

/* ===== Detail Sections ===== */
.detail-section {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.detail-section:last-child { border-bottom: none; margin-bottom: 0; }

.detail-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 5px;
}

.detail-content {
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
  color: var(--text);
}

/* ===== AI Block ===== */
.ai-block {
  background: linear-gradient(135deg, #f5f3ff, #fdf4ff);
  border: 1px solid #ddd6fe;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-top: 10px;
}

.ai-block-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--secondary);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ===== Alerts ===== */
.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
}

.alert-error   { background: #fef2f2; color: var(--error); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #065f46; border: 1px solid #bbf7d0; }
.alert-info    { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ===== Loading ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  color: var(--text-muted);
  font-size: 14px;
  gap: 10px;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}

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

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 44px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; line-height: 1.7; }

/* ===== Login Page ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
  background: white;
  border-radius: 20px;
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .logo-icon { font-size: 40px; margin-bottom: 8px; }
.login-logo h1 { font-size: 22px; font-weight: 800; color: var(--primary); }
.login-logo p  { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== FAB ===== */
.fab {
  position: fixed;
  bottom: 74px;
  right: 18px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(99,102,241,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
  z-index: 99;
  text-decoration: none;
}

.fab:hover {
  transform: scale(1.07);
  box-shadow: 0 6px 24px rgba(99,102,241,0.55);
}

@media (min-width: 768px) { .fab { bottom: 24px; } }

/* ===== Export Preview ===== */
.export-preview {
  background: #1e293b;
  color: #94a3b8;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 11px;
  font-family: 'Courier New', 'Consolas', monospace;
  white-space: pre-wrap;
  max-height: 280px;
  overflow-y: auto;
  margin-top: 12px;
  line-height: 1.6;
}

/* ===== Divider ===== */
.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* ===== Section Label ===== */
.section-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin-bottom: 10px;
}

/* ===== Action Bar ===== */
.action-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* ===== Count Badge ===== */
.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: white;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  padding: 0 5px;
  margin-left: 6px;
}

/* ===== Angle Analysis ===== */
.angle-grid {
  display: grid;
  gap: 8px;
}

.angle-card {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  border-left: 3px solid var(--primary);
}

.angle-card.a2 { border-left-color: var(--secondary); }
.angle-card.a3 { border-left-color: #ec4899; }

.angle-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.angle-body { font-size: 13px; line-height: 1.65; }

/* ===== Admin ===== */
.keyword-display {
  text-align: center;
  background: linear-gradient(135deg, #f5f3ff, #ede9fe);
  border: 2px solid #c4b5fd;
  border-radius: var(--radius);
  padding: 24px;
  margin: 16px 0;
}

.keyword-code {
  font-size: 42px;
  font-weight: 900;
  font-family: 'Courier New', monospace;
  color: var(--primary);
  letter-spacing: 6px;
}

.keyword-month {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ===== Responsive utils ===== */
.flex-row { display: flex; gap: 8px; }
.flex-col { display: flex; flex-direction: column; gap: 8px; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
