* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(135deg, #4FACFE 0%, #00F2FE 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.container {
  width: 100%;
  max-width: 1040px;
  background: white;
  border-radius: 16px;
  padding: 32px 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  margin: auto;
}

/* ── Header ──────────────────────────────────────────────────────── */

.header {
  text-align: center;
  margin-bottom: 24px;
}

.header h1 {
  margin: 0 0 8px 0;
  font-size: 28px;
  font-weight: 700;
  color: #1a1a1a;
}

.header p {
  margin: 0;
  font-size: 14px;
  color: #666;
}

/* ── Info cards ──────────────────────────────────────────────────── */

.info-card {
  margin-bottom: 16px;
  padding: 16px;
  background: #f9fbff;
  border: 1px solid #e3eefc;
  border-radius: 10px;
}

.info-card h2 {
  margin: 0 0 10px 0;
  font-size: 16px;
  font-weight: 700;
  color: #1a1a1a;
}

.info-card dl {
  margin: 0;
}

.info-row {
  display: flex;
  gap: 12px;
  padding: 7px 0;
  border-top: 1px solid #edf2f9;
  font-size: 14px;
}

.info-row:first-child {
  border-top: none;
}

.info-row dt {
  flex: 0 0 120px;
  color: #777;
}

.info-row dd {
  flex: 1;
  margin: 0;
  min-width: 0;
  color: #1a1a1a;
  overflow-wrap: anywhere;
}

.info-row code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.info-row a {
  color: #1f7fd6;
}

.muted {
  color: #aaa;
}

.info-card pre {
  margin: 0;
  padding: 12px;
  background: #f7f7f7;
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.5;
  color: #555;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Buttons ─────────────────────────────────────────────────────── */

.primary-button {
  display: block;
  width: 100%;
  padding: 16px;
  margin-top: 12px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #4FACFE 0%, #00F2FE 100%);
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(79, 172, 254, 0.3);
  transition: transform 0.2s, box-shadow 0.2s;
  text-align: center;
  text-decoration: none;
  font-family: inherit;
}

.primary-button:active {
  transform: scale(0.98);
  box-shadow: 0 2px 8px rgba(79, 172, 254, 0.2);
}

/* ── Loading indicator ───────────────────────────────────────────── */

.loading-indicator {
  text-align: center;
  padding: 32px 20px;
  background: #f0f8ff;
  border-radius: 8px;
  border: 2px solid #4FACFE;
  margin-bottom: 16px;
}

.fishing-animation {
  font-size: 48px;
  margin-bottom: 12px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bobber {
  display: inline-block;
  margin-left: 8px;
  font-size: 24px;
  animation: bobbing 2s ease-in-out infinite;
}

@keyframes bobbing {
  0%, 100% { transform: translateY(0px);   opacity: 0.6; }
  50%      { transform: translateY(-10px); opacity: 1; }
}

.loading-indicator p {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: #4FACFE;
}

/* ── Error card ───────────────────────────────────────────────────── */

.error-card {
  text-align: center;
  padding: 24px 16px;
  background: #fff8f8;
  border-radius: 8px;
  border: 2px solid #fcc;
  margin-bottom: 16px;
}

.error-card .error-icon {
  font-size: 40px;
  margin: 0 0 12px 0;
}

.error-card p {
  font-size: 14px;
  color: #666;
  margin: 0 0 16px 0;
  line-height: 1.5;
}

/* ── Summary tiles ───────────────────────────────────────────────── */

.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.stat-tile {
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #e3eefc;
  background: #f9fbff;
  font-family: inherit;
  color: #1a1a1a;
  cursor: pointer;
}

.stat-num {
  display: block;
  font-size: 22px;
  font-weight: 700;
}

.stat-label {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: #666;
}

.stat-tile--text .stat-num {
  padding: 4px 0 3px;
  font-size: 15px;
  color: #1f7fd6;
}

.stat-tile--alert {
  background: #fff4f3;
  border-color: #fcd4d0;
}

.stat-tile--alert .stat-num {
  color: #b42318;
}

.stat-tile--warn .stat-num {
  color: #b07d00;
}

.stat-tile--ok .stat-num {
  color: #1e7a45;
}

/* ── Tabs ────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 2px solid #e3eefc;
}

.tab {
  margin-bottom: -2px;
  padding: 10px 16px;
  border: none;
  border-bottom: 3px solid transparent;
  background: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #777;
  cursor: pointer;
}

.tab--active {
  color: #1f7fd6;
  border-bottom-color: #4FACFE;
}

.tab-count {
  font-weight: 600;
  opacity: 0.8;
}

.tab-count--alert {
  color: #b42318;
  opacity: 1;
}

/* ── Toolbar: status chips, catch filter, Refresh ──────────────────── */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.toolbar .filter-chips,
.toolbar .catch-filter {
  margin: 0;
}

.toolbar-spacer {
  flex: 1;
}

.small-button {
  padding: 8px 12px;
  border: 1px solid #d0eaff;
  border-radius: 8px;
  background: #f0f8ff;
  color: #1f7fd6;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.catch-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 600;
  color: #555;
}

.catch-filter select {
  min-width: 150px;
  max-width: 260px;
  padding: 8px 10px;
  border: 1px solid #d0eaff;
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  font-family: inherit;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.filter-chip {
  padding: 8px 12px;
  border: 1px solid #d0eaff;
  border-radius: 999px;
  background: #f0f8ff;
  color: #1f7fd6;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.filter-chip--active {
  background: #4FACFE;
  border-color: #4FACFE;
  color: white;
}

.status {
  min-height: 0;
  margin-bottom: 8px;
  font-size: 14px;
  color: #1e7a45;
}

.status:empty {
  display: none;
}

.status--error {
  color: #b42318;
}

/* ── Upload rows ─────────────────────────────────────────────────── */

.media-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.media-row {
  padding: 12px 14px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: #f9fbff;
  border: 1px solid #e3eefc;
  border-left: 4px solid #2e9e5b;
  font-size: 14px;
}

.media-row--submitted,
.media-row--processing {
  border-left-color: #e0a100;
}

.media-row--failed,
.media-row--stuck {
  border-left-color: #d92d20;
  background: #fff4f3;
  border-color: #fcd4d0;
}

.row-main {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
  margin-bottom: 4px;
}

.row-catch {
  font-weight: 700;
  color: #1f7fd6;
  text-decoration: none;
}

.row-status {
  font-weight: 600;
  white-space: nowrap;
}

.row-file {
  color: #1a1a1a;
  overflow-wrap: anywhere;
}

.row-meta {
  margin-top: 2px;
  font-size: 12px;
  color: #777;
}

.row-error {
  margin-top: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  background: white;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: #a93226;
  overflow-wrap: anywhere;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.row-action {
  padding: 8px 12px;
  border: 1px solid #d0eaff;
  border-radius: 8px;
  background: white;
  color: #1f7fd6;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.row-action--danger {
  color: #b42318;
  border-color: #fcd4d0;
}

.row-action--armed {
  background: #b42318;
  border-color: #b42318;
  color: white;
}

.row-action:disabled {
  opacity: 0.6;
  cursor: default;
}

.media-empty {
  padding: 20px;
  text-align: center;
  color: #888;
  font-size: 14px;
}

.secondary-button {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 8px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  border-radius: 8px;
  border: 2px solid #d0eaff;
  background: #f0f8ff;
  color: #1f7fd6;
  cursor: pointer;
}

.secondary-button:disabled {
  opacity: 0.6;
  cursor: default;
}

/* ── Wide screens: each upload is one table-like row ──────────────── */

/* Shared columns for the headings and every row */
.media-head,
#mediaList .media-row {
  display: grid;
  grid-template-columns: 118px 112px minmax(0, 1fr) 84px 76px 150px 190px;
  grid-template-areas: "status catch file type size when actions";
  column-gap: 12px;
  align-items: start;
}

.media-head {
  padding: 8px 14px 8px 18px;
  border-bottom: 1px solid #e3eefc;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #888;
}

#mediaList .media-row {
  margin-bottom: 0;
  border-radius: 0;
  border-width: 0 0 1px 4px;
  border-bottom-color: #eef3fa;
  background: white;
}

#mediaList .media-row--failed,
#mediaList .media-row--stuck {
  background: #fff4f3;
  border-left-color: #d92d20;
}

#mediaList .row-status { grid-area: status; }
#mediaList .row-catch  { grid-area: catch; }
#mediaList .row-body   { grid-area: file; min-width: 0; }
#mediaList .row-actions {
  grid-area: actions;
  justify-content: flex-end;
  margin-top: 0;
}

/* The details become their own columns */
#mediaList .row-meta {
  display: contents;
}

#mediaList .meta-type { grid-area: type; }
#mediaList .meta-size { grid-area: size; }
#mediaList .meta-when { grid-area: when; }

#mediaList .row-meta > span {
  font-size: 14px;
  color: #555;
}

#mediaList .meta-when .row-by {
  display: block;
  margin-top: 2px;
  font-size: 13px;
}

#mediaList .media-empty {
  display: block;
}

/* The uploader's name stands out a little from the rest of the details */
.row-by {
  font-weight: 600;
  color: #333;
}

/* ── Storage check ───────────────────────────────────────────────── */

.scan-head {
  display: flex;
  align-items: center;
  gap: 16px;
}

.scan-head .card-intro {
  flex: 1;
  margin: 0;
}

.scan-head .secondary-button {
  width: auto;
  margin: 0;
  padding: 10px 18px;
  white-space: nowrap;
}

.card-intro {
  font-size: 13px;
  color: #666;
  line-height: 1.5;
}

.scan-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.scan-result h3 {
  margin: 16px 0 8px 0;
  font-size: 14px;
  color: #1a1a1a;
}

.scan-summary {
  margin: 12px 0 0 0;
  font-size: 13px;
  color: #555;
}

.media-row--recent {
  border-left-color: #e0a100;
  background: #fffbea;
  border-color: #f4e3a6;
}

/* ── Phones ──────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .stat-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .tab {
    flex: 1;
    padding: 10px 6px;
    font-size: 14px;
    white-space: nowrap;
  }

  .media-head {
    display: none;
  }

  /* Back to cards: catch + status, then the file, the details on one line, any error, actions */
  #mediaList .media-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "catch status"
      "file file"
      "meta meta"
      "actions actions";
    row-gap: 4px;
    margin-bottom: 8px;
    border-radius: 10px;
    border-width: 1px 1px 1px 4px;
    border-color: #e3eefc;
    background: #f9fbff;
  }

  #mediaList .media-row--submitted,
  #mediaList .media-row--processing {
    border-left-color: #e0a100;
  }

  #mediaList .media-row--complete {
    border-left-color: #2e9e5b;
  }

  #mediaList .media-row--failed,
  #mediaList .media-row--stuck {
    background: #fff4f3;
    border-color: #fcd4d0;
    border-left-color: #d92d20;
  }

  #mediaList .row-meta {
    grid-area: meta;
    display: flex;
    flex-wrap: wrap;
  }

  #mediaList .row-meta > span {
    font-size: 12px;
    color: #777;
  }

  #mediaList .meta-when { order: 1; }
  #mediaList .meta-type { order: 2; }
  #mediaList .meta-size { order: 3; }

  #mediaList .meta-type::before,
  #mediaList .meta-size::before {
    content: "\00a0·\00a0";
  }

  #mediaList .meta-when .row-by {
    display: inline;
    font-size: 12px;
  }

  #mediaList .row-actions {
    justify-content: flex-start;
    margin-top: 6px;
  }

  .toolbar-spacer {
    display: none;
  }

  .scan-head {
    flex-direction: column;
    align-items: stretch;
  }

  .scan-head .secondary-button {
    width: 100%;
  }

  .scan-columns {
    grid-template-columns: 1fr;
  }
}

/* ── Utility ─────────────────────────────────────────────────────── */

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
