/* ==========================================================================
   工数管理システム デザインシステム
   Apple的なミニマル・高精細UIを意識: 白ベース + ブルーアクセント + カードUI
   ========================================================================== */

:root {
  /* カラー */
  --color-bg: #f5f5f7;
  --color-surface: #ffffff;
  --color-surface-hover: #fafafa;
  --color-border: #e5e5ea;
  --color-text-primary: #1d1d1f;
  --color-text-secondary: #6e6e73;
  --color-text-tertiary: #a1a1a6;
  --color-accent: #0071e3;
  --color-accent-hover: #0077ed;
  --color-accent-soft: #e8f2fd;
  --color-success: #34c759;
  --color-warning: #ff9f0a;
  --color-danger: #ff3b30;
  --color-purple: #af52de;

  /* ステータスカラー */
  --status-estimating: #af52de;
  --status-in_progress: #0071e3;
  --status-waiting_review: #ff9f0a;
  --status-revising: #ff453a;
  --status-completed: #34c759;
  --status-on_hold: #8e8e93;

  /* タイポグラフィ */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Segoe UI", Roboto, sans-serif;

  /* シャドウ */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.10);

  /* 角丸 */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  /* スペーシング */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-8: 48px;

  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --color-bg: #000000;
  --color-surface: #1c1c1e;
  --color-surface-hover: #2c2c2e;
  --color-border: #38383a;
  --color-text-primary: #f5f5f7;
  --color-text-secondary: #a1a1a6;
  --color-text-tertiary: #6e6e73;
  --color-accent: #0a84ff;
  --color-accent-hover: #409cff;
  --color-accent-soft: #0a3d66;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text-primary);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
  transition: background var(--transition-base), color var(--transition-base);
}

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

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.02em; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
p { margin: 0; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ========================= レイアウト ========================= */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: var(--space-5) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  padding: var(--space-2) var(--space-3) var(--space-5);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.sidebar-brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--color-accent);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-weight: 500;
  font-size: 14px;
  transition: background var(--transition-fast), color var(--transition-fast);
  cursor: pointer;
}
.nav-item:hover { background: var(--color-surface-hover); color: var(--color-text-primary); }
.nav-item.active { background: var(--color-accent-soft); color: var(--color-accent); }
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; }

.main {
  flex: 1;
  min-width: 0;
  padding: var(--space-6);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  gap: var(--space-3);
  flex-wrap: wrap;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--color-accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}

/* ========================= カード ========================= */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base);
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-4);
}

.grid {
  display: grid;
  gap: var(--space-4);
}
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.stat-label {
  font-size: 13px;
  color: var(--color-text-secondary);
}

/* ========================= フォーム ========================= */

.form-group { margin-bottom: var(--space-4); position: relative; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

.form-control {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-size: 15px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-control:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 4px var(--color-accent-soft);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236e6e73' stroke-width='1.5' fill='none' fill-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

textarea.form-control { resize: vertical; min-height: 80px; }

.form-row {
  display: flex;
  gap: var(--space-3);
}
.form-row > * { flex: 1; }

/* ボタン */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 11px 22px;
  border-radius: 980px;
  font-weight: 600;
  font-size: 14px;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.btn-primary { background: var(--color-accent); color: #fff; }
.btn-primary:hover { background: var(--color-accent-hover); transform: translateY(-1px); }
.btn-secondary { background: var(--color-surface-hover); color: var(--color-text-primary); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: var(--color-border); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--color-accent); padding: 8px 12px; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ========================= オートコンプリート（案件名） ========================= */

.autocomplete-wrapper { position: relative; }
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  max-height: 260px;
  overflow-y: auto;
  z-index: 50;
  display: none;
}
.autocomplete-list.open { display: block; }
.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover, .autocomplete-item.highlighted { background: var(--color-accent-soft); }
.autocomplete-item .name { font-weight: 500; }
.autocomplete-item.create-new { color: var(--color-accent); font-weight: 600; }
.autocomplete-empty { padding: var(--space-4); color: var(--color-text-tertiary); font-size: 13px; text-align: center; }

/* ========================= バッジ / ステータス ========================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 980px;
  font-size: 12px;
  font-weight: 600;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.badge-estimating { background: rgba(175,82,222,0.12); color: var(--status-estimating); }
.badge-in_progress { background: rgba(0,113,227,0.12); color: var(--status-in_progress); }
.badge-waiting_review { background: rgba(255,159,10,0.12); color: var(--status-waiting_review); }
.badge-revising { background: rgba(255,69,58,0.12); color: var(--status-revising); }
.badge-completed { background: rgba(52,199,89,0.12); color: var(--status-completed); }
.badge-on_hold { background: rgba(142,142,147,0.12); color: var(--status-on_hold); }

/* ========================= テーブル ========================= */

.table-wrapper { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--color-border); }
table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--color-surface); }
th, td { text-align: left; padding: 12px 16px; white-space: nowrap; }
thead th {
  background: var(--color-surface-hover);
  color: var(--color-text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky; top: 0;
}
tbody tr { border-top: 1px solid var(--color-border); transition: background var(--transition-fast); }
tbody tr:hover { background: var(--color-surface-hover); }

/* プログレスバー */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 999px;
  transition: width var(--transition-base);
}

/* レンジスライダー（進捗率入力） */
input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--color-border);
  appearance: none;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  cursor: pointer;
}

/* トースト通知 */
.toast-container {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 1000;
}
.toast {
  background: var(--color-text-primary);
  color: var(--color-bg);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 500;
  animation: toast-in 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.toast.error { background: var(--color-danger); color: #fff; }
.toast.success { background: var(--color-success); color: #fff; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* モーダル */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: var(--space-4);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  max-height: 85vh;
  overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-4);
}
.modal-close { cursor: pointer; color: var(--color-text-tertiary); font-size: 20px; background: none; border: none; }

/* ========================= ログイン画面 ========================= */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--color-bg) 0%, var(--color-surface-hover) 100%);
  padding: var(--space-4);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-8) var(--space-6);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--color-accent);
  margin: 0 auto var(--space-5);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 24px; font-weight: 700;
}
.login-title { font-size: 22px; margin-bottom: var(--space-1); }
.login-subtitle { color: var(--color-text-secondary); font-size: 14px; margin-bottom: var(--space-6); }
.login-error {
  background: rgba(255,59,48,0.1);
  color: var(--color-danger);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: var(--space-4);
  text-align: left;
}

/* ========================= ボトムナビ（スマホ） ========================= */

.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 100;
}
.bottom-nav-inner {
  display: flex;
  justify-content: space-around;
}
.bottom-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--color-text-tertiary);
  font-size: 11px;
  padding: 4px 12px;
}
.bottom-nav-item.active { color: var(--color-accent); }
.bottom-nav-item .icon { width: 22px; height: 22px; }

/* ダークモード切り替えスイッチ */
.theme-toggle {
  width: 44px; height: 26px;
  border-radius: 999px;
  background: var(--color-border);
  position: relative;
  cursor: pointer;
  border: none;
  flex-shrink: 0;
}
.theme-toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}
.theme-toggle.on { background: var(--color-accent); }
.theme-toggle.on::after { transform: translateX(18px); }

/* ユーティリティ */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.text-secondary { color: var(--color-text-secondary); }
.text-tertiary { color: var(--color-text-tertiary); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mt-4 { margin-top: var(--space-4); }
.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--color-text-tertiary);
}

/* ========================= レスポンシブ ========================= */

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

@media (max-width: 720px) {
  .sidebar { display: none; }
  .main { padding: var(--space-4); padding-bottom: 88px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }
  .bottom-nav { display: block; }
  h1 { font-size: 22px; }
  .login-card { padding: var(--space-6) var(--space-4); }
}
