/* Version 7: shared responsive layout, including narrow panels on wide screens. */
:root { --panel-surface: #fff; --layout-line: #e0e7ee; }
:root[data-theme=dark] { --panel-surface: #162234; --layout-line: #2d3d52; }
html { scroll-padding-bottom: 90px; }
body { min-width: 0; }
button, a, input, select, textarea { max-width: 100%; }
button { white-space: normal; overflow-wrap: anywhere; }
button svg, a svg { flex-shrink: 0; }
input, select, textarea { min-width: 0; }
.primary, .secondary, .ghost, .danger { min-height: 44px; line-height: 1.4; text-align: center; }
:where(button, a, input, select, textarea, summary, [tabindex]):focus-visible { outline: 3px solid #6f9dce; outline-offset: 3px; }
.pagehead, .panel-head, .action-row, .pagination { flex-wrap: wrap; }
.pagehead > *, .panel-head > *, .hero-card > *, .duty-bar > *, .duty-intro > *, .chat-heading > *, .event > * { min-width: 0; }
h1, h2, h3, .eyebrow, .patrol-name, .profile strong, .stat .k, .stat .foot, .event, .crumb { overflow-wrap: anywhere; }
.pagehead h1 { hyphens: auto; }
.pagehead .action-row { gap: 10px; }
.action-row { align-items: center; }
.action-row button, .mini-button { min-height: 40px; }
.pagehead .action-row button { min-height: 44px; padding: 10px 14px; font-size: 12px; }
.panel p { line-height: 1.65; }
.panel > h3 + .table-wrap, .panel > p + .table-wrap { margin-top: 18px; }
.panel-copy { display: grid; gap: 8px; }
.panel-copy p { margin: 0; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.panel-actions + .table-wrap { margin-top: 18px; }
.audit-content { margin-top: 14px; font-size: 13px; line-height: 1.65; overflow-wrap: anywhere; }
.audit-content .event:first-child { padding-top: 0; }
.audit-content details { margin-top: 10px; }
.event > :last-child { flex: 1; }
.event-icon { flex: none; }
.panel h3 { line-height: 1.35; overflow-wrap: anywhere; hyphens: auto; }
.table-wrap { container: table-space / inline-size; border-radius: 8px; }
.data-table { white-space: normal; }
.data-table th, .data-table td { overflow-wrap: anywhere; vertical-align: top; line-height: 1.55; }
.data-table th { hyphens: auto; }
.data-table td .action-row { min-width: 130px; }
.backup-table { table-layout: fixed; }
.backup-table th:first-child { width: 55%; }
.backup-table th:nth-child(2) { width: 30%; }
.backup-table th:last-child { width: 15%; }
.filename { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.patrol-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 255px), 1fr)); }
.patrol-top { flex-wrap: wrap; }
.patrol-type { overflow-wrap: anywhere; line-height: 1.5; }
.pill, .role { max-width: 100%; line-height: 1.4; overflow-wrap: anywhere; }
.pill::before { flex-shrink: 0; }
.duty-intro .iconbox { flex-shrink: 0; }
.searchrow input, .searchrow select { flex: 1 1 180px; }
.month-filters > div { flex: 1 1 200px; min-width: 0; max-width: 400px; }
.chat-heading > div { flex: 1 1 180px; }
.chat-heading button { margin-left: auto; }
.chat-meta strong { overflow-wrap: anywhere; }
.chat-bubble { flex: 0 1 auto; }
.modal-backdrop { padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
.modal { max-height: calc(100dvh - 32px); overscroll-behavior: contain; }
.modal-actions { flex-wrap: wrap; padding-top: 6px; }
.modal-actions > button { flex: 1 1 135px; }
#theme-toggle {
  width: 46px; height: 46px; min-width: 46px; min-height: 46px;
  padding: 0; border-radius: 50%; display: grid; place-items: center;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  transition: background-color .15s, box-shadow .15s;
}
#theme-toggle:hover { box-shadow: 0 6px 22px #12283b40; }
#toast { right: 16px; bottom: max(78px, calc(env(safe-area-inset-bottom) + 62px)); max-width: calc(100vw - 32px); }
#toast .notice { overflow-wrap: anywhere; line-height: 1.5; }
/* Keep the modal and its focus trap above the floating theme control. */
.modal-backdrop { z-index: 50; }
#toast { z-index: 60; }
@container table-space (max-width: 760px) {
  .data-table, .data-table tbody { display: block; width: 100%; }
  .data-table thead { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .data-table tbody { display: grid; gap: 14px; }
  .data-table tbody tr { display: block; padding: 8px 14px; border: 1px solid var(--layout-line); border-radius: 13px; }
  .data-table tbody td { display: grid; grid-template-columns: minmax(90px, .8fr) minmax(0, 1.3fr); gap: 12px; padding: 10px 0; width: auto; border: 0; align-items: start; }
  .data-table tbody td::before { content: attr(data-label); font-size: 11px; font-weight: 700; color: #718294; }
  html[data-theme=dark] .data-table tbody td::before { color: #a4b7ce; }
  .data-table tbody td.cell-empty { display: block; }
  .data-table tbody td.cell-empty::before { content: none; }
  .data-table td .action-row { min-width: 0; }
  .data-table td > * { min-width: 0; max-width: 100%; }
  .data-table td > .pill, .data-table td > .role { justify-self: start; }
  .data-table td.cell-actions { display: block; }
  .data-table td.cell-actions::before { display: block; margin-bottom: 8px; }
  .backup-table th:first-child, .backup-table th:nth-child(2), .backup-table th:last-child { width: auto; }
}
@container table-space (max-width: 360px) {
  .data-table tbody tr { padding: 8px 12px; }
  .data-table tbody td { grid-template-columns: minmax(0, 1fr); gap: 5px; }
  .data-table td .action-row > button { flex: 1 1 100px; }
}
@media (max-width: 1100px) {
  .topline { flex-wrap: wrap; align-items: start; }
  .topright { flex-wrap: wrap; gap: 8px 12px; }
}
@media (max-width: 760px) {
  .sidebar { width: 70px; height: 100dvh; }
  .content { padding: 24px 16px max(94px, calc(env(safe-area-inset-bottom) + 78px)); }
  .pagehead { gap: 16px; margin-bottom: 24px; }
  .pagehead h1 { font-size: clamp(25px, 5vw, 32px); }
  .pagehead > .primary, .pagehead > .action-row { max-width: 100%; }
  .panel-head { align-items: start; }
  .topline { gap: 10px; }
  .topright { max-width: none; justify-content: start; }
  .crumb { line-height: 1.65; }
  .chat-compose { flex-wrap: wrap; }
  .chat-compose input { flex-basis: 180px; }
  .chat-compose button { margin-left: auto; }
  .duty-bar { padding: 17px; }
  .duty-actions { max-width: 100%; }
  .stat .v { font-size: clamp(24px, 5vw, 29px); }
}
@media (max-width: 480px) {
  .content { padding-left: 12px; padding-right: 12px; }
  .panel, .hero-card, .duty-panel { padding: 16px; }
  .stats { grid-template-columns: minmax(0, 1fr); }
  .stat .iconbox { display: grid; }
  .stat .v { font-size: 29px; }
  .time-stats .v { font-size: 25px; }
  .pagehead > .primary, .pagehead > .action-row, .pagehead .action-row > *, .panel-actions > *, .duty-actions > button { width: 100%; }
  .pagehead .action-row { width: 100%; }
  .pagehead .action-row > * { flex: 1 1 100%; }
  .duty-actions button { flex: 1 1 100%; min-width: 0; }
  .duty-intro { flex-wrap: wrap; }
  .hero-card h2 { font-size: 21px; }
  .chat-heading { gap: 10px; }
  .chat-heading button { width: 100%; }
  .chat-messages { min-height: 240px; padding: 12px; }
  .chat-message { gap: 8px; }
  .chat-avatar { width: 28px; height: 28px; border-radius: 9px; font-size: 12px; }
  .chat-bubble { max-width: calc(100% - 36px); padding: 11px; }
  .chat-meta { gap: 5px; }
  .chat-compose input, .chat-compose button { flex-basis: 100%; width: 100%; }
  .modal { padding: 20px; border-radius: 19px; }
  .login-art { padding: 24px; }
  .login-art h1 { font-size: 39px; }
  .login-box h2 { font-size: 32px; }
}
@media (max-height: 600px) and (min-width: 761px) {
  .sidebar { padding-top: 14px; padding-bottom: 14px; }
  .sidebar .brand { padding-bottom: 12px; }
  .sidebar .nav-label { padding-top: 10px; }
  .nav-item { padding-top: 10px; padding-bottom: 10px; }
}
