:root {
  --ink: #19233a;
  --muted: #667085;
  --line: #dce3ec;
  --surface: #ffffff;
  --canvas: #f3f6f9;
  --navy: #12203a;
  --blue: #165dff;
  --blue-dark: #0c46cb;
  --green: #087a58;
  --red: #b42318;
  --amber: #9a6700;
  --shadow: 0 14px 40px rgba(18, 32, 58, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 4vw;
  color: #fff;
  background: rgba(18, 32, 58, 0.98);
  box-shadow: 0 4px 18px rgba(18, 32, 58, 0.18);
}
.brand { font-weight: 800; text-decoration: none; letter-spacing: .02em; }
.nav { display: flex; align-items: center; gap: 20px; font-size: 14px; }
.nav a, .nav-link { color: #dce7f7; text-decoration: none; background: none; border: 0; padding: 8px 0; cursor: pointer; }
.nav a:hover, .nav-link:hover { color: #fff; }
.nav-user { padding-left: 18px; border-left: 1px solid rgba(255,255,255,.22); color: #fff; font-weight: 700; }
.inline-form { margin: 0; }
.menu-button { display: none; border: 0; color: #fff; background: transparent; font-size: 25px; cursor: pointer; }

.container { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 40px 0 64px; }
.page-heading, .viewer-title-row { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.heading-actions { display: flex; gap: 10px; }
.page-heading h1, .viewer-heading h1 { margin: 4px 0 6px; font-size: clamp(28px, 4vw, 44px); line-height: 1.15; letter-spacing: -.035em; }
.page-heading p, .viewer-heading p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .15em; }
.muted { color: var(--muted); }

.button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid #bac6d6;
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
  transition: .16s ease;
}
.button:hover { border-color: #8fa0b7; transform: translateY(-1px); }
.button-primary { color: #fff; border-color: var(--blue); background: var(--blue); box-shadow: 0 8px 18px rgba(22, 93, 255, .2); }
.button-primary:hover { border-color: var(--blue-dark); background: var(--blue-dark); }
.button-danger { color: #fff; border-color: var(--red); background: var(--red); }
.button-ghost { background: transparent; }
.button-full { width: 100%; }

label { display: grid; gap: 7px; color: #344054; font-size: 13px; font-weight: 750; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #c8d2df;
  border-radius: 9px;
  color: var(--ink);
  background: #fff;
  outline: none;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(22,93,255,.12); }
small { color: var(--muted); }
.file-message { min-height: 20px; font-size: 13px; font-weight: 750; }
.file-message.is-error { color: var(--red); }
.file-message.is-success { color: var(--green); }
.readonly-field { display: grid; gap: 7px; padding: 13px; border: 1px solid var(--line); border-radius: 9px; background: #f7f9fc; }
.readonly-field span { color: #344054; font-size: 13px; font-weight: 750; }

.filter-panel {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr auto auto;
  align-items: end;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.result-summary { margin: 24px 0 12px; color: var(--muted); font-size: 14px; }
.result-summary strong { color: var(--ink); font-size: 20px; }
.breadcrumbs { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; color: var(--muted); font-size: 13px; overflow-x: auto; white-space: nowrap; }
.breadcrumbs a { color: var(--blue); text-decoration: none; font-weight: 700; }
.folder-section { margin: 24px 0; }
.folder-section > h2, .folder-admin-list > h2 { margin: 0 0 12px; font-size: 17px; }
.folder-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.folder-card { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 13px; min-height: 76px; padding: 15px 17px; border: 1px solid var(--line); border-radius: 13px; background: #fff; box-shadow: 0 5px 16px rgba(18,32,58,.04); text-decoration: none; }
.folder-card:hover { border-color: #9eb2ce; box-shadow: 0 8px 22px rgba(18,32,58,.08); }
.folder-icon { color: #e7a825; font-size: 25px; line-height: 1; transform: rotate(180deg); }
.folder-info, .folder-path > div { display: grid; gap: 4px; min-width: 0; }
.folder-info strong, .folder-path strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-info small, .folder-path small { color: var(--muted); font-size: 12px; }
.folder-arrow { color: #98a2b3; font-size: 24px; }
.document-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.document-card { padding: 20px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); box-shadow: 0 6px 20px rgba(18,32,58,.045); }
.document-card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.document-card time { color: var(--muted); font-size: 13px; }
.document-card h2 { min-height: 2.7em; margin: 16px 0; font-size: 19px; line-height: 1.35; }
.document-card dl { margin: 0 0 18px; }
.document-card dl div { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid #edf0f4; font-size: 13px; }
.document-card dt { color: var(--muted); }
.document-card dd { margin: 0; font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.badge { display: inline-flex; align-items: center; min-height: 26px; padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.badge-estimate { color: #175cd3; background: #eaf2ff; }
.badge-invoice { color: #087a58; background: #e7f8f1; }
.badge-master { color: #6941c6; background: #f1ebff; }

.alert { margin: 0 0 18px; padding: 13px 15px; border-radius: 10px; font-weight: 700; }
.alert-error { color: #8f1d16; border: 1px solid #f0b6b2; background: #fff0ef; }
.alert-success { color: #05603a; border: 1px solid #a6e3cb; background: #edfcf5; }
.alert-warning { color: #684f00; border: 1px solid #e7ca6c; background: #fff8dd; }
.empty-state { padding: 64px 24px; border: 1px dashed #bac6d6; border-radius: 16px; text-align: center; color: var(--muted); background: rgba(255,255,255,.5); }
.empty-state h2 { color: var(--ink); }

.auth-shell { min-height: calc(100vh - 110px); display: grid; place-items: center; padding: 20px 0; }
.auth-card { width: min(440px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 20px; background: #fff; box-shadow: 0 24px 70px rgba(18,32,58,.12); }
.auth-card h1 { margin: 5px 0 10px; font-size: 28px; }
.brand-mark { width: 54px; height: 54px; display: grid; place-items: center; margin-bottom: 22px; border-radius: 15px; color: #fff; background: var(--navy); font-size: 24px; font-weight: 900; }
.stack-form { display: grid; gap: 16px; margin-top: 24px; }
.security-note { margin: 22px 0 0; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; text-align: center; }
.setup-card { width: min(600px, 100%); }
.setup-steps { display: grid; gap: 18px; padding-left: 22px; line-height: 1.7; }

.form-card { padding: 24px; border: 1px solid var(--line); border-radius: 16px; background: #fff; box-shadow: var(--shadow); }
.password-form { width: min(520px, 100%); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.danger-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 24px; padding: 22px; border: 1px solid #efb4af; border-radius: 14px; background: #fff5f4; }
.danger-card h2 { margin: 0 0 4px; font-size: 17px; }
.danger-card p { margin: 0; color: var(--muted); font-size: 13px; }

.back-link { display: inline-block; margin-bottom: 22px; color: var(--blue); font-weight: 750; text-decoration: none; }
.viewer-actions { display: flex; gap: 10px; }
.viewer-warning { margin-bottom: 14px; padding: 11px 14px; border-radius: 9px; color: #684f00; background: #fff5cf; font-size: 13px; font-weight: 800; text-align: center; }
.pdf-viewer { min-height: 420px; padding: 22px; border-radius: 16px; background: #2a3240; box-shadow: var(--shadow); overflow: hidden; user-select: none; -webkit-user-select: none; }
.viewer-loading { padding: 80px 20px; color: #fff; text-align: center; }
.pdf-page { position: relative; width: fit-content; max-width: 100%; margin: 0 auto 22px; background: #fff; box-shadow: 0 8px 26px rgba(0,0,0,.24); overflow: hidden; }
.pdf-page canvas { display: block; max-width: 100%; height: auto; pointer-events: none; }
.watermark-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.watermark-text { position: absolute; left: 50%; width: 90%; color: rgba(155, 23, 23, .18); font-size: clamp(11px, 2.2vw, 18px); font-weight: 900; letter-spacing: .04em; text-align: center; transform: translateX(-50%) rotate(-27deg); white-space: nowrap; }
.viewer-error { padding: 50px 20px; color: #fff; text-align: center; }

.create-user { margin-bottom: 18px; }
.create-user summary { cursor: pointer; font-weight: 800; }
.compact-form { margin-top: 20px; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; }
.form-submit-cell { display: flex; align-items: end; }
.user-list { display: grid; gap: 12px; }
.user-card { display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; align-items: center; gap: 18px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.user-card.is-inactive { opacity: .62; background: #f3f4f6; }
.user-identity { display: flex; align-items: center; gap: 13px; }
.avatar { flex: 0 0 auto; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--navy); font-weight: 900; }
.user-identity h2 { margin: 0 0 4px; font-size: 17px; }
.user-identity p { margin: 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.user-controls { display: grid; grid-template-columns: 1fr 1.3fr auto auto; align-items: end; gap: 10px; }
.switch-label { display: flex; align-items: center; min-height: 44px; white-space: nowrap; }
.switch-label input { width: 18px; min-height: auto; }
.role-fixed { display: flex; align-items: center; justify-content: flex-end; gap: 14px; }

.folder-admin-tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 28px; }
.folder-admin-tools h2 { margin: 0; font-size: 19px; }
.folder-admin-tools p { color: var(--muted); }
.year-folder-card { background: #fffcf3; }
.folder-admin-list { display: grid; gap: 12px; }
.folder-admin-list > h2 { margin-bottom: 0; }
.folder-admin-row { display: grid; grid-template-columns: minmax(240px, 1fr) 2fr; align-items: end; gap: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 13px; background: #fff; }
.folder-path { display: flex; align-items: center; gap: 12px; min-width: 0; }
.folder-edit-form { display: grid; grid-template-columns: 1fr 1.4fr auto; align-items: end; gap: 10px; }

.history-filter { grid-template-columns: 1fr 1fr 1.3fr 2fr auto; }
.history-list { border: 1px solid var(--line); border-radius: 14px; background: #fff; overflow: hidden; }
.history-row { display: grid; grid-template-columns: 190px 1fr 2fr 1fr; align-items: center; gap: 16px; padding: 15px 18px; border-bottom: 1px solid #edf0f4; }
.history-row:last-child { border-bottom: 0; }
.history-row time { font-size: 13px; font-weight: 800; }
.history-person, .history-document, .history-device { display: grid; gap: 3px; min-width: 0; }
.history-person span, .history-document span, .history-device span, .history-device small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.history-document { grid-template-columns: auto 1fr; align-items: center; }
.history-document .badge { grid-row: span 2; width: max-content; }

@media (max-width: 920px) {
  .filter-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-panel .search-wide { grid-column: span 2; }
  .document-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .folder-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .folder-admin-row { grid-template-columns: 1fr; }
  .user-card { grid-template-columns: 1fr; }
  .user-controls { grid-template-columns: 1fr 1fr auto auto; }
  .history-row { grid-template-columns: 160px 1fr 2fr; }
  .history-device { grid-column: 2 / -1; display: flex; gap: 10px; }
  .history-filter { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .topbar { min-height: 58px; padding: 0 16px; }
  .menu-button { display: block; }
  .nav { display: none; position: absolute; inset: 58px 10px auto; flex-direction: column; align-items: stretch; gap: 0; padding: 10px; border-radius: 12px; background: var(--navy); box-shadow: var(--shadow); }
  .nav.is-open { display: flex; }
  .nav a, .nav-link, .nav-user { width: 100%; padding: 12px; border: 0; text-align: left; }
  .container { width: min(100% - 22px, 1180px); padding: 24px 0 50px; }
  .page-heading, .viewer-title-row { align-items: stretch; flex-direction: column; }
  .page-heading > .button, .viewer-title-row > .button { width: 100%; }
  .heading-actions { width: 100%; flex-direction: column; }
  .heading-actions .button { width: 100%; }
  .viewer-actions { width: 100%; flex-direction: column; }
  .viewer-actions .button { width: 100%; }
  .filter-panel { grid-template-columns: 1fr; padding: 14px; }
  .filter-panel .search-wide { grid-column: auto; }
  .document-grid { grid-template-columns: 1fr; }
  .folder-grid, .folder-admin-tools { grid-template-columns: 1fr; }
  .document-card h2 { min-height: auto; }
  .form-card { padding: 17px; }
  .form-grid, .compact-form { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .button { width: 100%; }
  .danger-card { align-items: stretch; flex-direction: column; }
  .danger-card .button { width: 100%; }
  .pdf-viewer { padding: 8px; border-radius: 10px; }
  .pdf-page { margin-bottom: 10px; }
  .auth-card { padding: 25px 20px; }
  .user-controls { grid-template-columns: 1fr; }
  .folder-edit-form { grid-template-columns: 1fr; }
  .switch-label { min-height: auto; }
  .role-fixed { justify-content: flex-start; flex-wrap: wrap; }
  .history-filter { grid-template-columns: 1fr; }
  .history-row { grid-template-columns: 1fr; gap: 8px; padding: 16px; }
  .history-device { grid-column: auto; }
}

@media print {
  body * { visibility: hidden !important; }
  body::before {
    visibility: visible !important;
    content: "この書類は印刷できません。";
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    color: #000;
    font-size: 24pt;
    font-weight: bold;
    background: #fff;
  }
}
