:root {
  --primary: #1a56db;
  --primary-dark: #1e429f;
  --primary-light: #e1effe;
  --success: #0e9f6e;
  --success-light: #def7ec;
  --warning: #c27803;
  --warning-light: #fdf6b2;
  --danger: #e02424;
  --danger-light: #fde8e8;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --sidebar-w: 240px;
  --header-h: 60px;
}

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

body {
  font-family: 'Segoe UI', 'Hiragino Sans', 'Yu Gothic UI', sans-serif;
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-50);
}

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

/* ===== LOGIN ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #1a56db 100%);
}

.login-box {
  background: white;
  border-radius: 12px;
  padding: 40px;
  width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .logo-icon {
  width: 56px;
  height: 56px;
  background: var(--primary);
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.login-logo .logo-icon svg { width: 32px; height: 32px; fill: white; }
.login-logo h1 { font-size: 20px; font-weight: 700; color: var(--gray-900); }
.login-logo p { font-size: 13px; color: var(--gray-500); margin-top: 4px; }

/* ===== LAYOUT ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--gray-900);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  background: white;
  padding: 8px 10px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-logo img {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}

.sidebar-user {
  padding: 14px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-user .user-name { font-size: 13px; font-weight: 600; color: white; }
.sidebar-user .user-code { font-size: 11px; color: var(--gray-400); margin-top: 2px; }
.sidebar-user .user-role {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 20px;
  margin-top: 4px;
  background: rgba(255,255,255,0.1);
  color: var(--gray-300);
}

.sidebar-user .user-role.admin { background: rgba(26,86,219,0.5); color: #93c5fd; }

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-500);
  padding: 8px 20px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--gray-400);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.15s;
  font-size: 13px;
}

.nav-item:hover { background: rgba(255,255,255,0.06); color: white; }
.nav-item.active { background: rgba(26,86,219,0.2); color: white; border-left-color: var(--primary); }

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.btn-logout {
  width: 100%;
  padding: 9px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-logout:hover { background: rgba(224,36,36,0.2); color: #fca5a5; border-color: rgba(224,36,36,0.3); }
.btn-logout svg { width: 16px; height: 16px; }

/* ===== MAIN CONTENT ===== */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 28px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 101;
}

.page-header h2 { font-size: 18px; font-weight: 700; color: var(--gray-900); }
.page-header .header-actions { display: flex; gap: 8px; align-items: center; }

.page-body { padding: 24px 28px; flex: 1; }

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

.stat-card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg { width: 24px; height: 24px; }
.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.yellow { background: var(--warning-light); color: var(--warning); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }

.stat-info .stat-value { font-size: 24px; font-weight: 700; color: var(--gray-900); }
.stat-info .stat-label { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

/* ===== CARD ===== */
.card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 20px;
}

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

.card-title { font-size: 15px; font-weight: 600; color: var(--gray-900); }
.card-body { padding: 20px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-secondary { background: white; color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #057a55; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c81e1e; }
.btn-warning { background: #d97706; color: white; }
.btn-warning:hover { background: #b45309; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 7px; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--gray-700); margin-bottom: 6px; }
.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 7px;
  font-size: 14px;
  color: var(--gray-800);
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}

.form-control.is-invalid { border-color: var(--danger); }
.form-hint { font-size: 12px; color: var(--gray-500); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  background: var(--gray-50);
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 13px;
  color: var(--gray-700);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }

.table-actions { display: flex; gap: 4px; }

/* ===== STATUS BADGES ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-pending { background: var(--warning-light); color: var(--warning); }
.badge-in_progress { background: var(--primary-light); color: var(--primary); }
.badge-unrecorded { background: #fef3c7; color: #d97706; border: 1px solid #fcd34d; }
.badge-completed { background: var(--success-light); color: var(--success); }
.badge-draft { background: var(--gray-100); color: var(--gray-600); }
.badge-sent { background: var(--primary-light); color: var(--primary); }
.badge-approved { background: var(--success-light); color: var(--success); }
.badge-paid { background: var(--success-light); color: var(--success); }
.badge-admin { background: rgba(26,86,219,0.1); color: var(--primary); }
.badge-staff { background: var(--gray-100); color: var(--gray-600); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-lg { max-width: 800px; }

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 16px; font-weight: 700; color: var(--gray-900); }

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--gray-100);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  transition: all 0.15s;
}

.modal-close:hover { background: var(--gray-200); color: var(--gray-700); }
.modal-close svg { width: 16px; height: 16px; }

.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ===== SEARCH & FILTER ===== */
.filter-bar {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 14px 20px;
  margin-bottom: 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.filter-bar .form-group { margin-bottom: 0; min-width: 160px; }

/* ===== ITEMS TABLE (estimate/invoice) ===== */
.items-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.items-table th { background: var(--gray-50); padding: 8px 10px; font-size: 12px; font-weight: 600; color: var(--gray-600); border: 1px solid var(--gray-200); }
.items-table td { padding: 6px 8px; border: 1px solid var(--gray-200); vertical-align: middle; }
.items-table input { border: none; outline: none; width: 100%; background: transparent; font-size: 13px; }
.items-table input:focus { background: var(--primary-light); border-radius: 3px; }
.items-total { text-align: right; font-size: 13px; color: var(--gray-700); margin-bottom: 8px; }
.items-total strong { font-size: 16px; color: var(--gray-900); }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray-400);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* ===== ALERT ===== */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.alert-danger { background: var(--danger-light); color: #9b1c1c; border: 1px solid #fca5a5; }
.alert-success { background: var(--success-light); color: #014737; border: 1px solid #6ee7b7; }

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--gray-200);
  margin-bottom: 20px;
}

.tab-btn {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
}

.tab-btn:hover { color: var(--gray-800); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== DETAIL VIEW ===== */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.detail-item .detail-label { font-size: 11px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.detail-item .detail-value { font-size: 14px; color: var(--gray-800); }

/* ===== MISC ===== */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 12px; }
.fw-bold { font-weight: 700; }
.mt-4 { margin-top: 16px; }
.hidden { display: none !important; }

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--gray-400);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 8px;
}

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

/* ===== TOAST ===== */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  animation: slideIn 0.2s ease;
}

.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
.toast-success svg { color: var(--success); }
.toast-error svg { color: var(--danger); }

@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== PROJECT SUBNAV ===== */
.project-subnav {
  background: white;
  border-bottom: 2px solid var(--gray-200);
  padding: 0 28px;
  display: flex;
  gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: sticky;
  top: var(--header-h);
  z-index: 40;
}
.subnav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color 0.15s;
}
.subnav-btn:hover { color: var(--gray-800); }
.subnav-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.subnav-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

/* ===== TODAY PAGE ===== */
.today-date-header {
  background: linear-gradient(135deg, var(--primary) 0%, #1e3a8a 100%);
  color: white;
  border-radius: 12px;
  padding: 24px 28px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.today-date-header .date-main { font-size: 28px; font-weight: 700; }
.today-date-header .date-sub { font-size: 14px; opacity: 0.85; margin-top: 4px; }
.today-date-header .weather-icon { font-size: 48px; opacity: 0.7; }

.today-project-card {
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 12px;
  background: white;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: box-shadow 0.15s;
}
.today-project-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.today-project-card .project-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.today-project-card .project-info { flex: 1; min-width: 0; }
.today-project-card .project-name { font-weight: 600; font-size: 14px; color: var(--gray-900); }
.today-project-card .project-meta { font-size: 12px; color: var(--gray-500); margin-top: 3px; }
.today-project-card .project-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* print */
@media print {
  .sidebar, .page-header, .btn, .filter-bar { display: none !important; }
  .main-content { margin-left: 0; }
}

/* ===== HAMBURGER BUTTON ===== */
.hamburger-btn {
  display: none;
  width: 38px;
  height: 38px;
  border: 1px solid var(--gray-200);
  background: white;
  border-radius: 7px;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-shrink: 0;
  transition: background 0.15s;
}
.hamburger-btn:hover { background: var(--gray-100); }
.hamburger-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--gray-700);
  border-radius: 2px;
}

/* ===== HEADER LEFT ===== */
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ===== SIDEBAR OVERLAY ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 99;
}
.sidebar-overlay.visible { display: block; }

/* ===== RANK BADGES ===== */
.badge-rank-vip { background: #fef3c7; color: #92400e; }
.badge-rank-general { background: var(--gray-100); color: var(--gray-600); }
.badge-rank-prospect { background: var(--primary-light); color: var(--primary); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open {
    transform: translateX(0);
    z-index: 100;
  }

  .hamburger-btn { display: flex; }

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

  .page-header { padding: 0 14px; }
  .page-body { padding: 14px; }

  .form-row { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr 1fr; }

  .stats-grid { grid-template-columns: 1fr 1fr; }

  .detail-grid { grid-template-columns: 1fr; }

  .filter-bar { padding: 12px 14px; gap: 8px; }
  .filter-bar .form-group { min-width: 130px; }

  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { border-radius: 14px 14px 0 0; max-height: 92vh; }

  .table-wrap { -webkit-overflow-scrolling: touch; }

  /* 今日の予定 2カラム → 1カラム */
  #today-grid { grid-template-columns: 1fr !important; }

  /* プロジェクトサブナビ */
  .project-subnav { padding: 0 14px; }
  .subnav-btn { padding: 10px 12px; font-size: 12px; }

  /* 今日の案件カード */
  .today-project-card { flex-direction: column; align-items: flex-start; gap: 10px; }
  .today-project-card .project-actions { width: 100%; }
  .today-project-card .project-actions .btn { flex: 1; justify-content: center; }
}
