/* ================================================================
   Layout - サイドバー (レール) + ヘッダー + メインコンテンツ
   Estate デザイン: 深緑レール + 和紙ガラスヘッダー
   ================================================================ */

body {
  display: block;
  min-height: 100vh;
}
@supports (display: grid) {
  body.has-sidebar {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr;
    grid-template-areas:
      "sidebar header"
      "sidebar main";
    min-height: 100vh;
  }
  body:has(.app-sidebar):not(.auth-page) {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr;
    grid-template-areas:
      "sidebar header"
      "sidebar main";
  }
}

/* ---- ヘッダー (top) ---- */
.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  background: rgba(247, 245, 240, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
}
.app-header-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.app-header-title h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: .05em;
}
.app-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.app-header-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}
.app-header-user-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(150deg, #C9A24E, var(--brass));
  color: white;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--font-size-sm);
  box-shadow: 0 4px 12px rgba(176, 138, 60, .35);
}
.app-header-port {
  font-size: var(--font-size-xs);
  color: rgba(255,255,255,.72);
  font-family: var(--font-mono);
}

/* ---- サイドバー (左レール) ---- */
.app-sidebar {
  grid-area: sidebar;
  background: linear-gradient(180deg, var(--color-primary-hover, #14532D), #0C3B20);
  color: rgba(255,255,255,.65);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}
.app-sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5);
  font-family: var(--font-serif);
  font-size: var(--font-size-lg);
  font-weight: 700;
  letter-spacing: .06em;
  color: white;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.app-sidebar-brand .logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(150deg, #C9A24E, var(--brass));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: 0 8px 20px rgba(176, 138, 60, .35);
}
.app-sidebar-nav {
  flex: 1;
  padding: var(--space-4) var(--space-3);
  overflow-y: auto;
}
.app-sidebar-section {
  margin-bottom: var(--space-5);
}
.app-sidebar-section-title {
  display: block;
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: #D2B77C;
  letter-spacing: .22em;
}
.app-sidebar-section-title.active {
  color: #E6D2A6;
}
.app-sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  margin-bottom: 2px;
  font-size: var(--font-size-sm);
  letter-spacing: .03em;
  color: rgba(255,255,255,.62);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  position: relative;
}
.app-sidebar-link:hover {
  background: rgba(255,255,255,.07);
  color: white;
  text-decoration: none;
}
.app-sidebar-link.active {
  background: rgba(176,138,60,.2);
  color: white;
}
.app-sidebar-link.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--brass);
  border-radius: 0 3px 3px 0;
}
.app-sidebar-link .icon { width: 20px; text-align: center; }
.app-sidebar-footer {
  padding: var(--space-4);
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: var(--font-size-xs);
  color: rgba(255,255,255,.72);
  line-height: 1.8;
}

/* ---- メインコンテンツ ---- */
.app-main {
  grid-area: main;
  padding: var(--space-6) var(--space-8) var(--space-12);
  max-width: 100%;
  overflow-x: hidden;
}
.app-main-inner {
  max-width: var(--container-max);
  margin: 0 auto;
}

/* ---- 認証ページ (サイドバーなし) ---- */
.auth-page {
  display: block;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(176,138,60,.14), transparent 60%),
    linear-gradient(160deg, #14532D 0%, #0C3B20 100%);
}
.auth-page .app-main {
  padding: var(--space-12) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  background: white;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: var(--space-8);
  width: 100%;
  max-width: 480px;
}
.auth-card-header {
  text-align: center;
  margin-bottom: var(--space-6);
}
.auth-card-header .logo {
  width: 52px;
  height: 52px;
  margin: 0 auto var(--space-3);
  border-radius: 14px;
  background: linear-gradient(150deg, #C9A24E, var(--brass));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  box-shadow: 0 8px 20px rgba(176, 138, 60, .35);
}
.auth-card-header h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: var(--font-size-2xl);
  letter-spacing: .05em;
}
.auth-card-header .subtitle {
  margin: var(--space-2) 0 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}
.auth-card-footer {
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  text-align: center;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

/* ---- レスポンシブ (簡易) ---- */
@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "main";
  }
  .app-sidebar { display: none; }
}

/* ---- スキップリンク ---- */
.skip-link {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: -56px;
  z-index: 2000;
  padding: 10px 22px;
  border-radius: 0 0 10px 10px;
  background: var(--color-primary, #245744);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: top .15s ease;
}
.skip-link:focus { top: 0; color: #fff; }
@media (prefers-reduced-motion: reduce) {
  .skip-link { transition: none; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
