/* Saltwater Blooms Dashboard — plain CSS, no framework.
 *
 * Accessibility notes:
 *  - :focus-visible styles are defined globally; every interactive
 *    element is reachable and visible via keyboard.
 *  - Draft/published state is encoded in text badges (color is never the
 *    only signal).
 */

:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #d7dde3;
  --text: #1c2b33;
  --muted: #5d6f7a;
  --accent: #0e7490;
  --accent-dark: #0c6076;
  --draft: #9a5b00;
  --draft-bg: #fdf1dd;
  --published: #176b37;
  --published-bg: #e2f3e8;
  --dirty: #8a4b0f;
  --dirty-bg: #fdebd4;
  --danger: #a32020;
  --danger-bg: #fbe9e9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 43, 51, 0.08), 0 4px 14px rgba(28, 43, 51, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;
  line-height: 1.5;
}

a {
  color: var(--accent);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

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

.topbar {
  background: #10333f;
  color: #eaf4f7;
  box-shadow: var(--shadow);
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.65rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
}

.brand {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand a {
  color: #ffffff;
  text-decoration: none;
}

.brand-sub {
  font-weight: 400;
  color: #9dc4d1;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.tabs a {
  color: #cfe6ee;
  text-decoration: none;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
}

.tabs a:hover {
  background: rgba(255, 255, 255, 0.12);
}

.tabs a[aria-current="page"] {
  background: #eaf4f7;
  color: #10333f;
  font-weight: 600;
}

.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.who {
  color: #cfe6ee;
  font-size: 0.9rem;
}

/* ── Layout ──────────────────────────────────────────────────────── */

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

h1 {
  font-size: 1.6rem;
  margin: 0 0 0.25rem;
}

h2 {
  font-size: 1.15rem;
  margin: 0 0 0.75rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
  margin: 1.25rem 0;
}

.muted {
  color: var(--muted);
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.25rem 0 0;
}

/* ── Badges ──────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-draft,
.badge-dirty {
  background: var(--draft-bg);
  color: var(--draft);
  border-color: #ecd9b4;
}

.badge-dirty {
  background: var(--dirty-bg);
  color: var(--dirty);
}

.badge-published,
.badge-active {
  background: var(--published-bg);
  color: var(--published);
  border-color: #bfe3cc;
}

.badge-inactive {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: #f0c8c8;
}

.badge-featured {
  background: #fdf6e0;
  color: #7a5b00;
  border-color: #ecd9a0;
}

.badge-role-admin {
  background: #e8eef7;
  color: #1d4f8a;
  border-color: #c5d6ea;
}

.badge-role-editor {
  background: #eef1f3;
  color: #445761;
  border-color: #d3dbe0;
}

/* ── Forms ────────────────────────────────────────────────────────── */

.field {
  margin: 0 0 0.9rem;
}

.field label {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 0.3rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
}

.form-error {
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid #f0c8c8;
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  margin: 0.5rem 0;
}

.page-message {
  color: var(--published);
  background: var(--published-bg);
  border: 1px solid #bfe3cc;
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
}

.page-message[data-error] {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #f0c8c8;
}

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

.btn {
  display: inline-block;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 0.45rem 0.95rem;
  border-radius: 8px;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-dark);
  color: #ffffff;
}

.btn-danger {
  color: var(--danger);
  border-color: #e3bcbc;
}

.btn-danger:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

.btn-ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.4);
  color: #eaf4f7;
}

.btn-ghost:hover {
  border-color: #ffffff;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.btn-small {
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.btn-block {
  width: 100%;
}

/* ── Login / error screens ────────────────────────────────────────── */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: min(400px, 100%);
}

.error-code {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--muted);
  margin: 0;
}

/* ── Users table ──────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.users-table th,
.users-table td {
  text-align: left;
  padding: 0.55rem 0.7rem 0.55rem 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.users-table thead th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--border);
}

.users-table tbody th {
  font-weight: 600;
}

.actions-cell {
  white-space: nowrap;
}

.actions-cell .btn + .btn {
  margin-left: 0.35rem;
}

/* ── Content blocks ───────────────────────────────────────────────── */

.block-card {
  margin: 1rem 0;
}

.block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.block-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.block-head code {
  font-size: 0.95rem;
  background: #eef1f3;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}

.published-textarea {
  background: #f7f9fa;
  color: var(--muted);
}

.block-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.preview-card .preview-result {
  margin-top: 0.75rem;
  padding: 0.6rem 0.8rem;
  background: #f0f7f9;
  border: 1px solid #cfe3e9;
  border-radius: 8px;
  overflow-wrap: anywhere;
}

/* ── Portfolio grid ───────────────────────────────────────────────── */

.publish-bar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.grid {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
}

.tile {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tile[draggable="true"] {
  cursor: grab;
}

.tile.dragging {
  opacity: 0.45;
}

.tile.drop-target {
  outline: 3px dashed var(--accent);
  outline-offset: -3px;
}

.tile-media {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #dfe7ec;
}

.tile-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile-badges {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.tile-body {
  padding: 0.7rem 0.8rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.tile-meta {
  font-size: 0.8rem;
  margin: 0;
}

.tile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: auto;
}

/* ── Crop editor dialog ───────────────────────────────────────────── */

dialog.crop-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(16, 51, 63, 0.35);
  padding: 1.1rem 1.25rem;
  width: min(760px, 94vw);
  max-height: 94vh;
  color: var(--text);
  background: var(--panel);
}

dialog.crop-dialog::backdrop {
  background: rgba(16, 51, 63, 0.45);
}

.crop-dialog h2 {
  margin-top: 0;
}

.crop-stage {
  position: relative;
  margin: 0.75rem 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background:
    repeating-conic-gradient(#e8edf1 0% 25%, #f6f8fa 0% 50%) 50% / 24px 24px;
}

.crop-stage .crop-image {
  display: block;
  max-width: 100%;
  height: auto;
}

.crop-frame {
  position: absolute;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 2px var(--accent), inset 0 0 0 9999px rgba(14, 116, 144, 0.18);
  cursor: move;
}

.crop-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border: 2px solid var(--accent);
  border-radius: 3px;
}

.crop-handle.nw {
  left: -8px;
  top: -8px;
  cursor: nwse-resize;
}

.crop-handle.ne {
  right: -8px;
  top: -8px;
  cursor: nesw-resize;
}

.crop-handle.sw {
  left: -8px;
  bottom: -8px;
  cursor: nesw-resize;
}

.crop-handle.se {
  right: -8px;
  bottom: -8px;
  cursor: nwse-resize;
}

.crop-layout {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  align-items: flex-start;
}

.crop-stage-col {
  flex: 1 1 380px;
}

.crop-preview-col {
  flex: 0 1 280px;
}

.crop-preview-col canvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: block;
  background: #dfe7ec;
}

.crop-readout {
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  margin: 0.35rem 0;
}

.crop-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.9rem;
  justify-content: flex-end;
}

/* ── Small screens ────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .topbar-user {
    margin-left: 0;
  }

  .crop-layout {
    flex-direction: column;
  }

  .crop-preview-col {
    flex: 1 1 auto;
    max-width: 320px;
  }
}
