:root {
  --bg: #f3f6fb;
  --sidebar: #10233d;
  --sidebar-soft: #1a3558;
  --panel: #ffffff;
  --panel-alt: #f8fafc;
  --primary: #1f8ef1;
  --primary-dark: #1067bf;
  --secondary: #dfeafc;
  --accent: #14b8a6;
  --warning: #ffb703;
  --danger: #ef4444;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
  background: linear-gradient(135deg, #eef6ff 0%, #f7fafc 100%);
  color: var(--text);
}

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e0f2fe, #f8fafc 60%, #eff6ff);
  padding: 24px;
}

.login-screen.active {
  display: flex;
}

.login-card {
  width: min(420px, 100%);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
  padding: 28px;
}

.login-logo {
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: linear-gradient(135deg, #1f8ef1, #66b6ff);
  font-weight: 800;
  color: white;
  margin-bottom: 18px;
}

.login-card h2 {
  margin: 0;
  font-size: 2rem;
}

.login-subtitle {
  color: var(--muted);
  margin: 8px 0 18px;
}

.demo-accounts {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid var(--border);
  background: white;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
}

.chip.active {
  background: #eaf4ff;
  color: var(--primary-dark);
  border-color: #b9d8ff;
}

#loginForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#loginForm label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--muted);
  font-weight: 600;
}

#loginForm input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fafc;
}

.full-width {
  width: 100%;
}

/* グリッド内では全列にまたがる（支払先欄や備考を1行に収めるため） */
.form-grid > .full-width {
  grid-column: 1 / -1;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-soft) 100%);
  color: white;
  padding: 24px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,0.15);
  font-weight: 700;
}

.brand-name {
  font-size: 1.05rem;
  font-weight: 700;
}

.brand small {
  color: rgba(255,255,255,0.7);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.8);
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255,255,255,0.08);
  color: white;
  border-color: rgba(255,255,255,0.22);
}

.sidebar-card {
  margin-top: 28px;
  background: rgba(255,255,255,0.05);
  padding: 16px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
}

.card-label {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.72);
  margin-bottom: 8px;
}

.month-pill {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.mini-meta {
  color: rgba(255,255,255,0.78);
  font-size: 0.8rem;
}

.content {
  flex: 1;
  padding: 28px 28px 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.eyebrow {
  font-size: 0.76rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

h1 {
  margin: 0;
  font-size: 2rem;
}

.user-area {
  display: flex;
  align-items: center;
  gap: 14px;
}

.user-badge {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.ghost-btn,
.primary-btn,
.secondary-btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
}

.ghost-btn {
  background: #eef4ff;
  color: var(--primary-dark);
}

.primary-btn {
  background: linear-gradient(135deg, var(--primary), #47a6ff);
  color: white;
  box-shadow: 0 8px 16px rgba(31, 142, 241, 0.2);
}

.secondary-btn {
  background: var(--secondary);
  color: var(--primary-dark);
}

.small {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 18px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.stat-card.accent {
  background: linear-gradient(135deg, #ecfeff, #eff6ff);
}

.stat-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
}

.stat-value {
  font-weight: 800;
  font-size: 2rem;
  margin-bottom: 8px;
}

.stat-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.panel-grid {
  display: grid;
  gap: 20px;
  margin-bottom: 20px;
}

.two-columns {
  grid-template-columns: 1.2fr 0.8fr;
}

.large-gap {
  gap: 28px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.link-text {
  text-decoration: none;
  color: var(--primary);
  font-weight: 600;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 12px;
}

.quick-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 12px;
  font-weight: 600;
  text-align: left;
}

.icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #dff7f3;
  color: var(--accent);
}

.summary-list, .rule-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.summary-list li, .rule-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}

.summary-list li:last-child, .rule-list li:last-child {
  border-bottom: none;
}

.total {
  color: var(--primary-dark);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

th {
  font-size: 0.82rem;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.checkbox-cell {
  width: 40px;
  text-align: center;
}

.checkbox-cell input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.selected-row {
  background: #f8fbff;
}

.danger-btn {
  background: #fee2e2;
  color: #b91c1c;
}

.danger-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.status {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.status.pending {
  background: #fff4d6;
  color: #b45309;
}

.status.approved {
  background: #dcfce7;
  color: #166534;
}

.status.returned {
  background: #fee2e2;
  color: #b91c1c;
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.checkbox-field input {
  width: auto;
}

.form-note {
  font-size: 0.8rem;
  color: var(--muted);
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--primary-dark, #1d4ed8);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.view-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.view-user span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.view-user select {
  max-width: 280px;
}

.payment-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.payment-head,
.payment-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 10px;
  align-items: center;
}

.payment-head span {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.payment-row input[type="number"] {
  text-align: right;
}

.payment-row output {
  display: block;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: right;
}

.edit-badge {
  display: inline-block;
  margin-left: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff4d6;
  color: #b45309;
  font-size: 0.72rem;
  font-weight: 700;
  vertical-align: middle;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

label span {
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
}

textarea {
  min-height: 86px;
  resize: vertical;
}

.route-panel {
  background: linear-gradient(180deg, #f7fbff, #ffffff);
}

.route-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.route-item {
  border: 1px solid var(--border);
  background: white;
  border-radius: 12px;
  padding: 12px 14px;
}

.route-item.selected {
  border-color: #97d0ff;
  background: #edf7ff;
}

.route-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.route-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.route-source-notice {
  margin-bottom: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #fff4d6;
  color: #b45309;
  font-size: 0.78rem;
  font-weight: 600;
}

.route-message {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 14px;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.calc-box {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
}

.calc-row.total {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--text);
  font-size: 1.05rem;
}

.detail-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
  padding: 14px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.detail-summary div {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.inline-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.copy-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.copy-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}

.copy-modal-card {
  width: min(640px, 100%);
  background: white;
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.2);
}

.copy-modal-header,
.copy-month-bar,
.copy-modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.copy-modal-header {
  margin-bottom: 18px;
}

.copy-modal-header h3 {
  margin: 0;
  font-size: 1.3rem;
}

.copy-month-bar {
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.copy-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 18px;
}

.copy-calendar-header {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  padding: 8px 4px;
  font-weight: 700;
}

.copy-day {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
  color: var(--text);
  font-weight: 600;
}

.copy-day.empty {
  background: transparent;
  border-style: dashed;
  opacity: 0.3;
  pointer-events: none;
}

.copy-day.selected {
  background: linear-gradient(135deg, #dbeafe, #dff7f3);
  border-color: #86b7ff;
  color: var(--primary-dark);
}

.copy-day:hover {
  border-color: #8ac6ff;
}

.pdf-box {
  margin-top: 18px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 14px;
  background: linear-gradient(180deg, #f8fafc, #ffffff);
}

.pdf-header {
  font-weight: 700;
  margin-bottom: 10px;
}

.pdf-preview {
  background: linear-gradient(180deg, #ffffff 0%, #fcfdff 100%);
  border: 1px solid #d9e2ec;
  border-radius: 12px;
  min-height: 210px;
  padding: 20px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.02);
}

.pdf-header-row,
.pdf-summary-row,
.pdf-table-head,
.pdf-table-row {
  display: grid;
  grid-template-columns: 96px 1fr 120px;
  gap: 10px;
  align-items: center;
}

.pdf-header-row {
  font-size: 1.15rem;
  justify-content: space-between;
  grid-template-columns: 1fr auto;
  padding-bottom: 8px;
  border-bottom: 2px solid #0f172a;
  margin-bottom: 2px;
}

.pdf-meta {
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

.pdf-table {
  border: 1px solid #dfe5ee;
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
}

.pdf-table-head,
.pdf-table-row {
  padding: 8px 10px;
}

.pdf-table-head {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  background: #f3f7fb;
  border-bottom: 1px solid #dfe5ee;
}

.pdf-table-row {
  font-size: 0.78rem;
  color: var(--text);
  background: white;
  border-bottom: 1px solid #edf1f6;
}

.pdf-table-row:last-child {
  border-bottom: none;
}

.pdf-summary-row {
  font-size: 0.8rem;
  color: var(--muted);
  grid-template-columns: 1fr auto;
  padding-top: 4px;
}

.total-row {
  color: var(--text);
  font-size: 0.95rem;
  border-top: 1px solid #dfe5ee;
  padding-top: 10px;
  margin-top: 4px;
}

.total-row strong {
  font-size: 1.2rem;
  color: #0f172a;
}

.approval-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.approval-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}

.approval-name {
  font-weight: 700;
  margin-bottom: 4px;
}

.approval-meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.approval-actions {
  display: flex;
  gap: 10px;
}

.link-btn {
  border: none;
  background: transparent;
  color: var(--primary-dark);
  font-weight: 700;
  padding: 0;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: rgba(15, 23, 42, 0.9);
  color: white;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

@media (max-width: 980px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
  }

  .stats-grid,
  .two-columns,
  .form-grid,
  .quick-actions {
    grid-template-columns: 1fr;
  }
}
