* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Yu Gothic", Meiryo, sans-serif; color: #222; background: #f4f6f7; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { width: min(1180px, 96vw); min-height: 700px; margin: 28px auto; background: #fff; border: 1px solid #8b8b8b; box-shadow: 0 3px 14px rgba(0,0,0,.08); }
.topbar { height: 58px; background: #31c0c4; color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 0 24px 0 0; }
.brand { height: 100%; display: flex; align-items: center; font-size: 25px; padding-left: 20px; }
.dshift { font-size: 25px; font-weight: 700; letter-spacing: .2px; }

.layout { display: grid; grid-template-columns: 155px 1fr; min-height: 640px; }
.sidebar { background: #31c0c4; color: #fff; display: flex; flex-direction: column; min-height: 640px; }
.menu-label { padding: 10px 15px 5px; font-size: 14px; opacity: .92; }
.menu-link { display: block; padding: 10px 18px 10px 40px; font-size: 15px; }
.sidebar-camera-form { margin: 0; }
.sidebar-camera-button { width: 100%; border: 0; text-align: left; background: transparent; color: inherit; cursor: pointer; }
.menu-link:hover, .menu-link.active { background: #009ec8; }
.sidebar-spacer { flex: 1; }
.menu-link.logout { margin-top: auto; padding: 18px; }

.content { position: relative; min-width: 0; padding: 25px 42px 22px; background: #fff; }
.content h1 { text-align: center; font-size: 24px; font-weight: 500; margin: 12px 0 28px; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 32px; padding: 4px 18px; border: 1px solid #555; background: #e5e5e5; color: #111; border-radius: 2px; }
.btn:hover { filter: brightness(.96); }
.btn.small { min-height: 28px; padding: 2px 12px; }
.btn.primary { background: #1f417a; color: #fff; border-color: #1f417a; }
.btn.reset { background: #4e7a49; color: #fff; border-color: #4e7a49; }
.btn.danger { color: #b00020; }

/* login */
.login-shell { min-height: 700px; }
.login-main { min-height: 640px; display: flex; flex-direction: column; padding: 0 28px 20px; background: #fff; }
.login-center { flex: 1; display: flex; align-items: center; justify-content: center; padding: 45px 0 30px; }
.login-form { width: min(560px, 100%); margin: 0; }
.login-row { display: grid; grid-template-columns: 150px minmax(240px, 320px); justify-content: center; align-items: center; column-gap: 14px; margin: 18px 0; }
.login-row label { text-align: right; white-space: nowrap; font-size: 17px; }
.login-row input { width: 100%; height: 36px; padding: 5px 8px; border: 1px solid #777; background: #fff; }
.login-actions { display: flex; justify-content: center; margin-top: 26px; }
.login-button { min-width: 125px; min-height: 38px; }

/* river screen */
.river-content { padding: 22px 36px 18px; }
.river-title-row { border-bottom: 2px solid #444; padding: 7px 2px 12px; margin-bottom: 20px; }
.river-title { font-size: 18px; }
.image-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.image-card { position: relative; display: block; width: 100%; padding: 0; border: 1px solid #777; background: #111; overflow: hidden; aspect-ratio: 16 / 9; }
button.image-card { border: 1px solid #777; }
.image-card img { display: block; width: 100%; height: 100%; object-fit: cover; }
button.image-card:hover::after { content: "クリックで拡大"; position: absolute; right: 8px; bottom: 8px; padding: 5px 8px; background: rgba(0,0,0,.66); color: #fff; font-size: 12px; }
.image-caption { position: absolute; left: 8px; top: 8px; padding: 4px 8px; color: #fff; background: rgba(0,0,0,.48); font-size: 12px; }
.dummy-image-card { display: flex; align-items: center; justify-content: center; background: #a9a9a9; color: #fff; }
.dummy-image-text { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 22px; }
.dummy-image-text strong { font-size: 24px; }

.river-control-form { margin-top: 18px; }
.update-control-row { display: flex; align-items: center; gap: 8px; min-height: 34px; margin-bottom: 8px; flex-wrap: wrap; }
.update-mode-button { min-width: 92px; height: 32px; border: 1px solid #666; background: #eee; color: #111; }
.update-mode-button.play.active { background: #4a5568; color: #fff; font-weight: 700; }
.update-mode-button.stop.active { background: #4a5568; color: #fff; font-weight: 700; }
.update-mode-button:disabled { cursor: not-allowed; opacity: .45; background: #ddd; color: #777; }
.refresh-status { margin-left: 10px; font-size: 12px; color: #555; }
.shift-row { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; padding-bottom: 12px; border-bottom: 2px solid #444; }
.nav-step { min-width: 92px; height: 32px; border: 1px solid #888; background: #eee; color: #111; }
.nav-step.active { background: #4a5568; color: #fff; font-weight: 700; }
.search-area { padding-top: 10px; }
.search-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.search-label { display: inline-flex; align-items: center; justify-content: center; min-width: 112px; height: 32px; border: 1px solid #666; background: #f7f7f7; }
.search-row input[type="datetime-local"] { height: 32px; border: 1px solid #aaa; padding: 3px 7px; }
.prototype-note { margin-top: 13px; padding: 9px 12px; background: #fff9df; border: 1px solid #e5d282; font-size: 12px; color: #655c2f; }

/* modal */
.image-modal { position: fixed; inset: 0; z-index: 1000; display: none; align-items: center; justify-content: center; }
.image-modal.open { display: flex; }
.image-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.72); }
.image-modal-dialog { position: relative; z-index: 1; width: min(1400px, 94vw); max-height: 94vh; background: #fff; padding: 18px; border-radius: 4px; box-shadow: 0 8px 35px rgba(0,0,0,.4); }
.image-modal-dialog h2 { margin: 0 45px 12px 0; font-size: 18px; }
.image-modal-close { position: absolute; top: 8px; right: 10px; width: 36px; height: 36px; border: 0; background: transparent; font-size: 30px; line-height: 1; }
.modal-image-wrap { position: relative; display: flex; justify-content: center; max-height: calc(94vh - 80px); overflow: auto; background: #111; }
.modal-image-wrap img { display: block; max-width: 100%; max-height: calc(94vh - 90px); object-fit: contain; }
body.modal-open { overflow: hidden; }

/* user */
.page-title-row { display: flex; align-items: center; justify-content: center; gap: 180px; margin: 10px 0 18px; }
.page-title-row h1 { margin: 0; }
.user-table { width: min(720px, 100%); margin: 0 auto; border-collapse: collapse; }
.user-table th, .user-table td { border: 1px solid #333; padding: 8px 12px; text-align: center; }
.user-table th { background: #bfd9ec; }
.message { width: min(720px,100%); margin: 0 auto 12px; padding: 9px 12px; background: #eef7e9; border: 1px solid #b8d4aa; }
.user-form { width: min(620px,100%); margin: 0 auto; }
.form-row { display: grid; grid-template-columns: 220px 1fr; gap: 10px; align-items: start; margin: 10px 0; }
.form-row > label { text-align: right; padding-top: 6px; }
.form-row input, .form-row select { width: 100%; min-height: 34px; border: 1px solid #555; padding: 5px 8px; }
.field-error { margin-top: 3px; color: #b00020; font-size: 12px; }
.help-text { margin-top: 3px; color: #666; font-size: 11px; }
.form-actions { display: flex; justify-content: center; gap: 30px; margin-top: 55px; }
.legacy-redirect-message { padding: 80px; text-align: center; }
.legacy-redirect-message a { text-decoration: underline; }


/* r8: login lock / password policy */
.account-table { width: min(900px, 100%); }
.inline-form { display: inline; margin: 0; }
.lock-status { display: inline-block; min-width: 76px; padding: 3px 8px; border-radius: 3px; font-size: 12px; text-align: center; }
.lock-status.normal { background: #eef7e9; border: 1px solid #b8d4aa; color: #31552b; }
.lock-status.warning { background: #fff8dc; border: 1px solid #d4b45f; color: #765c14; }
.lock-status.locked { background: #fdeaea; border: 1px solid #d38a8a; color: #9b1c1c; font-weight: 700; }
.btn.unlock { background: #eef7e9; border-color: #6d9b5c; }
.account-policy-note { width: min(900px, 100%); margin: 18px auto 0; padding: 10px 12px; border: 1px solid #c7c7c7; background: #f8f8f8; font-size: 12px; line-height: 1.6; }
.message.error { background: #fdeaea; border-color: #d38a8a; color: #7a1d1d; }

/* r7: account management / first-login password change */
.compact-user-table { width: min(560px, 100%); }
.password-change-notice { width: min(620px, 100%); margin: 0 auto 24px; padding: 10px 14px; border: 1px solid #d4b45f; background: #fff8dc; text-align: center; }
.password-change-form input[readonly] { background: #e9e9e9; color: #444; }
.password-actions { margin-top: 38px; }
.form-wide-error { width: min(620px, 100%); margin: 8px auto; text-align: center; }

@media (max-width: 820px) {
  .app-shell { width: 100%; margin: 0; border: 0; }
  .layout { grid-template-columns: 120px 1fr; }
  .content, .river-content { padding: 18px; }
  .image-pair { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .form-row > label { text-align: left; }
  .page-title-row { gap: 30px; }
  .refresh-status { width: 100%; margin-left: 0; }
}

/* r9: responsive design */
.mobile-menu-toggle,
.mobile-menu-close,
.sidebar-backdrop { display: none; }
.table-scroll { width: 100%; }

@media (max-width: 980px) {
  .app-shell {
    width: min(100%, 960px);
    margin: 0 auto;
    min-height: 100dvh;
    border-left: 0;
    border-right: 0;
  }

  .topbar {
    height: 56px;
    padding-right: 16px;
  }

  .brand {
    font-size: 22px;
    padding-left: 16px;
  }

  .dshift { font-size: 21px; }

  .layout {
    grid-template-columns: 132px minmax(0, 1fr);
    min-height: calc(100dvh - 56px);
  }

  .sidebar {
    min-height: calc(100dvh - 56px);
  }

  .content,
  .river-content {
    padding: 20px 24px;
  }

  .page-title-row { gap: 70px; }
  .form-row { grid-template-columns: 180px minmax(0, 1fr); }
  .user-table th,
  .user-table td { padding: 7px 8px; }
}

@media (max-width: 600px) {
  html, body { background: #fff; }

  .app-shell {
    width: 100%;
    min-height: 100dvh;
    margin: 0;
    border: 0;
    box-shadow: none;
  }

  .topbar {
    height: 54px;
    padding: 0 12px;
  }

  .brand {
    min-width: 0;
    padding-left: 0;
    font-size: clamp(18px, 5vw, 22px);
    white-space: nowrap;
  }

  .dshift {
    flex: 0 0 auto;
    margin-left: 12px;
    font-size: 18px;
  }

  .layout {
    display: block;
    min-height: calc(100dvh - 54px);
  }

  .mobile-menu-toggle {
    position: fixed;
    z-index: 950;
    left: 10px;
    bottom: 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 42px;
    padding: 7px 12px;
    border: 1px solid #177d84;
    border-radius: 5px;
    background: #31c0c4;
    color: #fff;
    box-shadow: 0 3px 12px rgba(0,0,0,.22);
    font-size: 14px;
  }

  .mobile-menu-icon { font-size: 20px; line-height: 1; }

  .mobile-menu-close {
    position: absolute;
    top: 8px;
    right: 8px;
    display: block;
    width: 38px;
    height: 38px;
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 30px;
    line-height: 1;
  }

  .sidebar {
    position: fixed;
    z-index: 1001;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(78vw, 280px);
    min-height: 100dvh;
    padding-top: 12px;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 4px 0 18px rgba(0,0,0,.25);
  }

  .sidebar-backdrop {
    position: fixed;
    z-index: 1000;
    inset: 0;
    background: rgba(0,0,0,.45);
  }

  body.sidebar-open { overflow: hidden; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; }
  body.sidebar-open .mobile-menu-toggle { visibility: hidden; }

  .menu-label { padding: 12px 18px 6px; }
  .menu-link { padding: 12px 18px 12px 34px; }
  .menu-link.logout { padding: 18px; }

  .content,
  .river-content {
    width: 100%;
    padding: 18px 14px 76px;
  }

  .content h1 {
    margin: 8px 0 22px;
    font-size: 21px;
  }

  .river-title-row {
    margin-bottom: 14px;
    padding: 5px 0 10px;
  }

  .river-title {
    font-size: 16px;
    line-height: 1.5;
  }

  .image-pair {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .image-card {
    max-height: none;
    aspect-ratio: 16 / 9;
  }

  .dummy-image-text { font-size: 18px; }
  .dummy-image-text strong { font-size: 20px; }

  .update-control-row {
    align-items: stretch;
    gap: 6px;
  }

  .update-mode-button {
    flex: 1 1 calc(50% - 3px);
    min-width: 0;
    min-height: 40px;
    height: auto;
  }

  .refresh-status {
    width: 100%;
    margin: 4px 0 0;
    line-height: 1.5;
  }

  .shift-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .nav-step {
    width: 100%;
    min-width: 0;
    height: auto;
    min-height: 40px;
    padding: 5px 3px;
    font-size: 13px;
  }

  .shift-row .nav-step:nth-child(4) {
    grid-column: 1 / -1;
  }

  .search-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .search-label {
    width: 100%;
    min-width: 0;
    justify-content: flex-start;
    padding: 0 8px;
  }

  .search-row input[type="datetime-local"] {
    width: 100%;
    min-width: 0;
    height: 40px;
  }

  .search-row .btn {
    width: 100%;
    min-height: 40px;
  }

  .prototype-note {
    font-size: 11px;
    line-height: 1.6;
  }

  .image-modal-dialog {
    width: 96vw;
    max-height: 92dvh;
    padding: 12px;
  }

  .image-modal-dialog h2 {
    font-size: 15px;
    line-height: 1.4;
  }

  .modal-image-wrap {
    max-height: calc(92dvh - 72px);
  }

  .modal-image-wrap img {
    max-height: calc(92dvh - 82px);
  }

  .page-title-row {
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    margin: 4px 0 18px;
  }

  .page-title-row h1 {
    text-align: left;
    font-size: 21px;
  }

  .page-title-row .btn { align-self: center; }

  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #ddd;
  }

  .user-table,
  .account-table,
  .compact-user-table {
    width: 100%;
    min-width: 610px;
    margin: 0;
  }

  .user-table th,
  .user-table td {
    padding: 7px 6px;
    white-space: nowrap;
    font-size: 13px;
  }

  .account-policy-note,
  .message,
  .password-change-notice,
  .form-wide-error {
    width: 100%;
  }

  .user-form {
    width: 100%;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 5px;
    margin: 12px 0;
  }

  .form-row > label {
    text-align: left;
    padding-top: 0;
    font-weight: 600;
  }

  .form-row input,
  .form-row select {
    min-height: 40px;
    font-size: 16px;
  }

  .form-actions {
    gap: 8px;
    margin-top: 32px;
    flex-wrap: wrap;
  }

  .form-actions .btn {
    flex: 1 1 100px;
    min-height: 40px;
  }

  .login-shell { min-height: 100dvh; }

  .login-main {
    min-height: calc(100dvh - 54px);
    padding: 0 18px 24px;
  }

  .login-center {
    align-items: flex-start;
    padding: clamp(64px, 18vh, 150px) 0 30px;
  }

  .login-form { width: 100%; }

  .login-row {
    grid-template-columns: 1fr;
    gap: 6px;
    margin: 16px 0;
  }

  .login-row label {
    text-align: left;
    font-size: 16px;
  }

  .login-row input {
    width: 100%;
    height: 42px;
    font-size: 16px;
  }

  .login-button {
    width: min(240px, 100%);
    min-height: 42px;
  }
}

@media (max-width: 420px) {
  .topbar { padding: 0 9px; }
  .brand { font-size: 17px; }
  .dshift { font-size: 16px; }
  .content, .river-content { padding-left: 10px; padding-right: 10px; }
  .shift-row { grid-template-columns: 1fr 1fr; }
  .nav-step { font-size: 12px; }
  .user-table, .account-table, .compact-user-table { min-width: 580px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* r10: image file source / multiple camera */
.no-image-card { display: flex; align-items: center; justify-content: center; background: #666; color: #fff; }
