/* ============================================================
   Construction & Real Estate SaaS — Design System
   Atlas Design System 準拠版 v2.0
   参照: CLAUDE-UI-DESIGN.md / design-tokens.css
   使い方:
     <link rel="stylesheet" href="../../design-system/design-tokens.css">
     <link rel="stylesheet" href="../../design-system/design-system.css">
     <body data-variant="construction" data-theme="dark">
   ============================================================ */

/* ── Atlas トークンをインポート ── */
@import url('./design-tokens.css');

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-canvas);
  color: var(--fg-default);
  min-height: 100vh;
  line-height: var(--lh-normal);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-pressed); }
img { max-width: 100%; }

/* ── フォーカスリング (アクセシビリティ) ── */
:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ── モーション軽減 ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 {
  color: var(--fg-default);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-title);
}
h1 { font-size: var(--fs-title1); }
h2 { font-size: var(--fs-title2); }
h3 { font-size: var(--fs-title3); }
h4 { font-size: var(--fs-headline); }
p  { color: var(--fg-secondary); font-size: var(--fs-body); line-height: var(--lh-normal); }
small { font-size: var(--fs-caption1); color: var(--fg-tertiary); }

code {
  font-family: var(--font-mono);
  font-size: var(--fs-footnote);
  background: var(--bg-surface-2);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--accent);
}

/* ── Layout ── */
/* モバイルファースト: ベースが1列、min-width で拡張 */
.page-wrapper {
  width: 100%;
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 var(--space-5);
  /* セーフエリア対応 */
  padding-bottom: max(48px, env(safe-area-inset-bottom));
}

.section { padding: var(--space-8) 0; }

/* グリッド: モバイルは1列、タブレット以上で複数列 */
.grid-2 { display: grid; grid-template-columns: 1fr; gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: 1fr; gap: var(--space-4); }
.grid-4 { display: grid; grid-template-columns: 1fr; gap: var(--space-4); }

@media (min-width: 768px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .page-wrapper { padding: 0 var(--space-6); padding-bottom: max(48px, env(safe-area-inset-bottom)); }
}

@media (min-width: 1024px) {
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

.flex         { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-end     { display: flex; justify-content: flex-end; }
.gap-2 { gap: var(--space-3); }
.gap-3 { gap: var(--space-4); }
.gap-4 { gap: var(--space-5); }

/* ── Header ── */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 14px var(--space-6);
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--elev-1);
}
.app-header .logo {
  font-size: var(--fs-title3);
  font-weight: 800;
  color: var(--fg-default);
  letter-spacing: -0.5px;
}
.app-header .logo span { color: var(--accent); }
.app-header .sub { font-size: var(--fs-caption1); color: var(--fg-tertiary); margin-top: 2px; }

/* ── Navigation Tabs ── */
.tabs-bar {
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  padding: 0 var(--space-5);
  gap: 2px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs-bar::-webkit-scrollbar { display: none; }

.tab-item {
  padding: 12px var(--space-4);
  cursor: pointer;
  font-size: var(--fs-footnote);
  font-weight: 500;
  color: var(--fg-tertiary);
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: color var(--dur-2) var(--ease-standard),
              border-color var(--dur-2) var(--ease-standard);
  user-select: none;
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.tab-item.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-item:hover:not(.active) { color: var(--fg-secondary); }

/* ── Card ── */
.card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  box-shadow: var(--elev-1);
  transition: box-shadow var(--dur-2) var(--ease-standard);
}
.card:hover { box-shadow: var(--elev-2); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
}
.card-title {
  font-size: var(--fs-caption1);
  font-weight: 700;
  color: var(--fg-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.card-body { }
.card-footer {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

/* Card variants */
.card-accent  { border-color: var(--accent);          border-left: 4px solid var(--accent); }
.card-success { border-color: var(--status-success);  border-left: 4px solid var(--status-success); }
.card-danger  { border-color: var(--status-danger);   border-left: 4px solid var(--status-danger); }

/* ── Stat / KPI ── */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

@media (min-width: 768px) {
  .stats-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

.stat-box {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
.stat-label {
  font-size: var(--fs-caption2);
  color: var(--fg-tertiary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat-value {
  font-size: var(--fs-title2);
  font-weight: 800;
  color: var(--fg-default);
  margin-top: 4px;
  letter-spacing: var(--tracking-title);
}
.stat-sub  { font-size: var(--fs-caption1); margin-top: 3px; color: var(--fg-tertiary); }
.stat-up   { color: var(--status-success); }
.stat-down { color: var(--status-danger); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  font-size: var(--fs-footnote);
  font-weight: 600;
  font-family: var(--font-sans);
  transition: background var(--dur-2) var(--ease-standard),
              box-shadow var(--dur-2) var(--ease-standard),
              transform var(--dur-1) var(--ease-standard);
  white-space: nowrap;
  user-select: none;
  min-height: var(--touch-min);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }

.btn-primary {
  background: var(--accent);
  color: var(--fg-on-accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-pressed); }

.btn-secondary {
  background: var(--bg-surface-3);
  color: var(--fg-default);
  border: 1px solid var(--border-default);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-surface-2); }

.btn-ghost {
  background: var(--bg-surface);
  color: var(--fg-secondary);
  border: 1px solid var(--border-default);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-surface-2); color: var(--fg-default); }

.btn-danger {
  background: var(--status-danger-bg);
  color: var(--status-danger);
  border: 1px solid color-mix(in srgb, var(--status-danger) 40%, transparent);
}
.btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--status-danger) 20%, transparent);
}

.btn-ai {
  background: linear-gradient(135deg, var(--brand-orange-500), var(--brand-orange-600));
  color: #000;
  font-size: var(--fs-subhead);
  font-weight: 700;
  padding: 14px 28px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px color-mix(in srgb, var(--brand-orange-500) 35%, transparent);
}
.btn-ai:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px color-mix(in srgb, var(--brand-orange-500) 45%, transparent);
}

.btn-sm {
  padding: 6px 12px;
  font-size: var(--fs-caption1);
  border-radius: var(--radius-sm);
  min-height: 32px; /* sm は touch-min 緩和 */
}
.btn-lg { padding: 14px 28px; font-size: var(--fs-subhead); }
.btn-block { width: 100%; }

/* ── Form ── */
.form-group  { margin-bottom: var(--space-4); }
.form-label  {
  display: block;
  font-size: var(--fs-caption2);
  font-weight: 700;
  color: var(--fg-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-surface-2);
  border: 1.5px solid var(--border-default);
  border-radius: var(--radius-md);
  /* iOS自動ズーム防止: 16px以上を保証 */
  font-size: max(16px, var(--fs-callout));
  color: var(--fg-default);
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--dur-2) var(--ease-standard),
              box-shadow var(--dur-2) var(--ease-standard);
  min-height: var(--touch-min);
}
.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.form-control::placeholder { color: var(--fg-tertiary); }
.form-control[aria-invalid="true"] { border-color: var(--status-danger); }
select.form-control { appearance: none; cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 100px; line-height: var(--lh-relaxed); }

/* form-row: モバイルは1列、タブレット以上で2列 */
.form-row { display: grid; grid-template-columns: 1fr; gap: var(--space-3); }

@media (min-width: 768px) {
  .form-row { grid-template-columns: 1fr 1fr; }
}

.form-hint { font-size: var(--fs-caption2); color: var(--fg-tertiary); margin-top: 4px; }

/* ── Table ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-footnote); }

thead th {
  text-align: left;
  padding: 10px var(--space-4);
  color: var(--fg-tertiary);
  font-size: var(--fs-caption2);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-default);
}
tbody td {
  padding: 12px var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  color: var(--fg-default);
}
tbody tr:hover td { background: var(--bg-surface-2); }
tbody tr:last-child td { border-bottom: none; }

/* ── Badge ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--fs-caption2);
  font-weight: 700;
  white-space: nowrap;
}
.badge-primary {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.badge-success {
  background: var(--status-success-bg);
  color: var(--status-success);
  border: 1px solid color-mix(in srgb, var(--status-success) 30%, transparent);
}
.badge-warning {
  background: var(--status-warning-bg);
  color: var(--status-warning);
  border: 1px solid color-mix(in srgb, var(--status-warning) 30%, transparent);
}
.badge-danger {
  background: var(--status-danger-bg);
  color: var(--status-danger);
  border: 1px solid color-mix(in srgb, var(--status-danger) 30%, transparent);
}
.badge-info {
  background: var(--status-info-bg);
  color: var(--status-info);
  border: 1px solid color-mix(in srgb, var(--status-info) 30%, transparent);
}
.badge-neutral {
  background: var(--bg-surface-2);
  color: var(--fg-secondary);
  border: 1px solid var(--border-default);
}

/* ── Modal / Overlay ── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 200;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.overlay.open { display: flex; }

.modal {
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-subtle);
  padding: var(--space-6);
  width: 500px;
  max-width: calc(100vw - var(--space-6));
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--elev-modal);
}

/* モバイルではボトムシート風に */
@media (max-width: 480px) {
  .overlay { align-items: flex-end; }
  .modal {
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: var(--space-5);
    padding-bottom: max(var(--space-6), env(safe-area-inset-bottom));
  }
}

.modal-title { font-size: var(--fs-title3); font-weight: 700; margin-bottom: var(--space-5); }
.modal-footer {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

/* ── AI Result Box ── */
.result-box {
  background: var(--bg-surface-2);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  padding: var(--space-5);
  font-size: var(--fs-footnote);
  line-height: var(--lh-relaxed);
  color: var(--fg-secondary);
  white-space: pre-wrap;
  margin-top: var(--space-4);
  min-height: 60px;
}

/* ── Loading ── */
.loading { display: flex; align-items: center; gap: var(--space-4); color: var(--fg-tertiary); }

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

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 48px var(--space-5);
  color: var(--fg-tertiary);
}
.empty-state .icon { font-size: 40px; margin-bottom: var(--space-4); }
.empty-state p { font-size: var(--fs-footnote); color: var(--fg-tertiary); }

/* ── Alert ── */
.alert {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--fs-footnote);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
}
.alert-success {
  background: var(--status-success-bg);
  color: var(--status-success);
  border: 1px solid color-mix(in srgb, var(--status-success) 30%, transparent);
}
.alert-warning {
  background: var(--status-warning-bg);
  color: var(--status-warning);
  border: 1px solid color-mix(in srgb, var(--status-warning) 30%, transparent);
}
.alert-danger {
  background: var(--status-danger-bg);
  color: var(--status-danger);
  border: 1px solid color-mix(in srgb, var(--status-danger) 30%, transparent);
}
.alert-info {
  background: var(--status-info-bg);
  color: var(--status-info);
  border: 1px solid color-mix(in srgb, var(--status-info) 30%, transparent);
}

/* ── Progress Bar ── */
.progress-wrap {
  background: var(--bg-surface-2);
  border-radius: var(--radius-full);
  height: 4px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width var(--dur-5) var(--ease-emphasized);
}

/* ── Utilities ── */
.text-primary { color: var(--accent); }
.text-success { color: var(--status-success); }
.text-danger  { color: var(--status-danger); }
.text-muted   { color: var(--fg-tertiary); }
.text-sub     { color: var(--fg-secondary); }
.text-sm      { font-size: var(--fs-footnote); }
.text-xs      { font-size: var(--fs-caption1); }
.text-lg      { font-size: var(--fs-title3); }
.text-bold    { font-weight: 700; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.mt-2 { margin-top: var(--space-3); }
.mt-3 { margin-top: var(--space-4); }
.mt-4 { margin-top: var(--space-5); }
.mb-4 { margin-bottom: var(--space-5); }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-canvas); }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-tertiary); }
