/* Shipyard components.css — reusable UI primitives.
 * Phase 1 covers nav, buttons, badges, tables, cards, forms, dialogs,
 * flashes, notices, and empty-state. Page-specific overrides go in
 * pages.css.
 */

/* ---------- Top nav ---------- */
.topnav {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  padding: 0 var(--s-5);
  height: var(--nav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topnav .brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-weight: 600;
  font-size: var(--text-lg);
  color: var(--fg);
  text-decoration: none;
}
.topnav .brand svg { width: 1.25rem; height: 1.25rem; color: var(--accent); }
.topnav nav { display: flex; gap: var(--s-2); flex: 1; }
.topnav nav a {
  display: inline-block;
  padding: var(--s-2) var(--s-3);
  color: var(--fg-muted);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
}
.topnav nav a:hover { color: var(--fg); background: var(--surface-alt); text-decoration: none; }
.topnav nav a.active { color: var(--accent); background: var(--brand-50); }
@media (prefers-color-scheme: dark) {
  .topnav nav a.active { background: rgba(96, 165, 250, 0.15); }
}

/* ---------- Footer ---------- */
.site-footer {
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--fg-muted);
  font-size: var(--text-xs);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--s-4);
  position: sticky;
  bottom: 0;
  z-index: 10;
}
.site-footer__brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--text-xs);
}
.site-footer__logo {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  color: var(--accent);
}
.site-footer__center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-4);
}
.site-footer__center a {
  color: var(--fg-muted);
  font-size: var(--text-xs);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease);
}
.site-footer__center a:hover,
.site-footer__center a[aria-current] { color: var(--accent); }
.site-footer__right {
  display: flex;
  justify-content: flex-end;
  font-size: var(--text-xs);
}
@media (max-width: 600px) {
  .site-footer {
    grid-template-columns: 1fr;
    gap: var(--s-2);
    text-align: center;
  }
  .site-footer__brand,
  .site-footer__center,
  .site-footer__right { justify-content: center; }
}

/* ---------- Buttons ---------- */
.btn,
button,
.logout-form button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-4);
  font-size: var(--text-sm);
  font-weight: 500;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}
.btn:hover,
button:hover { background: var(--surface-alt); text-decoration: none; }
.btn:disabled,
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary,
button.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn-primary:hover,
button.primary:hover { background: var(--brand-600); border-color: var(--brand-600); }

.btn-danger,
button.danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover,
button.danger:hover { background: #991b1b; border-color: #991b1b; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
}
.btn-ghost:hover { background: var(--surface-alt); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 0.125rem var(--s-2);
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.4;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-ok       { background: var(--success-bg); color: var(--success); }
.badge-warn     { background: var(--warning-bg); color: var(--warning); }
.badge-error    { background: var(--danger-bg);  color: var(--danger); }
.badge-muted    { background: var(--surface-alt); color: var(--fg-muted); border-color: var(--border); }
.badge-progress { background: var(--info-bg);    color: var(--info); }
.badge-info     { background: var(--info-bg);    color: var(--info); }

.pill-public,
.pill-private {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem var(--s-2);
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid transparent;
}
.pill-public  { background: var(--info-bg);     color: var(--info); }
.pill-private { background: var(--surface-alt); color: var(--fg-muted); border-color: var(--border); }

/* Access URL shown below the port pill in dashboard rows */
a.access-url {
  display: block;
  font-size: var(--text-xs);
  font-weight: 400;
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
  color: var(--fg-muted);
  margin-top: 0.2rem;
}
a.access-url:hover { text-decoration: underline; color: var(--brand); }

.warn-disagreement { color: var(--warning); margin-left: var(--s-1); cursor: help; }

/* ---------- Tables ---------- */
table.services,
table.env-table,
table.jobs {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
table.services th,
table.services td,
table.env-table th,
table.env-table td,
table.jobs th,
table.jobs td {
  padding: var(--s-2) var(--s-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.services th,
table.env-table th,
table.jobs th {
  background: var(--surface-alt);
  font-weight: 600;
  color: var(--fg-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
table.services tr:last-child td,
table.env-table tr:last-child td,
table.jobs tr:last-child td { border-bottom: 0; }
table.services tbody tr:hover { background: var(--surface-alt); }

/* ---------- Cards / sections ---------- */
.card,
section.metadata,
section.actions,
section.jobs,
section.env-editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
}
section + section { margin-top: var(--s-5); }

/* ---------- Forms ---------- */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: var(--s-2) var(--s-3);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  outline: none;
}
input[aria-invalid="true"] { border-color: var(--danger); }

.field { display: flex; flex-direction: column; gap: var(--s-1); margin-bottom: var(--s-3); }
.field > label { font-size: var(--text-sm); font-weight: 500; color: var(--fg); }
.field .hint { margin: 0; }
.field-error { color: var(--danger); font-size: var(--text-sm); margin: 0; }

ul.errors {
  margin: 0 0 var(--s-4);
  padding: var(--s-3) var(--s-4) var(--s-3) var(--s-6);
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius-md);
  border: 1px solid var(--danger);
}

/* ---------- Flash region ---------- */
.flash-region {
  max-width: var(--content-max);
  margin: var(--s-3) auto 0;
  padding: 0 var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.flash {
  padding: var(--s-3) var(--s-4);
  border-radius: var(--radius-md);
  border-left: 4px solid currentColor;
  background: var(--surface-alt);
  color: var(--fg);
}
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-info    { background: var(--info-bg);    color: var(--info); }
.flash-warning { background: var(--warning-bg); color: var(--warning); }
.flash-error   { background: var(--danger-bg);  color: var(--danger); }

/* ---------- Notices (inline) ---------- */
.notice {
  padding: var(--s-3) var(--s-4);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  margin-top: var(--s-4);
  margin-bottom: var(--s-4);
}
.notice-warn { background: var(--warning-bg); border-color: var(--warning); color: var(--warning); }
.notice-error { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: var(--s-7) var(--s-5);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--fg-muted);
}
.empty-state h2 { color: var(--fg); margin-top: var(--s-3); }
.empty-state .actions { margin-top: var(--s-4); }

/* ---------- Dialog ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--fg);
  padding: var(--s-5);
  box-shadow: var(--shadow-md);
  max-width: 32rem;
  width: calc(100% - 2rem);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }

/* ---------- HTMX loading indicator ----------
 * HTMX auto-adds `htmx-request` to the element issuing a request.
 * We give in-flight buttons a subtle spinner and dim them.
 */
@keyframes shipyard-spin { to { transform: rotate(360deg); } }
.htmx-request {
  cursor: progress;
}
.btn.htmx-request,
button.htmx-request {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.htmx-request::after,
button.htmx-request::after {
  content: "";
  position: absolute;
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--fg);
  top: 50%; left: 50%;
  margin: -0.45rem 0 0 -0.45rem;
  animation: shipyard-spin 0.6s linear infinite;
}
.btn-primary.htmx-request::after,
button.primary.htmx-request::after { color: #fff; }

/* The standalone `.spinner` utility (for inline use in templates). */
.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: shipyard-spin 0.6s linear infinite;
  vertical-align: middle;
}
@media (prefers-reduced-motion: reduce) {
  .btn.htmx-request::after,
  button.htmx-request::after,
  .spinner { animation: none; }
}

/* ---------- Responsive nav (hamburger) ---------- */
.nav-toggle { display: none; }
.nav-burger { display: none; }

@media (max-width: 720px) {
  .topnav { flex-wrap: wrap; gap: var(--s-3); padding: 0 var(--s-3); }
  .nav-burger {
    display: inline-flex;
    flex-direction: column;
    justify-content: space-between;
    width: 1.5rem;
    height: 1.1rem;
    margin-left: auto;
    cursor: pointer;
  }
  .nav-burger span {
    display: block;
    height: 2px;
    background: var(--fg);
    border-radius: 2px;
  }
  .primary-nav {
    display: none !important;
    flex-basis: 100%;
    flex-direction: column;
    padding: var(--s-2) 0;
    border-top: 1px solid var(--border);
  }
  .nav-toggle:checked ~ .primary-nav { display: flex !important; }
  .topnav nav a { padding: var(--s-2) var(--s-3); }
  .logout-form { margin-left: var(--s-2); }
}

/* ---------- Table horizontal scroll on narrow viewports ---------- */
.table-scroll { overflow-x: auto; }
@media (max-width: 720px) {
  table.services,
  table.env-table,
  table.jobs,
  table.audit-table { font-size: var(--text-xs); }
}

/* ---------- Print styles ---------- */
@media print {
  .topnav, .site-footer, .row-actions, .action-buttons,
  .sticky-rail, .log-toolbar, .dashboard-filters,
  .nav-burger, .logout-form { display: none !important; }
  body { background: #fff; color: #000; }
  .card, section.metadata, section.jobs, section.env-editor {
    box-shadow: none; border-color: #999;
  }
  a { color: #000; text-decoration: underline; }
  .log-pane { background: #fff; color: #000; max-height: none; }
}

/* ----- Inline alerts (used by error/permission partials) ----- */
.alert {
  display: flex;
  gap: var(--s-2);
  align-items: baseline;
  flex-wrap: wrap;
  padding: var(--s-2) var(--s-3);
  border: 1px solid transparent;
  border-radius: var(--radius);
  margin: var(--s-3) 0;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.alert-warn  { background: var(--warning-bg); color: var(--warning); border-color: var(--warning); }
.alert-ok    { background: var(--success-bg); color: var(--success); border-color: var(--success); }
