/* ==========================================================================
   CMC Fabric Collections — theme tokens
   Swap these to match your site exactly (colors, font-family) in one place.
   ========================================================================== */
:root {
  --blue-900: #0a2a52;   /* deep navy — header, headings */
  --blue-700: #10407d;   /* primary blue */
  --blue-600: #1259a5;   /* buttons, links, accents */
  --blue-500: #2b78c9;   /* hover state */
  --blue-100: #e8f0fa;   /* pale blue tints, hover backgrounds */
  --blue-50:  #f3f7fc;   /* page background */
  --white: #ffffff;
  --ink: #16233a;        /* body text on white */
  --ink-soft: #5b6b83;   /* secondary text */
  --border: #dbe4f0;
  --danger: #c1392b;
  --danger-bg: #fbeceb;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(10, 42, 82, 0.06);
  --shadow-md: 0 8px 24px rgba(10, 42, 82, 0.12);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--blue-50);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 {
  font-family: var(--font);
  font-weight: 700;
  color: var(--blue-900);
  margin: 0;
}

a { color: inherit; }

button, input {
  font-family: inherit;
  font-size: inherit;
}

img { max-width: 100%; display: block; }

:focus-visible {
  outline: 2px solid var(--blue-600);
  outline-offset: 2px;
}

/* ---------- Top bar ---------- */

.topbar {
  background: var(--blue-900);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  font-weight: 800;
  font-size: 1.05rem;
  background: var(--white);
  color: var(--blue-900);
  padding: 4px 9px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

.brand-name {
  font-weight: 600;
  font-size: 1.08rem;
  color: #fff;
}

.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.user-pill {
  font-size: 0.85rem;
  color: #c7d6ea;
}
.user-pill strong { color: #fff; font-weight: 600; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-accent {
  background: var(--blue-600);
  color: #fff;
}
.btn-accent:hover { background: var(--blue-500); }

.btn-ghost {
  background: transparent;
  color: inherit;
  border-color: rgba(255, 255, 255, 0.35);
}
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }

.card-actions .btn-ghost {
  border-color: var(--border);
  color: var(--ink-soft);
}
.card-actions .btn-ghost:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }

.btn-small { padding: 8px 14px; font-size: 0.82rem; }

/* ---------- Layout ---------- */

.wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 24px 72px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}

/* ---------- Cards ---------- */

.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.card:hover { box-shadow: var(--shadow-md); border-color: var(--blue-500); }

/* Thumbnail keeps the PDF's own first-page ratio (landscape decks stay
   landscape) via an inline `aspect-ratio` set per card from stored data;
   4:3 below is only the pre-JS fallback before that inline style applies. */
.card-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--blue-100);
  position: relative;
  border-bottom: 1px solid var(--border);
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--white);
}

.thumb-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: 0.06em;
  color: var(--blue-600);
  opacity: 0.55;
}

.card-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 4px; flex: 1; }

.card-title {
  font-size: 1rem;
  line-height: 1.35;
  font-weight: 700;
  color: var(--ink);
  /* Wrap up to 2 lines, then truncate with an ellipsis — never overflows the card. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: break-word;
  word-break: break-word;
  min-height: 2.7em;
}

.card-meta {
  margin: 2px 0 12px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.card-actions { display: flex; gap: 8px; margin-top: auto; }
.card-actions .btn { flex: 1; justify-content: center; }

/* ---------- Empty state ---------- */

.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 64px 24px;
  text-align: center;
  background: var(--white);
}

.empty-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--blue-900);
  margin: 0 0 8px;
}

.empty-sub {
  color: var(--ink-soft);
  max-width: 44ch;
  margin: 0 auto 22px;
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 42, 82, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--white);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 24px;
  box-shadow: var(--shadow-md);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-head h3 { font-size: 1.1rem; }

.modal-close {
  border: none;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-soft);
  padding: 4px;
}
.modal-close:hover { color: var(--ink); }

#uploadForm { display: flex; flex-direction: column; gap: 6px; }

#uploadForm label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-top: 12px;
}

#uploadForm input[type="text"],
#uploadForm input[type="file"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--white);
  width: 100%;
}
#uploadForm input[type="text"]:focus {
  border-color: var(--blue-500);
}

.preview-row {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.preview-row.hidden { display: none; }

.preview-canvas {
  width: 96px;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.preview-label {
  font-size: 0.8rem;
  color: var(--ink-soft);
  word-break: break-word;
}

.form-error {
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.85rem;
  margin: 14px 0 0;
}
.form-error.hidden { display: none; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

/* ---------- Login ---------- */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--blue-900);
  background-image: linear-gradient(160deg, var(--blue-900) 0%, #0e3766 100%);
  padding: 20px;
}

.login-card {
  background: var(--white);
  border-radius: 10px;
  padding: 40px 34px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
}

.login-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  background: var(--blue-900);
  color: #fff;
  padding: 8px 16px;
  border-radius: 6px;
  margin-bottom: 20px;
  letter-spacing: 0.03em;
}

.login-card h1 { font-size: 1.35rem; margin-bottom: 6px; }

.login-sub {
  color: var(--ink-soft);
  font-size: 0.88rem;
  margin: 0 0 24px;
}

.login-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #f2c9c4;
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.login-form { display: flex; flex-direction: column; text-align: left; gap: 6px; }

.login-form label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-top: 10px;
}

.login-form input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 11px 12px;
  width: 100%;
}
.login-form input:focus { border-color: var(--blue-500); }

.login-form button {
  margin-top: 22px;
  background: var(--blue-600);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 12px;
  font-weight: 700;
  cursor: pointer;
}
.login-form button:hover { background: var(--blue-500); }

.login-hint {
  margin-top: 20px;
  font-size: 0.74rem;
  color: var(--ink-soft);
}
.login-hint code {
  background: var(--blue-50);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ---------- Responsive ---------- */

@media (max-width: 960px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

@media (max-width: 640px) {
  .wrap { padding: 24px 16px 56px; }
  .grid { grid-template-columns: 1fr 1fr; gap: 14px; }
  .topbar-inner { padding: 12px 16px; }
  .brand-name { font-size: 0.95rem; }
  .user-pill { display: none; }
  .card-body { padding: 12px 14px 14px; }
  .card-title { font-size: 0.92rem; }
  .card-actions { flex-direction: column; }
  .modal { padding: 20px; }
}

@media (max-width: 420px) {
  .grid { grid-template-columns: 1fr; }
  .topbar-right { width: 100%; justify-content: space-between; }
}
