/* ===== Variables ===== */
:root {
  --blue-900: #0d2d4a;
  --blue-700: #1F4E79;
  --blue-500: #2E75B6;
  --blue-300: #9DC3E6;
  --blue-100: #DEEAF1;
  --blue-50:  #EBF3FB;
  --text:     #111111;
  --text-sub: #2d3748;
  --text-muted: #555555;
  --border:   #e2e8f0;
  --bg:       #f4f7fb;
  --surface:  #ffffff;
  --red:      #e53e3e;
  --green:    #38a169;
  --yellow:   #d69e2e;
  --radius:   8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.07);
  --shadow:    0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.12), 0 4px 10px rgba(0,0,0,0.07);
  --transition: 0.15s ease;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, '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;
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--blue-700);
  box-shadow: var(--shadow-md);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
  height: 58px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  letter-spacing: -0.01em;
}
.logo svg { opacity: 0.9; }

/* Search */
.search-wrap {
  flex: 1;
  max-width: 480px;
  position: relative;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: rgba(255,255,255,0.5);
}
#searchInput {
  width: 100%;
  padding: 8px 36px 8px 36px;
  background: rgba(255,255,255,0.13);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  color: #fff;
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: background var(--transition), border-color var(--transition);
}
#searchInput::placeholder { color: rgba(255,255,255,0.55); }
#searchInput:focus {
  background: rgba(255,255,255,0.22);
  border-color: rgba(255,255,255,0.4);
}
.search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 4px;
  line-height: 1;
}
.search-clear:hover { color: #fff; }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.admin-badge {
  background: rgba(254, 215, 170, 0.2);
  border: 1px solid rgba(254, 215, 170, 0.5);
  color: #fed7aa;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ===== Layout ===== */
.layout {
  display: flex;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
  gap: 24px;
  min-height: calc(100vh - 58px);
  align-items: flex-start;
}

/* ===== Sidebar ===== */
.sidebar { width: 210px; flex-shrink: 0; position: sticky; top: 82px; }
.sidebar-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.sidebar-section-title {
  padding: 10px 16px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.company-nav { list-style: none; }
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 16px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-sub);
  border-left: 3px solid transparent;
  user-select: none;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  gap: 8px;
}
.nav-item:hover { background: var(--blue-50); }
.nav-item.active {
  background: var(--blue-100);
  border-left-color: var(--blue-700);
  font-weight: 600;
  color: var(--blue-700);
}
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count {
  background: var(--blue-50);
  color: var(--blue-500);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}
.nav-item.active .nav-count { background: var(--blue-700); color: #fff; }
.nav-counts { display: flex; align-items: center; gap: 4px; }
.nav-unanswered {
  background: var(--red);
  color: #fff;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 0.68rem;
  font-weight: 700;
}

.sidebar-divider { height: 1px; background: var(--border); margin: 4px 0; }
.sidebar-admin-btns { padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text-sub);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background var(--transition), color var(--transition);
}
.sidebar-btn:hover { background: var(--blue-50); color: var(--blue-700); }
.sidebar-btn svg { flex-shrink: 0; color: var(--text-muted); }
.sidebar-btn:hover svg { color: var(--blue-500); }

/* ===== Main ===== */
.main { flex: 1; min-width: 0; }
.content-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}
.content-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--blue-700);
  line-height: 1.3;
}
.result-count { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

/* ===== Loader / Empty ===== */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 80px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--blue-500);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.5; }
#emptyMsg { font-size: 0.95rem; }

/* ===== Q&A Cards ===== */
.qa-list { display: flex; flex-direction: column; gap: 12px; }

/* Month group header */
.month-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 8px;
  border-bottom: 2px solid var(--blue-100);
  margin-top: 8px;
}
.month-header:first-child { margin-top: 0; }
.month-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--blue-700);
}
.month-count {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.month-unanswered {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--red);
}

.qa-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow var(--transition);
  border: 1px solid var(--border);
}
.qa-card:hover { box-shadow: var(--shadow-md); }
.qa-card.unanswered { border-left: 3px solid var(--red); }

.qa-card-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
}
.qa-card-header-main { flex: 1; min-width: 0; }
.qa-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge-company    { background: var(--blue-700); color: #fff; }
.badge-customer   { background: #e2e8f0; color: #2d3748; }
.badge-device     { background: #bee3f8; color: #2c5282; }
.badge-no         { background: var(--blue-100); color: var(--blue-700); }
.badge-unanswered { background: var(--red); color: #fff; }
.badge-cat-auto   { background: #d1fae5; color: #065f46; }
.badge-cat-home   { background: #fff3cd; color: #92400e; }

.qa-preview {
  font-size: 1rem;
  font-weight: 500;
  color: #1a1a1a;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qa-toggle {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 0.7rem;
  margin-top: 4px;
  transition: transform var(--transition);
}
.qa-card.expanded .qa-toggle { transform: rotate(180deg); }

/* Card body */
.qa-card-body {
  display: none;
  padding: 0 18px 18px;
  border-top: 1px solid var(--blue-50);
}
.qa-card.expanded .qa-card-body {
  display: block;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.qa-section { margin-top: 16px; }
.qa-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-sub);
  margin-bottom: 6px;
}
.qa-text {
  font-size: 0.95rem;
  line-height: 1.8;
  white-space: pre-wrap;
  color: #1a1a1a;
}
.qa-answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.qa-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  background: #dbeafe;
  color: #1e40af;
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 600;
}
.qa-attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.attachment-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--blue-500);
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition);
}
.attachment-link:hover {
  background: var(--blue-50);
  border-color: var(--blue-300);
  color: var(--blue-700);
}

/* Card footer */
.qa-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.qa-date { font-size: 0.78rem; color: var(--text-sub); font-weight: 500; }
.qa-actions { display: flex; gap: 6px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--blue-700); color: #fff; }
.btn-primary:hover { background: var(--blue-500); }
.btn-ghost {
  background: var(--surface);
  color: var(--text-sub);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-header {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  border-radius: 6px;
}
.btn-header:hover { background: rgba(255,255,255,0.24); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #c53030; }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }

/* ===== Modals ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(13, 45, 74, 0.55);
  backdrop-filter: blur(3px);
}
.modal-box {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  animation: modalIn 0.18s ease;
}
.modal-lg { max-width: 760px; }
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(-8px); }
  to   { opacity: 1; transform: none; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; }
.modal-close-x {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 4px 6px;
  border-radius: 4px;
  transition: background var(--transition), color var(--transition);
}
.modal-close-x:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 20px 24px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  background: var(--surface);
}

/* ===== Forms ===== */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 5px;
}
.req { color: var(--red); }
.hint { font-weight: 400; color: var(--text-muted); font-size: 0.75rem; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(46,117,182,0.14);
}
.form-group textarea { resize: vertical; min-height: 76px; line-height: 1.6; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 16px 0 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Attachment rows */
.attachment-row {
  display: grid;
  grid-template-columns: 1fr 1.6fr auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.attachment-row input { margin: 0; }
.btn-remove {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 5px;
  padding: 6px 9px;
  font-size: 0.8rem;
  transition: background var(--transition), color var(--transition);
}
.btn-remove:hover { background: #fff5f5; color: var(--red); border-color: #fed7d7; }

/* Company manage list */
.company-manage-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.company-manage-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  gap: 12px;
}
.company-manage-info { flex: 1; min-width: 0; }
.company-manage-name { font-weight: 600; font-size: 0.9rem; }
.company-manage-desc { font-size: 0.78rem; color: var(--text-muted); margin-top: 1px; }
.company-manage-actions { display: flex; gap: 6px; }

/* Edit-in-place */
.company-edit-form { display: flex; gap: 8px; align-items: center; flex: 1; min-width: 0; }
.company-edit-form input { flex: 1; }

/* Error msg */
.error-msg {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  color: var(--red);
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  margin-top: 8px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  background: #1a202c;
  color: #fff;
  padding: 11px 18px;
  border-radius: 8px;
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  max-width: 320px;
  animation: toastIn 0.2s ease;
}
.toast.hidden { display: none; }
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* Highlight */
mark {
  background: #fef08a;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* Utility */
.hidden { display: none !important; }

/* ===== Responsive ===== */
@media (max-width: 860px) {
  .layout { flex-direction: column; padding: 16px; }
  .sidebar { width: 100%; position: static; }
  .company-nav { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px 8px; }
  .nav-item {
    border: 1px solid var(--border);
    border-radius: 20px;
    border-left: 1px solid var(--border) !important;
    padding: 5px 12px;
    font-size: 0.8rem;
  }
  .nav-item.active { border-color: var(--blue-700); }
  .qa-answer-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .attachment-row { grid-template-columns: 1fr auto; }
  .attachment-row .att-url { grid-column: 1; }
  .modal-lg { max-width: 100%; }
}
@media (max-width: 480px) {
  .header-inner { padding: 0 14px; gap: 10px; }
  .search-wrap { max-width: none; }
  .admin-badge { display: none; }
}
