/* ============================================
   WebTechLab Japan Tools - Common Styles
   Header + Left Sidebar Layout
   ============================================ */

/* --- Reset --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* --- CSS Variables --- */
:root {
  /* Colors */
  --color-bg: #0f172a;
  --color-bg-elevated: #1e293b;
  --color-bg-input: #020617;
  --color-surface: #1e293b;
  --color-border: #334155;
  --color-border-light: #475569;

  --color-text-primary: #f8fafc;
  --color-text-secondary: #94a3b8;
  --color-text-tertiary: #64748b;

  --color-accent: #38bdf8;
  --color-accent-hover: #0ea5e9;
  --color-accent-subtle: rgba(56, 189, 248, 0.1);

  --color-success: #22c55e;
  --color-error: #ef4444;
  --color-warning: #f59e0b;

  /* Typography */
  --font-sans: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Menlo', 'Ubuntu Mono', monospace;
  --font-display: 'Poppins', 'Inter', sans-serif;

  /* Layout */
  --header-height: 56px;
  --sidebar-width: 240px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}

/* --- Base --- */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

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

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-accent-hover);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

button {
  font-family: var(--font-sans);
  cursor: pointer;
  border: none;
  background: none;
}

input,
textarea,
select {
  font-family: var(--font-sans);
}

/* ============================================
   HEADER
   ============================================ */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--color-border);
  height: var(--header-height);
}

.site-header__inner {
  padding: 0 20px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
}

.site-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--color-text-primary);
  flex-shrink: 0;
}

.site-header__logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--color-accent), #8b5cf6);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
}

.site-header__brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.site-header__brand-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-text-primary);
}

.site-header__brand-sub {
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--color-text-tertiary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Sidebar Toggle (hamburger) */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  background: var(--color-accent-subtle);
  color: var(--color-text-primary);
}

.sidebar-toggle svg {
  width: 20px;
  height: 20px;
}

/* ============================================
   SIDEBAR
   ============================================ */
.site-sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-bg-elevated);
  border-right: 1px solid var(--color-border);
  z-index: 150;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 0;
  transition: transform var(--transition-base);
}

.site-sidebar::-webkit-scrollbar {
  width: 4px;
}

.site-sidebar::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 2px;
}

/* Sidebar Section Label */
.sidebar-section {
  padding: 16px 16px 8px;
}

.sidebar-section__label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Sidebar Links */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}

.sidebar-nav__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav__link:hover {
  color: var(--color-text-primary);
  background: rgba(255, 255, 255, 0.06);
}

.sidebar-nav__link--active {
  color: var(--color-text-primary);
  background: var(--color-accent-subtle);
}

.sidebar-nav__link--active .sidebar-nav__icon {
  color: var(--color-accent);
}

.sidebar-nav__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--color-text-tertiary);
  transition: color var(--transition-fast);
}

.sidebar-nav__link:hover .sidebar-nav__icon {
  color: var(--color-text-secondary);
}

.sidebar-nav__badge {
  margin-left: auto;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--color-text-tertiary);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

/* Sidebar divider */
.sidebar-divider {
  height: 1px;
  background: var(--color-border);
  margin: 8px 16px;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.site-layout {
  display: flex;
  min-height: 100vh;
  padding-top: var(--header-height);
}

.site-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.page-container {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 32px;
}

.page-container--narrow {
  max-width: 900px;
}

.page-container--wide {
  max-width: 1400px;
}

/* --- Page Hero --- */
.page-hero {
  text-align: center;
  padding: 32px 0 28px;
}

.page-hero__title {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.page-hero__subtitle {
  font-size: 0.95rem;
  color: var(--color-text-secondary);
  line-height: 1.7;
}

/* ============================================
   CARD
   ============================================ */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-border);
}

.card__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all var(--transition-base);
  border: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn--primary {
  background: var(--color-accent);
  color: #0f172a;
}

.btn--primary:hover {
  background: var(--color-accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
}

.btn--outline {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.btn--outline:hover {
  color: var(--color-text-primary);
  border-color: var(--color-border-light);
  background: rgba(255, 255, 255, 0.05);
}

.btn--danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--color-error);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn--danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn--sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

.btn svg {
  width: 16px;
  height: 16px;
}

/* ============================================
   FOOTER
   ============================================ */
.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 20px 24px;
  text-align: center;
  color: var(--color-text-tertiary);
  font-size: 0.8rem;
  margin-top: auto;
}

.site-footer a {
  color: var(--color-text-secondary);
  font-weight: 500;
}

.site-footer a:hover {
  color: var(--color-accent);
}

/* ============================================
   TOAST
   ============================================ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--color-surface);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  pointer-events: none;
  z-index: 300;
}

.toast--visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.toast--success {
  border-color: var(--color-success);
}

/* ============================================
   LOADING OVERLAY
   ============================================ */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-overlay__content {
  text-align: center;
  color: var(--color-text-primary);
}

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

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

/* ============================================
   FORM ELEMENTS
   ============================================ */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 10px 14px;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-primary);
  font-size: 0.95rem;
  transition: border-color var(--transition-fast);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

.form-textarea {
  resize: vertical;
  min-height: 120px;
  font-family: var(--font-mono);
  line-height: 1.6;
}

/* ============================================
   EDITOR PANE (dual-pane layout)
   ============================================ */
.editor-grid {
  display: flex;
  gap: 16px;
}

.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.editor-pane__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--color-border);
}

.editor-pane__label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.editor-pane__content textarea {
  width: 100%;
  min-height: 300px;
  padding: 16px;
  background: var(--color-bg-input);
  border: none;
  color: var(--color-text-primary);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
  resize: vertical;
}

.editor-pane__content textarea:focus {
  outline: none;
}

.editor-pane__statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-top: 1px solid var(--color-border);
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
}

/* ============================================
   UPLOAD AREA
   ============================================ */
.upload-area {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-base);
  background: rgba(56, 189, 248, 0.02);
}

.upload-area:hover,
.upload-area--dragover {
  border-color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.upload-area__icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  color: var(--color-text-tertiary);
}

.upload-area__icon svg {
  width: 100%;
  height: 100%;
}

.upload-area__title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 8px;
}

.upload-area__desc {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
}

.upload-area__note {
  display: inline-block;
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--color-text-tertiary);
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 12px;
  border-radius: 999px;
}

/* ============================================
   TOGGLE SWITCH
   ============================================ */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.toggle-switch input {
  display: none;
}

.toggle-switch__slider {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--color-border);
  border-radius: 10px;
  transition: background var(--transition-fast);
  flex-shrink: 0;
}

.toggle-switch__slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition-fast);
}

.toggle-switch input:checked + .toggle-switch__slider {
  background: var(--color-accent);
}

.toggle-switch input:checked + .toggle-switch__slider::after {
  transform: translateX(16px);
}

.toggle-switch__label {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

/* ============================================
   SIDEBAR OVERLAY (mobile)
   ============================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 140;
}

.sidebar-overlay--visible {
  display: block;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 900px) {
  .sidebar-toggle {
    display: flex;
  }

  .site-sidebar {
    transform: translateX(-100%);
  }

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

  .site-main {
    margin-left: 0;
  }

  .page-container {
    padding: 24px 20px;
  }

  .page-hero__title {
    font-size: 1.5rem;
  }

  .editor-grid {
    flex-direction: column;
  }

  .card {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .page-hero__title {
    font-size: 1.3rem;
  }

  .site-header__brand-name {
    font-size: 0.8rem;
  }

  .site-header__brand-sub {
    display: none;
  }

  .page-container {
    padding: 16px 12px;
  }
}
