:root {
  --navy: #1f3a5f;
  --navy-2: #2d5487;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1d2430;
  --muted: #667085;
  --line: #dde3ea;
  --ng: #b42318;
  --ng-bg: #fdecea;
  /* 期限の色分け（左の太線＝濃い色、行の地＝薄い色） */
  --overdue: #c62828;   --overdue-bg: #fde8e8;
  --alert: #e06c00;     --alert-bg: #fff0e0;
  --warn: #c9a400;      --warn-bg: #fffbe0;
  --done: #98a2b3;      --done-bg: #f2f4f7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 24px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { height: 30px; width: auto; }
.app-name { font-weight: 700; color: var(--navy); font-size: 17px; white-space: nowrap; }
.user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); min-width: 0; }
.user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 64px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px;
}
.card.center { text-align: center; padding: 56px 24px; max-width: 560px; margin: 40px auto; }
h1 { font-size: 24px; margin: 0 0 12px; color: var(--navy); }
h2 { font-size: 17px; margin: 0; color: var(--navy); }
.lead { font-size: 16px; margin: 0 0 28px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }

.btn {
  font: inherit; border-radius: 8px; border: 1px solid transparent; cursor: pointer;
  padding: 8px 16px; font-weight: 600; transition: background .15s, border-color .15s; white-space: nowrap;
}
.btn.primary { background: var(--navy); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--navy-2); }
.btn.primary:disabled { background: #a9b6c7; cursor: not-allowed; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--text); }
.btn.ghost:hover { border-color: var(--navy); color: var(--navy); }
.btn.danger { background: #fff; border-color: #f1c0bb; color: var(--ng); }
.btn.danger:hover { background: var(--ng-bg); }
.btn.large { padding: 12px 28px; font-size: 16px; }
.btn.small { padding: 4px 10px; font-size: 13px; }

input, select, textarea {
  font: inherit; font-size: 14px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b9cbe3; border-color: var(--navy); }
input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--navy); cursor: pointer; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; white-space: nowrap; }

/* ── 期限の状況 ── */
.summary { display: flex; flex-wrap: wrap; gap: 10px; align-items: stretch; margin-bottom: 16px; }
.chip {
  font: inherit; display: flex; align-items: baseline; gap: 8px; padding: 10px 16px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line); border-left-width: 6px; box-shadow: var(--shadow); color: var(--text);
}
button.chip { cursor: pointer; }
button.chip:hover { border-color: var(--navy); }
.chip.on { outline: 2px solid var(--navy); outline-offset: 1px; }
.chip-n { font-size: 24px; font-weight: 700; line-height: 1; }
.chip-l { font-size: 13px; font-weight: 600; }
.chip.overdue { border-left-color: var(--overdue); } .chip.overdue:not(.zero) { background: var(--overdue-bg); color: var(--overdue); }
.chip.alert { border-left-color: var(--alert); }     .chip.alert:not(.zero) { background: var(--alert-bg); color: #a14e00; }
.chip.warn { border-left-color: var(--warn); }       .chip.warn:not(.zero) { background: var(--warn-bg); color: #7a6300; }
.chip.info { border-left-color: var(--navy); }
.chip.zero .chip-n { color: var(--muted); }
.today { margin-left: auto; align-self: center; font-size: 13px; color: var(--muted); }

/* ── 一覧 ── */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.toolbar input[type="search"] { width: 240px; }
.toolbar select { width: auto; max-width: 220px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--muted); margin: 12px 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border-left: 4px solid; }
.sw.overdue { background: var(--overdue-bg); border-color: var(--overdue); }
.sw.alert { background: var(--alert-bg); border-color: var(--alert); }
.sw.warn { background: var(--warn-bg); border-color: var(--warn); }
.sw.done { background: var(--done-bg); border-color: var(--done); }

.table-wrap { overflow-x: auto; }
table.items { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.items th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 8px 10px;
  border-bottom: 2px solid var(--line); white-space: nowrap; user-select: none;
}
.items th[data-sort] { cursor: pointer; }
.items th[data-sort]:hover, .items th[data-sort]:focus { color: var(--navy); outline: none; }
.items th.sorted { color: var(--navy); }
.items th[data-sort]::after { content: attr(data-arrow); margin-left: 4px; font-size: 10px; }
.items td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.items tbody tr { transition: background .15s; }
.items tbody tr:hover { filter: brightness(.98); }
.items td:first-child { border-left: 6px solid transparent; }
.items tr.u-overdue td { background: var(--overdue-bg); }
.items tr.u-overdue td:first-child { border-left-color: var(--overdue); }
.items tr.u-alert td { background: var(--alert-bg); }
.items tr.u-alert td:first-child { border-left-color: var(--alert); }
.items tr.u-warn td { background: var(--warn-bg); }
.items tr.u-warn td:first-child { border-left-color: var(--warn); }
.items tr.u-done td { background: var(--done-bg); color: var(--muted); }
.items tr.u-done td:first-child { border-left-color: var(--done); }
.items tr.u-done .content { text-decoration: line-through; }
.c-done { width: 52px; text-align: center; }
.c-done input { margin-top: 2px; }
.c-pri { width: 64px; }
.c-due { width: 150px; white-space: nowrap; }
.c-company { width: 18%; }
.c-assignee { width: 100px; }
.c-entry { width: 130px; white-space: nowrap; color: var(--muted); }
.c-act { width: 64px; text-align: right; }
.content { white-space: pre-wrap; word-break: break-word; }
.note { white-space: pre-wrap; word-break: break-word; font-size: 12px; color: var(--muted); margin-top: 4px; }
.due-date { display: block; }
.remain { display: inline-block; font-size: 12px; font-weight: 700; padding: 0 8px; border-radius: 10px; margin-top: 2px; background: #eef2f6; color: var(--muted); }
.remain.overdue { background: var(--overdue); color: #fff; }
.remain.alert { background: var(--alert); color: #fff; }
.remain.warn { background: var(--warn); color: #3d3200; }
.pri { display: inline-block; min-width: 28px; text-align: center; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 10px; }
.pri.high { background: #7a1f1f; color: #fff; }
.pri.medium { background: #dbe4ef; color: var(--navy); }
.pri.low { background: #eef0f3; color: var(--muted); }
.empty { text-align: center; padding: 32px 0; }
#countLine { margin: 10px 0 0; }

/* ── ダイアログ ── */
dialog { border: none; border-radius: var(--radius); padding: 0; width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(16, 24, 40, .45); }
.dlg { padding: 20px 24px 24px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
.span2 { grid-column: span 2; }
.span3 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; }
.field label em { font-style: normal; font-size: 11px; color: var(--ng); margin-left: 4px; }
.form-err { color: var(--ng); background: var(--ng-bg); padding: 8px 12px; border-radius: 6px; font-size: 14px; margin: 12px 0 0; }
.actions { display: flex; align-items: center; gap: 10px; margin-top: 18px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200;
  background: #1d2430; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px;
  max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.toast.error { background: var(--ng); }

/* ── 携帯：表をカードにする ── */
@media (max-width: 760px) {
  .topbar { padding: 8px 16px; }
  .app-name { font-size: 15px; }
  #userEmail { display: none; }
  .card { padding: 16px; }
  .toolbar input[type="search"], .toolbar select { width: 100%; max-width: none; }
  .toolbar .spacer { display: none; }
  .today { width: 100%; margin-left: 0; }
  .chip { flex: 1 1 40%; }
  .items thead { display: none; }
  .items, .items tbody, .items tr, .items td { display: block; width: auto; }
  .items tr {
    display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 2px 8px;
    border: 1px solid var(--line); border-left: 6px solid transparent; border-radius: 10px; margin-bottom: 10px; padding: 10px 10px 10px 4px;
  }
  .items td, .items td:first-child { border: none; padding: 0; background: transparent !important; }
  .items tr.u-overdue { background: var(--overdue-bg); border-left-color: var(--overdue); }
  .items tr.u-alert { background: var(--alert-bg); border-left-color: var(--alert); }
  .items tr.u-warn { background: var(--warn-bg); border-left-color: var(--warn); }
  .items tr.u-done { background: var(--done-bg); border-left-color: var(--done); }
  .c-done { grid-row: 1 / span 4; }
  .c-pri { grid-column: 2; grid-row: 1; }
  .c-act { grid-column: 3; grid-row: 1; }
  .c-due, .c-company, .c-content, .c-assignee, .c-entry { grid-column: 2 / -1; }
  .c-due .due-date { display: inline; margin-right: 6px; }
  .c-company { font-weight: 700; }
  .c-assignee::before, .c-entry::before { content: attr(data-label) "："; color: var(--muted); font-size: 12px; }
  .c-assignee, .c-entry { font-size: 13px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .span2, .span3 { grid-column: auto; }
  .dlg { padding: 16px; }
}
