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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --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;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.1), 0 2px 4px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

header {
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  color: white;
  padding: 1.5rem 2rem;
  box-shadow: var(--shadow-md);
}
.header-inner { max-width: 1400px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; }
.header-left {}
header h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: 0.05em; }
header .subtitle { font-size: 0.85rem; opacity: 0.85; margin-top: 0.25rem; }
.header-right { display: flex; align-items: center; gap: 0.75rem; }
.user-badge { font-size: 0.85rem; font-weight: 600; color: white; }
.role-badge {
  font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.15rem 0.5rem; border-radius: 9999px;
}
.role-badge.admin { background: #fbbf24; color: #78350f; }
.role-badge.user { background: rgba(255,255,255,.2); color: white; }
.btn-logout {
  background: rgba(255,255,255,.15); color: white; border: 1px solid rgba(255,255,255,.3);
  padding: 0.3rem 0.7rem; font-size: 0.75rem; border-radius: 6px; cursor: pointer;
  transition: background 0.15s;
}
.btn-logout:hover { background: rgba(255,255,255,.25); }
.btn-notif {
  background: rgba(255,255,255,.15);
  color: white;
  border: 1px solid rgba(255,255,255,.3);
  position: relative;
}
.btn-notif:hover { background: rgba(255,255,255,.25); }
.notif-count {
  min-width: 1.2rem;
  height: 1.2rem;
  border-radius: 9999px;
  background: #ef4444;
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  align-items: center;
  justify-content: center;
  padding: 0 0.3rem;
}

nav#main-nav {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  gap: 0;
  overflow-x: auto;
  padding: 0 1rem;
  max-width: 1400px;
  margin: 0 auto;
  -webkit-overflow-scrolling: touch;
}
.nav-btn {
  background: none;
  border: none;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--gray-500);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  font-weight: 500;
}
.nav-btn:hover { color: var(--primary); }
.nav-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.section-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gray-800);
}

.payment-filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.payment-filter-group label {
  font-size: 0.8rem;
  color: var(--gray-600);
  font-weight: 600;
}
.payment-filter-group select {
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.85rem;
  background: white;
  color: var(--gray-800);
}

.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.stats-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.stat-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem 1.25rem;
  display: flex;
  flex-direction: column;
}
.stat-label { font-size: 0.75rem; color: var(--gray-500); font-weight: 500; }
.stat-value { font-size: 1.25rem; font-weight: 700; color: var(--gray-800); }
.stat-value.text-primary { color: var(--primary); }
.stat-value.text-success { color: var(--success); }

/* Tables */
.table-wrap {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
thead th {
  background: var(--gray-50);
  padding: 0.625rem 0.75rem;
  text-align: left;
  font-weight: 600;
  color: var(--gray-600);
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
tbody td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
tbody tr:hover { background: var(--gray-50); }
tbody tr.selected-row { background: var(--primary-light); }
tbody tr.unresolved-row { background: #fef2f2; }
tbody tr.unresolved-row:hover { background: #fee2e2; }

/* Buttons */
.btn {
  padding: 0.4rem 0.85rem;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn-outline {
  background: white;
  color: var(--gray-600);
  border: 1px solid var(--gray-300);
}
.btn-outline:hover { background: var(--gray-50); }

.action-btns { display: flex; gap: 0.25rem; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-close {
  background: none; border: none;
  font-size: 1.5rem; color: var(--gray-400);
  cursor: pointer; line-height: 1;
}
#modal-body { padding: 1.5rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 0.25rem;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.5rem; }

/* Plan card layout */
.plan-section { margin-bottom: 1.5rem; }
.plan-section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-dark);
  padding-bottom: 0.375rem;
  border-bottom: 2px solid var(--primary-light);
  margin-bottom: 0.75rem;
}
.plan-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.5rem 1rem;
  align-items: start;
}
.plan-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-500);
  padding-top: 0.25rem;
}
.plan-value {
  font-size: 0.9rem;
  color: var(--gray-800);
  padding: 0.25rem 0;
  white-space: pre-line;
}
.plan-value.editable {
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: background 0.15s;
  min-height: 1.5em;
  border: 1px dashed transparent;
}
.plan-value.editable:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--primary-light); color: var(--primary); }

/* Checkbox style */
.check-mark { font-size: 1.1rem; }
.check-mark.checked { color: var(--success); }
.check-mark.unchecked { color: var(--gray-300); }

/* Deadline cards */
.deadline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}
.deadline-card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.deadline-card h4 {
  font-size: 0.85rem;
  color: var(--gray-500);
  margin-bottom: 0.5rem;
}
.deadline-card .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-800);
}
.deadline-card .sub { font-size: 0.8rem; color: var(--gray-400); margin-top: 0.25rem; }

/* Loading */
.loading {
  text-align: center;
  padding: 2rem;
  color: var(--gray-400);
}

/* Notifications */
.notif-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.75rem;
}
.notif-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.notif-item {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 0.75rem;
  background: white;
}
.notif-item.unread {
  border-color: #fca5a5;
  background: #fff1f2;
}
.notif-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.72rem;
  color: var(--gray-500);
}
.notif-title {
  font-size: 0.88rem;
  font-weight: 700;
  margin-top: 0.3rem;
}
.notif-message {
  font-size: 0.82rem;
  color: var(--gray-700);
  margin-top: 0.2rem;
  white-space: pre-line;
}
.notif-read-action {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.45rem;
}

/* Responsive */
@media (max-width: 768px) {
  header { padding: 1rem; }
  header h1 { font-size: 1.2rem; }
  .nav-btn { padding: 0.6rem 0.75rem; font-size: 0.75rem; }
  main { padding: 1rem 0.5rem; }
  .form-row { grid-template-columns: 1fr; }
  .plan-grid { grid-template-columns: 1fr; }
  .plan-label { font-weight: 700; }
}

/* Number formatting */
.num { text-align: right; font-variant-numeric: tabular-nums; }
.num-positive { color: var(--success); }
.num-zero { color: var(--gray-400); }

/* Toast notification */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  color: white;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 2000;
  animation: slideIn 0.3s ease;
  box-shadow: var(--shadow-md);
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
@keyframes slideIn {
  from { transform: translateY(1rem); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
