:root{
  --day-w:36px;
  --row-h:64px;
  --name-w:84px;
  --grid-border:#222;
  --weekend:#d9d9d9;
  --days:31;
  --rows:3;
  --name-font:22px;
  --surface:#fff;
  --soft:#f5f5f5;
  --line:#ddd;
  --ink:#111;
  --muted:#5d6670;
  --accent:#111;
}
*{ box-sizing:border-box; }
html{ color-scheme:light; }
body{
  margin:0;
  font-family:Arial, "Noto Sans", "Noto Sans JP", "Noto Sans SC", Helvetica, sans-serif;
  background:var(--soft);
  color:var(--ink);
}
button,input,select,textarea{ font:inherit; }
button{ cursor:pointer; }
button:disabled{ cursor:not-allowed; opacity:.55; }
[hidden]{ display:none !important; }
.app{ max-width:1380px; margin:0 auto; padding:18px; }
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:18px;
  margin-bottom:14px;
  padding:12px 14px;
  border:1px solid var(--line);
  border-radius:14px;
  background:var(--surface);
  box-shadow:0 2px 10px rgba(0,0,0,.05);
}
.brand-block{ display:flex; flex-direction:column; gap:2px; min-width:max-content; }
.brand-name{ font-size:18px; letter-spacing:.02em; }
.brand-subtitle{ color:var(--muted); font-size:12px; }
.topbar-actions{ display:flex; align-items:center; justify-content:flex-end; gap:12px; flex-wrap:wrap; }
.language-switch{ display:inline-flex; padding:3px; border:1px solid #c8cdd3; border-radius:10px; background:#f1f3f5; }
.language-button{
  padding:6px 9px;
  border:0;
  border-radius:7px;
  background:transparent;
  color:#333;
  font-size:12px;
  font-weight:800;
}
.language-button.active{ background:#111; color:#fff; box-shadow:0 1px 4px rgba(0,0,0,.18); }
.auth-area{ display:flex; align-items:center; gap:7px; min-height:34px; }
.sync-status{ color:var(--muted); font-size:11px; font-weight:800; white-space:nowrap; }
.user-button-slot{ min-width:32px; min-height:32px; }
.panel{
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:14px;
  padding:14px;
  margin-bottom:14px;
  box-shadow:0 2px 10px rgba(0,0,0,.06);
}
h1,h2,h3{ margin-top:0; }
h1.settings-title{ margin:0 0 12px; font-size:19px; }
h2{ margin:0 0 10px; font-size:18px; }
h3{ margin:0 0 6px; font-size:14px; }
label{ display:flex; flex-direction:column; gap:4px; font-size:12px; font-weight:700; }
input,select,textarea,button,.file-button{
  padding:8px 10px;
  border:1px solid #bbb;
  border-radius:8px;
  background:#fff;
}
textarea{ min-height:58px; resize:vertical; white-space:pre-wrap; }
input[type="color"]{ min-height:38px; padding:3px; }
button,.file-button{ font-weight:800; background:#111; color:#fff; border-color:#111; text-align:center; }
button.secondary{ background:#fff; color:#111; }
button.danger{ background:#b42318; border-color:#b42318; }
.compact-button{ padding:6px 9px; font-size:12px; }
.small-btn{ padding:5px 8px; border-radius:7px; font-size:12px; }
.note{ margin:0; font-size:12px; color:#555; line-height:1.5; }
.form-error{ margin:0; color:#b42318; font-size:12px; font-weight:700; }

.calendar-card{ overflow:auto; background:#fff; }
.sheet{ min-width:1120px; width:max-content; min-height:200px; background:#fff; padding:10px 10px 0 0; }
.calendar-title{ text-align:center; font-size:40px; font-weight:900; font-style:italic; margin-bottom:18px; }
.grid-wrap{
  position:relative;
  width:calc(var(--name-w) + var(--day-w) * var(--days) + 2px);
  margin:0 auto;
  padding-bottom:22px;
}
.month-band{
  display:grid;
  grid-template-columns:var(--name-w) repeat(var(--days), var(--day-w));
  height:28px;
  align-items:center;
  text-align:center;
  font-weight:800;
}
.corner{ height:28px; border-bottom:1px solid var(--grid-border); }
.month-label{ border:1px solid var(--grid-border); border-left:0; height:28px; line-height:28px; background:#fff; overflow:hidden; white-space:nowrap; }
.month-label.first-day{ border-left:1px solid var(--grid-border); }
.day-grid{ display:grid; grid-template-columns:var(--name-w) repeat(var(--days), var(--day-w)); }
.name-cell,.date-cell,.dow-cell,.body-cell{
  border-right:1px solid var(--grid-border);
  border-bottom:1px solid var(--grid-border);
  display:flex;
  align-items:center;
  justify-content:center;
}
.first-day{ border-left:1px solid var(--grid-border); }
.date-cell,.dow-cell{ height:32px; font-weight:800; }
.dow-cell{ font-size:13px; }
.dow-cell.sun{ color:red; }
.dow-cell.sat{ color:#0070c0; }
.body-cell{ height:var(--row-h); }
.name-cell{
  height:var(--row-h);
  border-right:0;
  font-size:var(--name-font);
  font-weight:800;
  padding:2px 4px;
  white-space:pre-line;
  line-height:1.05;
  overflow:hidden;
  text-align:center;
  word-break:keep-all;
}
.weekend-bg{ background:var(--weekend); }
.arrow-layer{
  position:absolute;
  left:var(--name-w);
  top:84px;
  width:calc(var(--day-w) * var(--days));
  height:calc(var(--row-h) * var(--rows));
  pointer-events:auto;
  overflow:visible;
  touch-action:none;
}
.shift-arrow{ cursor:grab; }
.shift-arrow.dragging{ cursor:grabbing; opacity:.82; }
.resize-handle{ cursor:ew-resize; opacity:.92; }
.resize-handle:hover{ opacity:1; }
.palette{
  display:flex;
  justify-content:center;
  gap:22px;
  margin:18px auto 10px;
  font-size:21px;
  font-weight:800;
  align-items:center;
  flex-wrap:wrap;
  max-width:calc(var(--name-w) + var(--day-w) * var(--days));
}
.palette-item{ display:flex; align-items:center; gap:8px; white-space:nowrap; }
.legend-arrow{ width:58px; height:30px; cursor:grab; user-select:none; touch-action:none; overflow:visible; }
.legend-arrow:active{ cursor:grabbing; }
.legend-arrow svg{ display:block; width:58px; height:30px; overflow:visible; }
.calendar-note-box{
  width:calc(var(--name-w) + var(--day-w) * var(--days) + 2px);
  max-width:100%;
  margin:4px auto 16px;
  display:grid;
  grid-template-columns:var(--name-w) 1fr;
  align-items:start;
  border:0;
  background:transparent;
  padding:0;
  font-size:15px;
  line-height:1.55;
  white-space:pre-wrap;
}
.calendar-note-title{ grid-column:2; font-weight:900; margin:0 0 .25em 0; padding:0; align-self:start; }
.calendar-note-text{ grid-column:2; margin:0; padding-left:2.2em; text-align:left; white-space:pre-wrap; min-height:24px; }

.settings-grid{
  display:grid;
  grid-template-columns:minmax(290px,1fr) minmax(300px,1.05fr) minmax(350px,1.25fr) minmax(270px,.9fr);
  gap:12px;
  align-items:start;
}
.tool-box{ border:1px solid #e0e0e0; border-radius:10px; padding:10px; background:#fafafa; min-width:0; overflow:hidden; }
.control-grid{ display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; align-items:end; }
.control-grid .wide{ grid-column:1 / -1; }
.control-grid input,.control-grid select,.control-grid textarea{ width:100%; min-width:0; }
.nested-grid{ display:grid; margin:0; }
.period-fieldset{ margin:0; padding:0; border:0; min-width:0; }
.period-fieldset legend{ margin-bottom:5px; font-size:12px; font-weight:700; }
.period-mode-switch{ display:grid; grid-template-columns:1fr 1fr; gap:6px; }
.period-option{ position:relative; display:block; }
.period-option input{ position:absolute; opacity:0; pointer-events:none; }
.period-option span{ display:block; padding:8px 9px; border:1px solid #bbb; border-radius:8px; background:#fff; text-align:center; cursor:pointer; }
.period-option input:checked + span{ border-color:#111; background:#111; color:#fff; }
.entry-list,.shift-list{ max-height:260px; overflow:auto; margin-top:10px; }
.entry,.shift-editor{ border:1px solid #ddd; border-radius:10px; padding:9px; margin-bottom:8px; background:#fff; }
.entry strong{ display:block; margin-bottom:4px; white-space:pre-line; }
.entry-actions{ display:flex; gap:6px; margin-top:8px; flex-wrap:wrap; }
.shift-editor{ display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; align-items:end; }
.shift-editor .entry-actions{ grid-column:1 / -1; }
.print-actions{ display:flex; gap:8px; flex-wrap:wrap; margin:12px 0; }
.backup-box{ margin:12px 0; padding:10px; border:1px solid #cfd4da; border-radius:10px; background:#fff; }
.backup-actions{ display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:8px; }
.file-button{ display:block; cursor:pointer; }
.backup-status{ min-height:1.2em; margin:7px 0 0; color:var(--muted); font-size:11px; font-weight:700; }
.reset-button{ width:100%; margin-top:4px; }
.drag-ghost{ position:fixed; z-index:9999; pointer-events:none; opacity:.82; transform:translate(-50%,-50%); }
.context-menu{ position:fixed; z-index:10000; min-width:118px; background:#fff; border:1px solid #aaa; border-radius:8px; box-shadow:0 6px 20px rgba(0,0,0,.18); padding:6px; }
.context-menu.hidden{ display:none; }
.context-menu button{ display:block; width:100%; margin:0; padding:7px 9px; border-radius:6px; text-align:left; background:#fff; color:#111; border:0; }
.context-menu button:hover{ background:#eef2f7; }
.visually-hidden{ position:absolute !important; width:1px !important; height:1px !important; padding:0 !important; margin:-1px !important; overflow:hidden !important; clip:rect(0,0,0,0) !important; white-space:nowrap !important; border:0 !important; }

.modal{ position:fixed; inset:0; z-index:20000; display:flex; align-items:center; justify-content:center; padding:18px; background:rgba(15,20,26,.62); }
.modal.hidden{ display:none; }
.modal-card{ width:min(440px,100%); max-height:calc(100vh - 36px); overflow:auto; padding:14px; border-radius:14px; background:#fff; box-shadow:0 18px 60px rgba(0,0,0,.3); }
.modal-header{ display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:8px; }
.modal-header h2{ margin:0; }
.modal-close{ width:36px; height:36px; padding:0; font-size:20px; line-height:1; }

@media (max-width:1120px){
  .settings-grid{ grid-template-columns:1fr 1fr; }
  .topbar{ align-items:flex-start; }
}
@media (max-width:760px){
  .app{ padding:10px; }
  .settings-grid{ grid-template-columns:1fr; }
  .topbar{ flex-direction:column; }
  .topbar-actions{ width:100%; justify-content:space-between; }
  .auth-area{ flex-wrap:wrap; }
}
@media (max-width:480px){
  .topbar-actions{ align-items:flex-start; flex-direction:column; }
  .language-switch{ width:100%; }
  .language-button{ flex:1; }
  .auth-area{ width:100%; }
}
@media print{
  body{ background:#fff; }
  .no-print{ display:none !important; }
  .app{ max-width:none; padding:0; }
  .panel{ border:0; box-shadow:none; padding:0; margin:0; }
  .calendar-card{ overflow:visible; }
  .sheet{ min-width:0; width:max-content; padding-right:8px !important; }
  .resize-handle{ display:none !important; }
  .shift-arrow{ cursor:default !important; }
  .weekend-bg{ background:var(--weekend) !important; -webkit-print-color-adjust:exact; print-color-adjust:exact; }
  .month-label{ border:1px solid var(--grid-border) !important; -webkit-print-color-adjust:exact; print-color-adjust:exact; }
  @page{ size:A4 landscape; margin:8mm; }
}
