/* Manage Damage — lifecycle queues, table + tabbed drawer */

.mp-main--damage {
  position: relative;
}

.md-toolbar {
  flex-wrap: wrap;
}

.md-search-note {
  flex: 1 1 100%;
  margin: 0;
  font-size: 0.75rem;
  color: #92400e;
}

.md-search-note[hidden] {
  display: none !important;
}

.md-sync-banner {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid #fcd34d;
  background: #fffbeb;
  color: #92400e;
  font-size: 0.8125rem;
}

.md-sync-banner[hidden] {
  display: none !important;
}

.md-sync-banner p {
  margin: 0 0 0.35rem;
}

.md-sync-banner code {
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.7);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.md-queues {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.md-queue {
  appearance: none;
  border: 1px solid var(--border, #e5e7eb);
  background: var(--surface, #fff);
  color: var(--text, #111827);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.md-queue:hover {
  background: var(--surface-2, #f8fafc);
}

.md-queue.is-active {
  background: var(--accent, #2563eb);
  border-color: var(--accent, #2563eb);
  color: #fff;
}

.md-queue__count {
  opacity: 0.85;
  margin-left: 0.25rem;
}

.md-table-wrap {
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px;
  overflow: auto;
  background: var(--surface, #fff);
}

.md-table-wrap[hidden] {
  display: none !important;
}

.md-table {
  width: 100%;
  min-width: 980px;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.md-col-name { width: 24%; }
.md-col-lifecycle { width: 14%; }
.md-col-crew { width: 12%; }
.md-col-utility { width: 12%; }
.md-col-type { width: 10%; }
.md-col-docs { width: 8%; }
.md-col-claim { width: 12%; }
.md-col-amount { width: 8%; }

.md-table th,
.md-table td {
  padding: 0.55rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border, #e5e7eb);
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.md-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted, #6b7280);
  background: var(--surface-2, #f8fafc);
  font-weight: 600;
}

.md-table tr:last-child td {
  border-bottom: none;
}

.md-table tbody tr {
  cursor: pointer;
}

.md-table tbody tr:hover,
.md-table tbody tr.is-selected {
  background: var(--surface-2, #f8fafc);
}

.md-table__name {
  font-weight: 500;
}

.md-muted {
  display: block;
  font-size: 0.68rem;
  color: var(--muted, #6b7280);
  margin-top: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.md-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--surface-2, #f1f5f9);
  color: var(--text, #111827);
  border: 1px solid transparent;
}

.md-chip--queue-open { background: #dbeafe; color: #1e40af; }
.md-chip--queue-investigating { background: #fef3c7; color: #92400e; }
.md-chip--queue-claims { background: #ede9fe; color: #5b21b6; }
.md-chip--queue-closed { background: #e5e7eb; color: #374151; }
.md-chip--queue-stale { background: #fee2e2; color: #991b1b; }
.md-chip--queue-awaiting { background: #ffedd5; color: #9a3412; }

.md-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--surface-2, #e5e7eb);
  color: var(--muted, #6b7280);
}

.md-badge--warn {
  background: #fed7aa;
  color: #9a3412;
}

.md-badge--ok {
  background: #bbf7d0;
  color: #166534;
}

.md-drawer[hidden] {
  display: none !important;
}

.md-drawer {
  position: fixed;
  inset: 0;
  z-index: 80;
}

.md-drawer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
}

.md-drawer__panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(480px, 100%);
  height: 100%;
  max-height: 100dvh;
  background: var(--surface, #fff);
  border-left: 1px solid var(--border, #e5e7eb);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.md-drawer__head,
.md-drawer__foot {
  flex: 0 0 auto;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border, #e5e7eb);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.md-drawer__head {
  /* PWA + Safari use black-translucent status bar; pad below Dynamic Island. */
  padding-top: calc(0.75rem + var(--safe-top, env(safe-area-inset-top, 0px)));
  padding-right: max(1.1rem, var(--safe-right, env(safe-area-inset-right, 0px)));
  padding-left: max(1.1rem, var(--safe-left, env(safe-area-inset-left, 0px)));
}

.md-drawer__head .mp-btn {
  flex: 0 0 auto;
  align-self: flex-start;
  min-height: 44px;
  min-width: 44px;
  z-index: 1;
}

.md-drawer__foot {
  border-bottom: none;
  border-top: 1px solid var(--border, #e5e7eb);
  align-items: center;
  gap: 0.5rem;
  padding-bottom: calc(0.75rem + var(--safe-bottom, env(safe-area-inset-bottom, 0px)));
  padding-right: max(1.1rem, var(--safe-right, env(safe-area-inset-right, 0px)));
  padding-left: max(1.1rem, var(--safe-left, env(safe-area-inset-left, 0px)));
}

.md-drawer__foot .mp-btn--danger {
  margin-right: auto;
}

.md-drawer__title {
  margin: 0.15rem 0 0;
  font-size: 1.05rem;
  line-height: 1.3;
  word-break: break-word;
}

.md-drawer__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 1rem 1.1rem 1.5rem;
  -webkit-overflow-scrolling: touch;
}

.md-drawer__error {
  margin: 0;
  color: #b91c1c;
  font-size: 0.8125rem;
  flex: 1;
}

.md-tabs {
  flex: 0 0 48px;
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0;
  height: 48px;
  max-height: 48px;
  border-bottom: 1px solid var(--border, #e5e7eb);
  padding: 0 max(1.1rem, var(--safe-right, env(safe-area-inset-right, 0px))) 0 max(1.1rem, var(--safe-left, env(safe-area-inset-left, 0px)));
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  overscroll-behavior-y: none;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.md-tabs::-webkit-scrollbar {
  display: none;
  height: 0;
}

.md-tab {
  appearance: none;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  height: 48px;
  padding: 0 0.85rem;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted, #6b7280);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.md-tab.is-active {
  color: var(--accent, #2563eb);
  border-bottom-color: var(--accent, #2563eb);
}

.md-tab-panel[hidden] {
  display: none !important;
}

.md-hint {
  margin: 0 0 0.85rem;
  font-size: 0.75rem;
  color: var(--muted, #6b7280);
  line-height: 1.4;
}

.md-field input:disabled {
  background: var(--surface-2, #f8fafc);
  color: var(--muted, #6b7280);
}

.md-section {
  margin-bottom: 1.15rem;
}

.md-section__title {
  margin: 0 0 0.55rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted, #6b7280);
  font-weight: 600;
}

.md-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.md-field--full {
  grid-column: 1 / -1;
}

.md-field label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted, #6b7280);
  margin-bottom: 0.25rem;
}

.md-field input,
.md-field select,
.md-field textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 34px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  font: inherit;
  background: var(--surface, #fff);
  color: var(--text, #111827);
}

.md-field textarea {
  min-height: 72px;
  resize: vertical;
}

.md-people__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
}

.md-person-chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--border, #e5e7eb);
  background: var(--surface-2, #f8fafc);
  color: var(--text, #111827);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}

.md-person-chip span {
  color: var(--muted, #6b7280);
  font-weight: 700;
}

.md-people__search {
  width: 100%;
}

.md-people__results {
  display: flex;
  flex-direction: column;
  margin-top: 0.35rem;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface, #fff);
}

.md-people__results[hidden] {
  display: none !important;
}

.md-people__option,
.md-people__empty {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--border, #e5e7eb);
  background: transparent;
  color: var(--text, #111827);
  font: inherit;
  font-size: 0.8125rem;
  padding: 0.45rem 0.6rem;
  cursor: pointer;
}

.md-people__option:last-child,
.md-people__empty:last-child {
  border-bottom: 0;
}

.md-people__option:hover {
  background: var(--surface-2, #f8fafc);
}

.md-people__empty {
  margin: 0;
  color: var(--muted, #6b7280);
  cursor: default;
}

.md-files {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.md-files a,
.md-file-link {
  color: var(--accent, #2563eb);
  font-size: 0.8125rem;
  text-decoration: underline;
  display: block;
  margin-bottom: 0.25rem;
}

.md-file-muted {
  display: block;
  font-size: 0.8125rem;
  color: var(--muted, #6b7280);
  margin-bottom: 0.25rem;
}

.md-files__upload {
  font-size: 0.8125rem;
  margin-top: 0.5rem;
}

.md-update-form textarea,
.md-reply-form textarea {
  width: 100%;
  min-height: 72px;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
}

.md-update-form__row,
.md-reply-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.md-reply-form[hidden] {
  display: none;
}

.md-update-form__file {
  font-size: 0.8125rem;
}

.md-update-form__status {
  font-size: 0.8125rem;
  color: var(--muted, #6b7280);
}

.md-update {
  display: flex;
  gap: 0.65rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border, #e5e7eb);
}

.md-update--reply {
  border-bottom: 0;
  padding-top: 0.65rem;
}

.md-update__avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  object-fit: cover;
  flex: 0 0 auto;
}

.md-update__avatar--initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #e5e7eb;
  color: #111827;
  font-size: 0.7rem;
  font-weight: 650;
}

.md-update__body {
  min-width: 0;
  flex: 1;
}

.md-update__meta {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  font-size: 0.8125rem;
}

.md-update__meta span {
  color: var(--muted, #6b7280);
}

.md-update__text {
  margin: 0.25rem 0 0;
  white-space: pre-wrap;
}

.md-update__reply {
  margin-top: 0.35rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent, #2563eb);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
}

.md-update__replies {
  margin-top: 0.35rem;
  padding-left: 0.25rem;
}

@media (max-width: 720px) {
  .md-fields {
    grid-template-columns: 1fr;
  }

  .md-drawer__panel {
    width: 100%;
    border-left: none;
  }

  .md-drawer__title {
    padding-right: 0.25rem;
  }
}

.md-file-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.35rem;
}

.md-files .md-file-row a.md-file-open,
.md-file-open {
  display: inline;
  margin: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--accent, #2563eb);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.35rem;
  text-decoration: none;
  cursor: pointer;
}

.md-file-name {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text, #111827);
  font: inherit;
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.md-file-thumb-btn {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  line-height: 0;
  overflow: hidden;
}

.md-file-thumb {
  display: block;
  width: 40px;
  height: 40px;
  max-width: 40px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2, #f3f4f6);
}

.md-file-preview {
  position: fixed;
  inset: 0;
  z-index: 140;
}

.md-file-preview[hidden] {
  display: none !important;
}

.md-file-preview__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.md-file-preview__dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(960px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  margin: 1rem auto;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.28);
  overflow: hidden;
}

.md-file-preview__bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border, #e5e7eb);
}

.md-file-preview__title {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
}

.md-file-preview__close {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted, #6b7280);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.3rem 0.45rem;
  cursor: pointer;
}

.md-file-preview__body {
  min-height: 240px;
  max-height: calc(100vh - 7rem);
  overflow: auto;
  background: #0f172a;
}

.md-file-preview__media {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 7rem);
  margin: 0 auto;
}

.md-file-preview__frame {
  display: block;
  width: 100%;
  height: min(75vh, 820px);
  border: 0;
  background: #fff;
}

@media (max-width: 720px) {
  .md-file-preview__dialog {
    width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    border-radius: 0;
  }

  .md-file-preview__bar {
    padding-top: calc(0.65rem + var(--safe-top, env(safe-area-inset-top, 0px)));
    padding-right: max(0.75rem, var(--safe-right, env(safe-area-inset-right, 0px)));
    padding-left: max(0.75rem, var(--safe-left, env(safe-area-inset-left, 0px)));
  }

  .md-file-preview__body {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    padding-bottom: var(--safe-bottom, env(safe-area-inset-bottom, 0px));
  }

  .md-file-preview__media {
    width: 100%;
    max-height: 100%;
    object-fit: contain;
  }

  .md-file-preview__frame {
    height: 100%;
  }
}
