:root {
  --bg: #f4f6f8;
  --surface: #fff;
  --ink: #172033;
  --text: #172033;
  --muted: #667085;
  --line: #d0d7e2;
  --border: #d0d7e2;
  --soft-line: #e6ebf2;
  --accent: #147d64;
  --accent-dark: #0f604e;
  --danger: #b42318;
  --blue: #1d4ed8;
  --orange: #b54708;
  --red: #c01024;
  --green: #16803c;
  --shadow: 0 14px 32px rgba(23, 32, 51, .08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { color-scheme: light; }

body {
  min-width: 1060px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

.recovery-mode-banner {
  position: relative;
  z-index: 100;
  padding: 12px 18px;
  border-bottom: 2px solid #b54708;
  background: #fffaeb;
  color: #7a2e0e;
  font-weight: 800;
  line-height: 1.5;
  text-align: center;
}

button, input, select, textarea { font: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgba(20, 125, 100, .28);
  outline-offset: 2px;
}

.app { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; }

.app-header {
  position: relative;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 28px 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.eyebrow { margin: 0 0 4px; color: var(--accent); font-size: .78rem; font-weight: 800; text-transform: uppercase; }
h1 { margin: 0 0 18px; font-size: 1.8rem; letter-spacing: 0; }
.signed-in-user { margin: -14px 0 14px; color: var(--muted); font-size: .82rem; }

.month-tabs { display: flex; align-items: end; gap: 4px; }
.month-tab {
  display: inline-flex;
  min-width: 128px;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: #eef2f7;
  color: #475467;
  font-weight: 700;
  text-decoration: none;
}
.month-tab.active { min-height: 56px; background: var(--bg); color: var(--ink); }
.month-tab.disabled { pointer-events: none; opacity: .48; }

.account-nav, .admin-nav { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.account-nav { padding-bottom: 10px; }

.is-editing .month-tab,
.is-editing .print-button,
.is-editing .review-button,
.is-editing .mobile-month-picker select,
.is-editing .mobile-pc-link,
.is-editing tbody tr:not(.editing-row) .edit-button,
.is-editing tbody tr:not(.editing-row) .danger,
.is-editing .mobile-day-card:not(.editing-row) .edit-button,
.is-editing .mobile-day-card:not(.editing-row) .danger {
  cursor: not-allowed;
  opacity: .48;
  pointer-events: none;
}

.floating-message {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 50;
  display: grid;
  min-width: 360px;
  max-width: min(720px, calc(100vw - 48px));
  gap: 4px;
  padding: 14px 18px;
  border: 1px solid #fecdca;
  border-left: 5px solid var(--danger);
  border-radius: 8px;
  background: #fff7f7;
  box-shadow: 0 18px 44px rgba(23, 32, 51, .18);
  color: var(--danger);
  transform: translateX(-50%);
}
.floating-message span { color: #7a271a; line-height: 1.5; }

.app-body { padding: 20px 24px 112px; }
.body-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.label { display: block; margin-bottom: 2px; color: var(--muted); font-size: .78rem; font-weight: 700; }
.toolbar-status { display: flex; align-items: center; gap: 10px; }

.button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.button:hover { background: #f8fafc; }
.button.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-dark); }
.button.danger { border-color: #fecdca; background: #fff1f0; color: var(--danger); }
.button.large { min-height: 48px; padding: 0 24px; font-size: 1.05rem; }
.button:disabled { cursor: not-allowed; opacity: .48; }

.month-state { padding: 6px 10px; border-radius: 999px; background: #ecfdf3; color: var(--accent-dark); font-weight: 700; }
.month-state.locked { background: #eef2f7; color: #344054; }

.table-panel { overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.table-wrap { max-height: calc(100vh - 250px); overflow: auto; }
table { width: 100%; min-width: 1280px; border-collapse: separate; border-spacing: 0; }
th, td { height: 58px; padding: 8px; border-right: 1px solid var(--soft-line); border-bottom: 1px solid var(--line); background: var(--surface); text-align: left; vertical-align: middle; font-size: .88rem; }
thead th { position: sticky; top: 0; z-index: 5; background: #f8fafc; text-align: center; font-weight: 800; }
thead small { display: block; margin-top: 3px; color: var(--muted); font-weight: 700; }
.sticky-col { position: sticky; left: 0; z-index: 4; background: var(--surface); box-shadow: 1px 0 0 var(--line); }
thead .sticky-col { z-index: 8; background: #f8fafc; }
.date-col, .date-cell { width: 116px; min-width: 116px; }
.status-col, .status-cell { width: 54px; text-align: center; }
.stack-col, .stack-cell { width: 255px; }
.internal-col, .internal-cell, .internal-edit { width: 76px; text-align: center; }
.leave-type-col, .leave-type-cell, .leave-type-edit { width: 104px; text-align: center; }
.leave-range-col, .leave-range-cell, .leave-range-edit { width: 84px; text-align: center; }
.memo-col, .memo-cell, .memo-edit { width: 230px; }
.action-col, .action-cell { width: 144px; text-align: center; }
.total-cell { width: 76px; text-align: center; font-weight: 800; }
tbody tr:not(.editing-row) td, tbody tr:not(.editing-row) th { font-size: .98rem; }
.date-cell small { display: block; margin-top: 2px; color: var(--muted); font-size: .72rem; }
.saturday .date-cell { color: var(--blue); }
.sunday .date-cell { color: var(--orange); }
.public-holiday .date-cell { color: var(--red); }
.company-holiday .date-cell { color: var(--green); }

.stack-line { display: grid; grid-template-columns: minmax(112px, 1fr) 56px; align-items: center; gap: 6px; min-height: 28px; text-align: center; }
.stack-line + .stack-line { border-top: 1px solid #eef2f7; }
.stack-time { font-weight: 800; }
.stack-break { color: var(--muted); }
.status-icon { display: inline-flex; width: 28px; height: 28px; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 50%; background: #f8fafc; color: var(--muted); font-size: .78rem; font-weight: 900; }
.status-icon.ok { border-color: #abefc6; background: #ecfdf3; color: #067647; }
.status-icon.locked { border-color: #c7d7fe; background: #eef4ff; color: #3538cd; }
.status-icon.editing { border-color: #fedf89; background: #fffaeb; color: #b54708; }
.inline-form { display: inline-flex; margin: 0; }
.row-errors { display: grid; gap: 3px; margin: 0 0 6px; padding: 7px; border: 1px solid #fecdca; border-radius: 6px; background: #fff1f0; color: var(--danger); font-size: .72rem; line-height: 1.4; text-align: left; }
.row-errors span { display: block; }

select, input, textarea { min-width: 0; width: 100%; min-height: 36px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
textarea { resize: vertical; }
.stack-edit, .internal-edit, .leave-type-edit, .leave-range-edit, .memo-edit { padding: 6px; }
.time-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 4px; }
.break-edit { min-width: 54px; }
.editing-row .stack-line { grid-template-columns: minmax(132px, 1fr) 58px; gap: 5px; }
.editing-row .stack-line + .stack-line { margin-top: 4px; padding-top: 4px; }
.edit-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.save-block-reason { margin: 0 0 7px; padding: 6px; border-radius: 5px; background: #fff1f0; color: var(--danger); font-size: .72rem; line-height: 1.35; text-align: left; }

.app-footer { position: fixed; right: 0; bottom: 0; left: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-top: 1px solid var(--line); background: rgba(255,255,255,.96); box-shadow: 0 -10px 30px rgba(23,32,51,.08); }
.summary-item { display: grid; min-width: 104px; gap: 2px; }
.summary-item span { color: var(--muted); font-size: .74rem; font-weight: 700; }
.summary-item strong { font-size: 1rem; }
.summary-item.featured strong { color: var(--accent-dark); font-size: 1.38rem; }
.summary-item.compact { min-width: 76px; }
.app-footer form { margin-left: auto; }
.summary-manual-warning { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 9px 12px; border: 1px solid #fed7aa; border-radius: 6px; background: #fff7ed; color: #9a3412; line-height: 1.35; }
.summary-manual-warning small { font-family: ui-monospace, monospace; overflow-wrap: anywhere; }
.app-footer > .summary-manual-warning { position: absolute; bottom: calc(100% + 8px); left: 24px; }

/* Administration */
.admin-body { min-width: 920px; }
.admin-page { padding: 28px; }
.admin-page.narrow { max-width: 900px; margin: 0 auto; }
.admin-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.admin-header h1 { margin: 0; }
.admin-header .eyebrow { margin-bottom: 2px; }
.admin-table { min-width: 980px; }
.holiday-table { min-width: 720px; }
.review-admin-table { min-width: 920px; }
.technical-value { max-width: 230px; overflow-wrap: anywhere; font-family: ui-monospace, monospace; font-size: .78rem; }
.empty-state { padding: 28px; color: var(--muted); text-align: center; }
.status-pill { display: inline-flex; padding: 4px 9px; border-radius: 999px; font-size: .76rem; font-weight: 800; }
.status-pill.active { background: #ecfdf3; color: #067647; }
.status-pill.inactive { background: #f2f4f7; color: #475467; }
.admin-success, .admin-error, .form-errors { margin: 0 0 16px; padding: 11px 13px; border-radius: 6px; }
.admin-success { border: 1px solid #a6d8c9; background: #effaf6; color: var(--accent-dark); }
.admin-error, .form-errors { border: 1px solid #fecdca; background: #fff1f0; color: #912018; }
.form-errors ul { margin: 8px 0 0; padding-left: 22px; }
.admin-filter { display: flex; margin-bottom: 14px; }
.admin-filter form { display: flex; align-items: end; gap: 8px; }
.admin-filter label { display: grid; gap: 4px; color: var(--muted); font-size: .82rem; font-weight: 700; }

.user-form { display: grid; gap: 14px; max-width: 720px; padding: 20px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.user-form label { display: grid; gap: 6px; color: var(--muted); font-weight: 700; }
.required { margin-left: 6px; color: var(--danger); font-size: .7rem; }
.field-help { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.55; }
.user-form .checkbox { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.user-form .checkbox input { width: auto; }
.checkbox.standalone { justify-self: start; }
.checkbox-grid { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.manager-selector { display: grid; gap: 8px; margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: 6px; }
.manager-selector legend { color: var(--ink); font-weight: 700; }
.form-actions, .review-decision-form { display: flex; flex-wrap: wrap; gap: 10px; }
.review-admin-summary { margin: 0 0 20px; }
.review-admin-summary div { display: grid; grid-template-columns: 100px 1fr; padding: 8px 0; border-bottom: 1px solid var(--soft-line); }
.review-admin-summary dt { color: var(--muted); font-weight: 700; }
.review-admin-summary dd { margin: 0; }
.force-reject-form { padding: 0; border: 0; box-shadow: none; }

/* Authentication, errors, and review decisions */
.auth-body, .review-body { min-width: 0; }
.auth-page, .review-result-page { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; background: var(--bg); }
.auth-panel, .review-result-panel { width: min(560px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 9px; background: #fff; box-shadow: 0 20px 40px rgba(15,23,42,.08); }
.auth-panel { text-align: center; }
.login-actions { display: grid; gap: 10px; }
.login-actions form { margin: 0; }
.login-actions .button { width: 100%; }
.auth-panel h1, .review-result-panel h1 { margin: 6px 0 12px; font-size: 28px; }
.auth-panel > p:not(.eyebrow), .review-result-message { margin: 0 0 20px; color: var(--text); line-height: 1.7; }
.auth-error, .review-result-warning { margin: 0 0 20px; padding: 12px; border: 1px solid #fed7aa; border-radius: 6px; background: #fff7ed; color: #9a3412; line-height: 1.6; }
.request-id { color: var(--muted) !important; font-size: .82rem; }
.request-id code { user-select: all; }
.error-details { margin: 0 0 20px; padding-left: 22px; color: #912018; }
.processing-indicator { display: flex; align-items: center; gap: 12px; margin: 18px 0; padding: 14px; border-radius: 7px; background: #f0fdf9; color: var(--accent-dark); }
.spinner { width: 22px; height: 22px; flex: none; border: 3px solid #a6d8c9; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Mobile card layout */
body.mobile-body { min-width: 0; background: #f5f5f5; }
.mobile-app { min-height: 100vh; padding: 18px 0 168px; }
.mobile-header { position: sticky; top: 0; z-index: 12; display: grid; grid-template-columns: minmax(0,1fr) 54px 44px; align-items: center; gap: 8px; padding: 12px 14px 6px; background: rgba(245,245,245,.96); backdrop-filter: blur(8px); }
.mobile-month-picker { display: grid; grid-template-columns: 58px minmax(0,1fr); min-height: 44px; align-items: center; overflow: hidden; border: 1px solid #d9dee7; border-radius: 7px; background: #fff; box-shadow: 0 1px 4px rgba(23,32,51,.08); }
.mobile-month-picker span { display: grid; height: 100%; place-items: center; border-right: 1px solid #eef1f5; color: #111827; font-size: .98rem; font-weight: 900; }
.mobile-month-picker select { min-height: 44px; border: 0; border-radius: 0; font-size: 1rem; font-weight: 700; }
.mobile-pc-link { display: grid; width: 44px; height: 44px; place-items: center; border: 1px solid #d9dee7; border-radius: 7px; background: #fff; color: #2563eb; font-weight: 900; text-decoration: none; }
.mobile-review-action, .mobile-review-action form { min-width: 0; margin: 0; }
.mobile-review-action .mobile-review-button { display: grid; min-height: 44px; place-items: center; gap: 0; padding: 4px 6px; border: 1px solid #d9dee7; border-radius: 7px; background: #fff; box-shadow: 0 1px 4px rgba(23,32,51,.08); font-size: .78rem; line-height: 1.05; }
.mobile-review-action .mobile-review-button span { display: block; }
.mobile-list { display: grid; gap: 0; padding: 0 14px; }
.mobile-day-card { overflow: hidden; border-bottom: 1px solid #d7dde6; background: #fff; box-shadow: 0 1px 4px rgba(23,32,51,.12); }
.mobile-day-card.registered { background: #fff8e7; }
.mobile-card-header { display: flex; align-items: start; justify-content: space-between; gap: 8px; padding: 10px 8px 4px; }
.mobile-date { display: grid; gap: 2px; }
.mobile-date strong { color: #111827; font-size: 1rem; line-height: 1.2; }
.mobile-date small { color: var(--muted); font-size: .72rem; }
.saturday .mobile-date strong { color: var(--blue); }
.sunday .mobile-date strong { color: var(--orange); }
.public-holiday .mobile-date strong { color: var(--red); }
.company-holiday .mobile-date strong { color: var(--green); }
.mobile-card-actions { display: flex; align-items: center; gap: 6px; }
.mobile-card-actions .button { min-height: 34px; padding: 6px 10px; font-size: .88rem; }
.mobile-card-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); column-gap: 18px; row-gap: 6px; align-items: center; padding: 0 8px 10px; }
.mobile-metric { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 8px; align-items: baseline; }
.mobile-metric span { color: #111827; font-size: .92rem; }
.mobile-metric strong { color: #111827; font-size: 1.2rem; line-height: 1; text-align: right; }
.mobile-line { grid-column: 1/-1; display: grid; grid-template-columns: minmax(76px,1fr) 28px minmax(48px,.75fr) 28px minmax(48px,.75fr) 32px minmax(42px,.65fr); gap: 4px; align-items: center; padding: 5px 6px; border: 1px solid #e5eaf2; border-radius: 6px; background: #fff; box-shadow: 0 1px 3px rgba(23,32,51,.08); }
.mobile-line > span, .mobile-bottom-row span, .mobile-memo span { color: #111827; font-size: .88rem; line-height: 1.1; }
.mobile-line > span:nth-of-type(2), .mobile-line > span:nth-of-type(3), .mobile-line > span:nth-of-type(4) { writing-mode: vertical-rl; justify-self: center; }
.mobile-line strong { color: #111827; font-size: 1rem; font-weight: 500; text-align: right; }
.mobile-bottom-row { grid-column: 1/-1; display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; align-items: center; padding: 5px 6px; border: 1px solid #e5eaf2; border-radius: 6px; background: #fff; }
.mobile-bottom-row div { display: grid; grid-template-columns: 34px minmax(0,1fr); gap: 6px; align-items: center; }
.mobile-bottom-row strong { min-width: 0; font-size: 1rem; font-weight: 500; overflow-wrap: anywhere; }
.mobile-memo { grid-column: 1/-1; display: grid; grid-template-columns: 42px 1fr; gap: 6px; min-height: 20px; padding: 5px 6px; border: 1px solid #e5eaf2; border-radius: 6px; background: #fff; }
.mobile-memo strong { font-size: .92rem; font-weight: 500; overflow-wrap: anywhere; }
.mobile-edit-card { background: #fffdf7; }
.mobile-edit-card .row-errors { display: block; margin: 6px 8px; padding: 8px; border: 1px solid #fecdca; border-radius: 6px; background: #fff1f0; color: var(--danger); }
.mobile-edit-card .row-errors span { display: block; }
.mobile-edit-grid { display: grid; gap: 10px; padding: 4px 8px 12px; }
.mobile-edit-grid section { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; padding: 10px; border: 1px solid #e2e8f0; border-radius: 8px; background: #fff; }
.mobile-edit-grid section:last-child { grid-template-columns: minmax(0,2fr) minmax(0,3fr) minmax(0,2fr); }
.mobile-edit-grid section:last-child .mobile-other-full { grid-column: 1/-1; }
.mobile-edit-grid h2 { grid-column: 1/-1; margin: 0; color: #0f172a; font-size: .96rem; }
.mobile-edit-grid label { display: grid; gap: 4px; color: #475467; font-size: .76rem; font-weight: 800; }
.mobile-edit-grid input, .mobile-edit-grid select { min-height: 42px; font-size: 1rem; }
.mobile-edit-card .save-block-reason { margin: 0 8px 8px; }
.mobile-edit-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 8px; background: #fffdf7; }
.is-editing .mobile-summary { display: none; }
.is-editing .mobile-app { padding-bottom: 28px; }
.mobile-summary { position: fixed; right: 14px; bottom: 0; left: 14px; z-index: 15; }
.mobile-summary > .summary-manual-warning { margin-bottom: 6px; background: rgba(255,247,237,.98); font-size: .78rem; }
.mobile-summary-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 6px 10px; padding: 10px 14px; border: 1px solid #d9dee7; border-radius: 6px; background: rgba(255,255,255,.97); box-shadow: 0 -2px 10px rgba(23,32,51,.14); }
.mobile-summary-grid div { display: grid; grid-template-columns: auto 1fr; gap: 6px; align-items: center; }
.mobile-summary-grid span { color: #111827; font-size: .9rem; font-weight: 900; line-height: 1.15; }
.mobile-summary-grid strong { color: #111827; font-size: 1.05rem; text-align: right; white-space: nowrap; }
.mobile-summary-grid div:nth-child(-n+3) strong { font-size: 1.25rem; }
.mobile-review-button { width: 100%; min-height: 50px; border: 0; background: transparent; color: #9ca3af; cursor: pointer; font-size: 1.35rem; font-weight: 900; }
.mobile-review-button:not(:disabled) { color: var(--accent); }

@media (max-width: 430px) {
  .mobile-card-grid { column-gap: 12px; }
  .mobile-line { grid-template-columns: minmax(68px,1fr) 24px minmax(44px,.75fr) 24px minmax(44px,.75fr) 28px minmax(40px,.65fr); gap: 3px; }
  .mobile-line strong, .mobile-bottom-row strong { font-size: .95rem; }
  .mobile-summary-grid { gap: 6px; padding: 9px 10px; }
  .mobile-summary-grid span { font-size: .84rem; }
  .mobile-summary-grid strong { font-size: .98rem; }
}
