* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  background: #fff;
  color: #222;
  font-size: 14px;
}
.hidden { display: none !important; }
.screen { min-height: 100vh; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid #cfd4da;
  background: #fff;
  color: #222;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  font-family: inherit;
}
.btn:hover { background: #f6f7f9; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: #1f4f5b; border-color: #1f4f5b; color: #fff;
}
.btn-primary:hover { background: #163942; }
.btn-secondary {
  background: #6c757d; border-color: #6c757d; color: #fff;
}
.btn-secondary:hover { background: #545b62; }
.btn-dark {
  background: #2c2f33; border-color: #2c2f33; color: #fff;
}
.btn-dark:hover { background: #1c1f23; }
.btn-green {
  background: #1e7a3a; border-color: #1e7a3a; color: #fff;
}
.btn-green:hover { background: #185f2d; }
.btn-light {
  background: #fff; border-color: #cfd4da; color: #222;
}
.btn-danger {
  background: #b3261e; border-color: #b3261e; color: #fff;
}
.btn-danger:hover { background: #911e18; }
.btn-outline-danger {
  background: #fff; border: 1.5px solid #d23a2a; color: #d23a2a; font-weight: 600;
}
.btn-outline-danger:hover { background: #fff3f2; }
.btn-block { width: 100%; justify-content: center; }
.icon-only { padding: 8px 10px; }
.link-btn {
  background: none; border: none; color: #1f4f5b; cursor: pointer;
  padding: 8px 0; font-size: 13px; text-decoration: underline;
  display: block; margin: 8px auto 0;
  font-family: inherit;
}

/* ---------- Icons ---------- */
.icon-dl, .icon-print, .icon-key, .icon-out {
  width: 16px; height: 16px; display: inline-block;
  background-repeat: no-repeat; background-size: contain; background-position: center;
}
.icon-dl { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/><polyline points='7 10 12 15 17 10'/><line x1='12' y1='15' x2='12' y2='3'/></svg>"); }
.icon-print { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23222' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 6 2 18 2 18 9'/><path d='M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2'/><rect x='6' y='14' width='12' height='8'/></svg>"); }
.icon-key { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23222' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4'/></svg>"); }
.icon-out { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4'/><polyline points='16 17 21 12 16 7'/><line x1='21' y1='12' x2='9' y2='12'/></svg>"); }
.icon-gear { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23222' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='12' r='3'/><path d='M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z'/></svg>"); }

/* ---------- Auth ---------- */
#auth-screen {
  display: flex; align-items: center; justify-content: center;
  background: #f4f6f8; padding: 20px;
}
.auth-card {
  background: #fff; border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  padding: 32px; width: 100%; max-width: 380px;
}
.auth-title {
  margin: 0 0 24px; text-align: center; font-size: 24px;
}
.auth-desc {
  font-size: 13px; color: #555; margin: 0 0 16px; line-height: 1.6;
}
.auth-label {
  display: block; font-size: 13px; color: #444;
  margin: 12px 0 6px; font-weight: 500;
}
.auth-input {
  width: 100%; padding: 10px 12px; border: 1px solid #cfd4da;
  border-radius: 8px; font-size: 14px; font-family: inherit;
}
.auth-input:focus { outline: none; border-color: #1f4f5b; box-shadow: 0 0 0 2px rgba(31,79,91,0.15); }
.auth-error {
  color: #b3261e; font-size: 13px; margin: 10px 0; min-height: 16px;
}
.auth-card .btn-block { margin-top: 16px; }
.login-tabs {
  display: flex;
  border-bottom: 1px solid #cfd4da;
  margin-bottom: 18px;
}
.login-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 10px;
  font-size: 14px;
  color: #777;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-family: inherit;
}
.login-tab.active {
  color: #1f4f5b;
  border-bottom-color: #1f4f5b;
  font-weight: 600;
}
.recovery-code {
  background: #f4f6f8; border: 1.5px dashed #888;
  padding: 18px; text-align: center; font-size: 22px;
  font-weight: 700; letter-spacing: 2px; margin: 12px 0;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  user-select: all;
}

/* ---------- App Header ---------- */
.app-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; gap: 16px; flex-wrap: wrap;
}
.header-left, .header-right {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.month-title {
  margin: 0 6px; font-size: 18px; font-weight: 600;
  min-width: 130px; text-align: center;
}

/* ---------- Staff section ---------- */
.staff-section {
  border: 1px solid #e0e3e7; border-radius: 8px;
  padding: 14px 18px; margin: 0 20px 18px;
}
.section-title {
  margin: 0 0 12px; font-size: 14px; font-weight: 500; color: #444;
}
.staff-add-row {
  display: flex; gap: 8px; margin-bottom: 12px;
}
.staff-input {
  flex: 0 0 240px; padding: 8px 12px;
  border: 1px solid #cfd4da; border-radius: 8px; font-size: 14px;
  font-family: inherit;
}
.staff-input:focus { outline: none; border-color: #1f4f5b; }
.staff-chips {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid #cfd4da; border-radius: 22px;
  padding: 5px 12px 5px 6px; background: #fff;
  font-size: 14px; cursor: grab; user-select: none;
}
.chip.dragging { opacity: 0.4; }
.chip-handle {
  color: #999; cursor: grab; font-size: 13px; line-height: 1;
  letter-spacing: -2px;
}
.chip-name { padding: 0 4px; }
.chip-remove {
  width: 18px; height: 18px; border-radius: 50%;
  background: transparent; border: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: #888; font-size: 14px; font-family: inherit;
}
.chip-remove:hover { background: #f0f0f0; color: #222; }

/* ---------- Shift table ---------- */
#shift-tables { padding: 0 20px 30px; }
.week-table {
  width: 100%; border-collapse: collapse;
  margin-bottom: 14px; table-layout: fixed;
}
.week-table th, .week-table td {
  border: 1px solid #d8dbe0; padding: 6px 4px;
  text-align: center; vertical-align: middle;
  font-size: 13px; height: 34px;
}
.week-table th { font-weight: 600; }
.col-no { width: 36px; }
.col-name { width: 80px; }
.col-time { width: auto; }
.col-total { width: 70px; }
.total-header { background: #eeeeee; font-weight: 600; }
.total-cell { font-weight: 700; background: #fafafa; }

.week-publish-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fffaf0;
  border: 1px solid #f0dcb0;
  border-radius: 6px;
  padding: 6px 12px;
  margin: 14px 0 4px;
  font-size: 12.5px;
}
.week-publish-bar.published {
  background: #e8f7ee;
  border-color: #cfe9d8;
}
.week-pub-label { color: #555; }
.week-publish-bar.published .week-pub-label { color: #1e7a3a; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.dow-header { font-weight: 600; }
.dow-mon, .dow-wed, .dow-fri, .dow-sun { background: #fff200; }
.dow-sat { background: #cfe2f3; }
.date-cell { font-weight: 700; }
.date-sat { color: #1f4e78; }
.date-sun { color: #c00; }
.staff-no { color: #999; font-weight: 600; }
.name-cell { text-align: left; padding-left: 10px; font-weight: 500; }
.shift-cell {
  cursor: pointer; padding: 0;
}
.shift-cell:hover { background: #f5f8fa; }
.shift-cell-inner {
  display: grid; grid-template-columns: 1fr 1fr;
  height: 100%; min-height: 28px;
}
.shift-time {
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12.5px; padding: 4px 2px;
}
.shift-time:first-child {
  border-right: 1px solid #d8dbe0;
}
.shift-time.last { color: #c00; }
.no-day { background: #f7f7f7; cursor: default; }
.no-day:hover { background: #f7f7f7; }
.shift-cell.other-month { background: #fafafa; }
.shift-cell.other-month .shift-time { color: #888; }
.date-cell.other-month { color: #aaa; font-weight: 400; }

/* Monthly summary table */
.summary-section {
  margin: 30px 0 20px;
}
.summary-title {
  font-size: 15px; font-weight: 600; margin: 0 0 10px;
}
.summary-table {
  width: 100%; border-collapse: collapse;
  max-width: 520px;
}
.summary-table th, .summary-table td {
  border: 1px solid #d8dbe0; padding: 8px 12px;
  text-align: center; font-size: 13px;
}
.summary-table th {
  background: #eeeeee; font-weight: 600;
}
.summary-table .sum-name {
  text-align: left; font-weight: 500;
}
.summary-table .sum-total {
  font-weight: 700;
}
.hint-text {
  font-size: 12px; color: #666; margin: 4px 0 8px;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.modal-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,0.4);
}
.modal-content {
  position: relative; background: #fff; border-radius: 12px;
  padding: 22px 22px 18px; width: 92%; max-width: 380px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal-title {
  margin: 0 0 12px; text-align: center; font-size: 16px; font-weight: 600;
}
.modal-content hr {
  border: none; border-top: 1px solid #e0e3e7; margin: 0 0 16px;
}
.time-row {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; margin-bottom: 14px;
}
.time-col label {
  display: block; font-size: 13px; color: #555; margin-bottom: 6px;
}
.time-col input[type=time] {
  width: 100%; padding: 10px; border: 1px solid #cfd4da;
  border-radius: 8px; font-size: 15px; text-align: center;
  font-family: inherit;
}
.modal-buttons {
  display: flex; gap: 8px; margin-top: 14px; justify-content: center;
}
.modal-buttons .btn { flex: 1; justify-content: center; }
#last-toggle.active {
  background: #1f4f5b; color: #fff; border-color: #1f4f5b;
}
#sr-last-toggle.active {
  background: #1f4f5b; color: #fff; border-color: #1f4f5b;
}
.request-hint-row {
  background: #fff8ec;
  border: 1px solid #f0dcb0;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.request-hint-text {
  font-size: 13px;
  color: #555;
}
.request-hint-text .hint-strong {
  font-weight: 700;
  color: #1f4f5b;
}
.request-hint-text.ng .hint-strong {
  color: #b3261e;
}

.template-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  background: #f4f6f8;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 12px;
}
.template-chips .tpl-label {
  font-size: 12px;
  color: #666;
  margin-right: 4px;
}
.template-chips .tpl-chip {
  border: 1px solid #4a86b3;
  background: #fff;
  color: #1f4e78;
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.template-chips .tpl-chip:hover { background: #e8f0f9; }

.shift-cell.dragging { opacity: 0.4; }
.shift-cell.drag-over { background: #fff3d0; outline: 2px dashed #c97b00; outline-offset: -2px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 18px;
  border-radius: 6px; z-index: 2000; font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* ---------- Print ---------- */
.print-only { display: none; }

@media print {
  *, *::before, *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  .no-print { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; }
  .staff-section { display: none; }
  #shift-tables { padding: 0; }
  .week-publish-bar { display: none; }
  .week-table {
    page-break-inside: avoid;
    margin-bottom: 14px;
  }
  .week-table th, .week-table td {
    font-size: 11px; padding: 3px 2px; height: auto;
  }
  .print-title-only {
    text-align: center; margin: 0 0 14px;
  }
  .print-title-only h1 {
    margin: 8px 0; font-size: 16px; font-weight: 600;
  }
  .summary-section {
    page-break-inside: avoid;
    margin-top: 20px;
  }
  .summary-table th, .summary-table td {
    font-size: 11px; padding: 4px 8px;
  }
  /* @page rule injected dynamically by app.js for portrait/landscape */
}
