/* Fonts loaded via <link> in base templates */
:root {
  /* HENNGE brand */
  --color-primary: #7b32f5;
  --color-primary-dark: #5d22c4;
  --color-primary-light: #f0eaff;
  --color-accent-blue: #0079ff;
  --color-accent-teal: #03b09d;

  /* Backgrounds */
  --color-bg: #ffffff;
  --color-bg-subtle: #faf9fb;
  --color-bg-sidebar: #ffffff;

  /* Text */
  --color-text: #000000;
  --color-text-muted: #525964;
  --color-text-sidebar: #000000;

  /* UI */
  --color-border: #e8e4ef;
  --color-accent: #03b09d;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;

  /* Radii */
  --radius: 8px;
  --radius-lg: 24px;
  --radius-pill: 100px;

  /* Shadows */
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.08);

  /* Layout */
  --sidebar-width: 252px;
  --topbar-height: 64px;

  --font-sans: 'Noto Sans JP', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html { font-size: 16px; }

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg-subtle);
  line-height: 1.5;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-bg-sidebar);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* ── Sidebar close button ── */
.sidebar-close-btn {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 4px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.13s, background 0.13s;
}
.sidebar-close-btn:hover { color: var(--color-text); background: var(--color-primary-light); }

/* ── Backdrop ── */
.sidebar-backdrop {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.sidebar-backdrop.visible { opacity: 1; pointer-events: all; }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-logo img { width: 28px; height: 28px; }

.sidebar-logo-text {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: 0.03em;
}

.sidebar-logo-sub {
  font-size: 0.68rem;
  color: var(--color-text-muted);
}

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }

.sidebar-section-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: 10px 12px 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius);
  transition: background 0.13s, color 0.13s;
  margin-bottom: 2px;
}

.sidebar-link:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
  text-decoration: none;
}

.sidebar-link.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 600;
}

.sidebar-icon { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--color-border);
  font-size: 0.8rem;
}

.sidebar-user { color: var(--color-text-muted); margin-bottom: 8px; }
.sidebar-user strong { color: var(--color-text); display: block; font-weight: 600; }

/* ── Main content ── */
.main { flex: 1; display: flex; flex-direction: column; }

/* ── Topbar ── */
.topbar {
  height: var(--topbar-height);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 0 16px;
  position: sticky;
  top: 0;
  z-index: 150;
  gap: 12px;
}

.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-title { font-size: 1rem; font-weight: 700; color: var(--color-text); white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

/* Hamburger */
.hamburger-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 6px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.13s, background 0.13s;
}
.hamburger-btn:hover { color: var(--color-primary); background: var(--color-primary-light); }

/* Topbar company context */
.topbar-company {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.3;
}
.topbar-company-name { font-size: 0.82rem; font-weight: 700; color: var(--color-text); }
.topbar-company-poc { font-size: 0.72rem; color: var(--color-text-muted); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-green { background: #d1fae5; color: #065f46; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-purple { background: var(--color-primary-light); color: var(--color-primary-dark); }

/* ── Page content ── */
.page-content { padding: 32px 28px; flex: 1; }

.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--color-text); letter-spacing: -0.02em; }
.page-header p { color: var(--color-text-muted); font-size: 0.9rem; margin-top: 6px; }

/* ── Cards ── */
.card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  min-width: 0; /* allow shrinking as a grid/flex child */
}

.card-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2 { font-size: 1rem; font-weight: 700; }

.card-body { padding: 24px; }

/* ── Client grid ── */
.client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.client-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  transition: box-shadow 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.client-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}

.client-card-name { font-size: 1rem; font-weight: 700; color: var(--color-text); }
.client-card-domain { font-size: 0.8rem; color: var(--color-text-muted); }

.client-card-meta {
  display: flex;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.client-card-meta strong { color: var(--color-text); }

.client-card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: var(--radius-pill);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  text-decoration: none;
  font-family: var(--font-sans);
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.btn-primary:hover {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(123, 50, 245, 0.3);
}

.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.btn-outline:hover {
  background: var(--color-primary-light);
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border-color: var(--color-border);
}
.btn-ghost:hover { background: var(--color-bg-subtle); color: var(--color-text); text-decoration: none; }

.btn-sm { padding: 6px 14px; font-size: 0.78rem; }
.btn-danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-subtle);
}
tbody td { padding: 14px 16px; border-bottom: 1px solid var(--color-border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-bg-subtle); }

/* ── Alert / stale banner ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: var(--color-primary-light); color: var(--color-primary-dark); border: 1px solid #d8c4ff; }

/* ── Detail section ── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.detail-item label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}
.detail-item span { font-size: 1rem; font-weight: 500; }

/* ── Auth / login page ── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-subtle);
}

.auth-box {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
}

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  transition: border-color 0.15s, box-shadow 0.15s;
  background: var(--color-bg);
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(123, 50, 245, 0.12);
}
.form-error { font-size: 0.8rem; color: var(--color-danger); margin-top: 4px; }

/* ── Breadcrumb ── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-bottom: 20px;
}
.breadcrumb a { color: var(--color-text-muted); }
.breadcrumb a:hover { color: var(--color-primary); }
.breadcrumb-sep { opacity: 0.4; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-muted);
}
.empty-state h3 { font-size: 1rem; font-weight: 700; margin-bottom: 8px; color: var(--color-text); }
.empty-state p { font-size: 0.875rem; }

/* ── Tabs ── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--color-border); margin-bottom: 24px; }
.tab-link {
  padding: 10px 18px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.tab-link:hover { color: var(--color-text); text-decoration: none; }
.tab-link.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* ── Logout form ── */
.logout-form { display: inline; }
.logout-form button {
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--color-text-muted);
  padding: 0;
}
.logout-form button:hover { color: var(--color-primary); }

/* ── HTMX indicator ── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; align-items: center; gap: 6px; }
.spin {
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Profile dropdown ── */
.profile-dropdown { position: relative; }

.profile-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  background: none;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 5px 12px 5px 6px;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--color-text);
  transition: border-color 0.15s, background 0.15s;
}

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

.profile-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.profile-btn-email {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 240px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  z-index: 200;
  overflow: hidden;
  animation: dropdownIn 0.12s ease;
}

.profile-menu.open { display: block; }

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.profile-menu-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--color-border);
}

.profile-menu-name { font-size: 0.875rem; font-weight: 700; color: var(--color-text); }
.profile-menu-email { font-size: 0.78rem; color: var(--color-text-muted); margin-top: 1px; }

.profile-menu-section {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: 10px 16px 4px;
}

.profile-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 16px;
  background: none;
  border: none;
  text-align: left;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--color-text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.1s;
}

.profile-menu-item:hover { background: var(--color-bg-subtle); text-decoration: none; }
.profile-menu-item--danger { color: var(--color-danger); }
.profile-menu-item--danger:hover { background: #fef2f2; }

.profile-menu-divider {
  height: 1px;
  background: var(--color-border);
  margin: 4px 0;
}

/* ── Dark mode ── */
[data-theme="dark"] {
  --color-bg: #111118;
  --color-bg-subtle: #1a1928;
  --color-bg-sidebar: #0f0e17;
  --color-text: #efefef;
  --color-text-muted: #8a8fa8;
  --color-text-sidebar: #efefef;
  --color-border: #2d2c40;
  --color-primary-light: #1e1040;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
}

[data-theme="dark"] .profile-menu-item--danger:hover { background: rgba(239,68,68,0.12); }
[data-theme="dark"] thead th { background: var(--color-bg-subtle); }
[data-theme="dark"] .auth-error { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.3); }
[data-theme="dark"] .form-control {
  color: var(--color-text);
  background: var(--color-bg-subtle);
  border-color: var(--color-border);
}
[data-theme="dark"] .form-control::placeholder { color: var(--color-text-muted); }

/* ── Utility: responsive grids ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.stat-grid > * { min-width: 0; }

.two-col-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 24px;
  align-items: start;
}
.two-col-grid > * { min-width: 0; }

/* ── Responsive: desktop — wider sidebar drawer ── */
@media (min-width: 1024px) {
  .sidebar {
    width: 280px;
  }
}

/* ── Responsive: tablet ── */
@media (max-width: 1023px) {
  .client-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

/* ── Tables: sticky first column ── */
.table-sticky-first thead th:first-child,
.table-sticky-first tbody td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--color-bg);
}
.table-sticky-first thead th:first-child {
  background: var(--color-bg-subtle);
}

/* ── Responsive: mobile ── */
@media (max-width: 767px) {
  .client-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr; }
  .two-col-grid { grid-template-columns: 1fr; }
  .profile-btn-email { display: none; }
  .topbar-company { display: none; }
  .page-content { padding: 16px 14px; }
  .card-body { padding: 16px; }
  .card-header { padding: 14px 16px 12px; }
  .page-header { margin-bottom: 18px; }
  .page-header h1 { font-size: 1.25rem; }
  .auth-box { padding: 28px 20px; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; }
  .tab-link { white-space: nowrap; }
  .hide-mobile { display: none !important; }
  tbody td { padding: 10px 12px; }
  thead th { padding: 8px 12px; }
}

@media (max-width: 1023px) {
  .hide-tablet { display: none !important; }
}

/* ── Page progress bar ── */
#page-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  background: var(--color-primary);
  z-index: 9999;
  width: 0%;
  opacity: 0;
  pointer-events: none;
  border-radius: 0 2px 2px 0;
}

/* ── Entrance animations ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card { animation: fadeInUp 0.2s ease both; }
.page-header { animation: fadeInUp 0.14s ease both; }

.stat-grid > .card:nth-child(2) { animation-delay: 50ms; }
.stat-grid > .card:nth-child(3) { animation-delay: 100ms; }

tbody tr { transition: background-color 0.1s ease; }

@media (prefers-reduced-motion: reduce) {
  .card, .page-header { animation: none; }
}
